我是tensorflow的新手。我正在使用Tflearn训练我的图像来分类眼睛状态。在初始阶段,现在,我有400张训练图像和200张验证图像。我正在使用image_preloader在我的脚本中输入自定义图像。我认为它成功加载图像 所示:
tflearn.data_utils.ImagePreloader对象位于0x7fa28f3a5310
但是在训练时分割和获取批次会导致问题,
将跟踪错误显示为
Traceback (most recent call last):
File "tflearn_custom.py", line 181, in <module>
model.fit(x,y,validation_set=({'input':test_x},{'targets':test_y}),n_epoch=10,batch_size=10)
File "/usr/local/lib/python2.7/dist-packages/tflearn/models/dnn.py", line 215, in fit
callbacks=callbacks)
File "/usr/local/lib/python2.7/dist-packages/tflearn/helpers/trainer.py", line 285, in fit
self.summ_writer, self.coord)
File "/usr/local/lib/python2.7/dist-packages/tflearn/helpers/trainer.py", line 709, in initialize_fit
self.n_train_samples = len(get_dict_first_element(feed_dict))
TypeError: object of type 'Tensor' has no len()
这是我的代码:
import tflearn
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.core import input_data, dropout,fully_connected
from tflearn.layers.estimator import regression
import tensorflow as tf
from tflearn.data_utils import image_preloader
test_filename='/path_to_validating_set/'
train_filename='/path_to_training_set/'
x, y = image_preloader(train_filename, image_shape=(128, 128), mode='folder', grayscale=True, categorical_labels=True, normalize=True)
test_x, test_y = image_preloader(test_filename, image_shape=(128, 128), mode='folder', grayscale=True, categorical_labels=True, normalize=True)
convnet =input_data(shape=[None, 128,128,1], name='input')
convnet = conv_2d(convnet, 32, 2, activation='relu')
convnet = max_pool_2d(convnet,2)
convnet = conv_2d(convnet, 64, 2, activation='relu')
convnet = max_pool_2d(convnet,2)
convnet = fully_connected(convnet, 1024, activation='relu')
convnet = dropout(convnet, 0.8)
convnet = fully_connected(convnet, 2, activation='softmax')
convnet = regression(convnet, optimizer='adam', learning_rate=0.01, loss='categorical_crossentropy', name='targets')
model= tflearn.DNN(convnet)
model.fit(x,y,validation_set=({'input':test_x},{'targets':test_y}),n_epoch=5,batch_size=5)
我正在使用tensorflow 1.0。我已经尝试过搜索类似的问题,但没有什么能解决它。
答案 0 :(得分:2)
我认为问题是feed_dict
是一个张量,Tensor
类型的对象没有长度。您可以使用feed_dict.shape[0]
来获取它的长度。