0

how can i solve this ? this is my first time for Tensortflow. I try to copy Train and Evaluate the Model from tensortflow tutorial but it seem not work. Can someone help me to solve my problem? Thanks!

http://pastebin.com/NCQKNyKy

import tensorflow as tf
sess = tf.InteractiveSession()

import numpy as np
from numpy import genfromtxt

def weight_variable(shape):
    initial = tf.truncated_normal(shape, stddev=0.1)
    return tf.Variable(initial)

def bias_variable(shape):
    initial = tf.constant(0.1, shape=shape)
    return tf.Variable(initial)

def conv2d(x, W):
    return tf.nn.conv2d(x, W, strides=[1, 1, 3*3, 1], padding='VALID') 


data = genfromtxt('circle_deeplearn_data_small.txt',delimiter=',')
out = genfromtxt('circle_deeplearn_output_small.txt',delimiter=',')

x = tf.placeholder(tf.float32, shape =[None, 3*3*15]) # size of x
y_ = tf.placeholder(tf.float32, shape =[None, 1])   # size of output




W_conv1 = weight_variable([1,3*3,1,15])
b_conv1 = bias_variable([15])

x_image = tf.reshape(x,[-1,1,3*3*15,1])

h_conv1 = tf.nn.relu(conv2d(x_image,W_conv1) + b_conv1)


W_fc1 = weight_variable([1 * 1 * 15 , 1])
b_fc1 = bias_variable([1])

h_conv1_flat = tf.reshape(h_conv1 , [-1,1 * 1 * 15])
h_fc1 = tf.nn.relu(tf.matmul(h_conv1_flat , W_fc1) + b_fc1)
y_conv = h_fc1
keep_prob = tf.placeholder(tf.float32)
h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob)



#Adam 

cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(y_conv, y_))
train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
correct_prediction = tf.equal(tf.argmax(y_conv,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
#sess.run(tf.global_variables_initializer())    
sess.run(tf.initialize_all_variables())
for i in range(20000):
    batch = data.train.next_batch(50)
    if i%100 == 0:
        train_accuracy = accuracy.eval(feed_dict={x:batch[0], y_: batch[1], keep_prob: 1.0})
        print("step %d, training accuracy %g"%(i, train_accuracy))
    train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5})
print("test accuracy %g"%accuracy.eval(feed_dict={x: data, y_: out, keep_prob: 1.0}))

This is result:

AttributeError: 'numpy.ndarray' object has no attribute 'train'
1
  • 1
    Still mostly in python 2.7... Can you edit your quetion to include the line where the error occurs, or even better the full traceback message? Commented Feb 21, 2017 at 9:06

4 Answers 4

2

here datais just a numpy array. You may need to write ur own train data iterator

Sign up to request clarification or add additional context in comments.

Comments

1

I have faced same problem. Actually, it's not a problem. Literally, I didn't know the structure of the data that's why I have faced this problem. Te datasets comes from tensorflow lib are compressed in a single file and separated in a file as train, test, and validation set. That's why when we call dataset.train.next_batch() it does work. You own datatset is not compressed in the same way that's why it doesn't work. You have to configure your dataset on the own way so do the batch system and looping.

Comments

0

It is not quite clear what you are trying to do. The problem occurs because data is a numpy array generated in this line

data = genfromtxt('circle_deeplearn_data_small.txt',delimiter=',')

The error occurs when you try to use the method train of data, which does not exist, in the following line

batch = data.train.next_batch(50)

Instead you need to feed data to tensorflow.

Comments

0

You may try to use numpy.reshape to turn your data from 2 dimension into 3 dimension. For example if you had 20 samples and 100 features, so a (20,100) data matrix and used a minibatch size of 5. Then you could reshape using np.reshape(data,[10,5,-1]) to get a (10,5,40) matrix.

*The "-1" meaning that you leave numpy to count the array for your, the total number of array is 20,000. Thus, in this example: 10*5*40 = 20,000.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.