AttributeError:“ TensorSliceDataset”对象没有属性“ train”

时间:2018-07-13 15:08:05

标签: python tensorflow

我正在尝试在张量流中创建模型,但是在获取火车数据时遇到了问题。当前,我将数据作为TensorSliceDataset对象。但是,我不断收到错误消息,“ TensorSliceDataset”对象没有属性“ train”。这是我的代码的相关部分。

labels = np.asarray(labels)
features = np.asarray(features)
print (labels)
print (features)
data = tf.data.Dataset.from_tensor_slices((features,labels))    
with tf.Session() as sess:
    ans = 0

    sess.run(tf.global_variables_initializer())

    for i in range(EPOCHS):
        batch_xs, batch_ys = data.train.next_batch(MINIBATCH_SIZE)
        sess.run(gd_step, feed_dict={x: batch_xs, y_true: batch_ys})
        if i%100 == 0:
            train_accuracy = sess.run(accuracy, feed_dict ={x:batch_xs,y_: batch_ys,keep_prob: 0.5})
            print "step {}, training accuracy {}".format(i, train_accuracy)

    ans = ans = sess.run(accuracy, feed_dict={x: data.test.features, y_true: data.test.labels})
    print ("Accuracy: " + str(ans*100))

0 个答案:

没有答案