gpt4 book ai didi

python - Tflearn 训练批处理错误说 "object of type ' Tensor' has no len()"

转载 作者:太空宇宙 更新时间:2023-11-03 14:55:35 25 4
gpt4 key购买 nike

我是 tensorflow 的新手。我正在使用 Tflearn 训练我的图像以对眼睛状态进行分类。对于初始阶段,现在,我有 400 张训练图像和 200 张验证图像。我正在使用 image_preloader 在我的脚本中获取自定义图像输入。我认为它成功加载图像显示:

tflearn.data_utils.ImagePreloader object at 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。我已经尝试搜索类似的问题,但没有任何解决办法。

最佳答案

我认为问题是 feed_dict 是一个张量,Tensor 类型的对象没有长度。您可以使用 feed_dict.shape[0] 来获取它的长度。

关于python - Tflearn 训练批处理错误说 "object of type ' Tensor' has no len()",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42910155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com