Tensorflow 'numpy.ndarray' object has no attribute 'train' -
i encounter same problem training tensorflow predicting column in csv file is:
attributeerror traceback (most recent call last) in () 1 in range(1000): ----> 2 batch_xs, batch_ys = data.train.next_batch(100) 3 sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
attributeerror: 'numpy.ndarray' object has no attribute 'train'
how able solve it?
from __future__ import print_function import matplotlib.pyplot plt import numpy np import matplotlib # import mnist data #from tensorflow.examples.tutorials.mnist import input_data #mnistt = input_data.read_data_sets("/tttmp/data/", one_hot=true) numpy import genfromtxt import csv import tensorflow tf %matplotlib inline # read data... x_input = genfromtxt('data_coffee.csv',delimiter=',') y_input = genfromtxt('class_coffee.csv',delimiter=',') data=genfromtxt('data_coffee.csv',delimiter=',') matsize = np.shape(data) # parameters learning_rate = 0.001 training_epochs = 15 batch_size = 100 display_step = 1 # tf graph input x = tf.placeholder(tf.float32, [none, matsize[0]]) y = tf.placeholder(tf.float32, [none, matsize[1]]) #x= genfromtxt('data_coffee.csv',delimiter=',') #y= genfromtxt('class_coffee.csv',delimiter=',') # initializing variables init = tf.global_variables_initializer() # launch graph tf.session() sess: sess.run(init) # training cycle epoch in range(training_epochs): avg_cost = 0. total_batch = int(x.train.num_examples/batch_size) # loop on batches in range(total_batch): batch_x, batch_y = data.train.next_batch(batch_size) # run optimization op (backprop) , cost op (to loss value) _, c = sess.run([optimizer, cost], feed_dict={x: batch_x, y: batch_y}) # compute average loss avg_cost += c / total_batch # display logs per epoch step if epoch % display_step == 0: print("epoch:", '%04d' % (epoch+1), "cost=", \ "{:.9f}".format(avg_cost)) print("optimization finished!")
i think copying pattern mnist example: data.train.next_batch
in mnist example data read object of class has train variable, whereas reading data numpy array.
Comments
Post a Comment