问题遇到的现象和发生背景
用百度飞桨做一个手写数字的神经网络,这个问题是怎么回事压。
用代码块功能插入代码,请勿粘贴截图
for batch_id, data in enumerate(train_reader()): #遍历train_reader
train_cost, train_acc = exe.run(program=fluid.default_main_program(),#运行主程序
feed=feeder.feed(data), #给模型喂入数据
fetch_list=[avg_cost, acc]) #fetch 误差、准确率
all_train_iter=all_train_iter+BATCH_SIZE
all_train_iters.append(all_train_iter)
all_train_costs.append(train_cost[0])
all_train_accs.append(train_acc[0])
# 每200个batch打印一次信息 误差、准确率
if batch_id % 200 == 0:
print('Pass:%d, Batch:%d, Cost:%0.5f, Accuracy:%0.5f' %
(pass_id, batch_id, train_cost[0], train_acc[0]))
# 进行测试
test_accs = []
test_costs = []
运行结果及报错内容
TypeError Traceback (most recent call last)
/tmp/ipykernel_270/293710678.py in <module>
----> 1 for data in enumerate(train_reader()):
2 1
3
4
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/batch.py in batch_reader()
56 r = reader()
57 b = []
---> 58 for instance in r:
59 b.append(instance)
60 if len(b) == batch_size:
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/reader/decorator.py in data_reader()
165 def data_reader():
166 buf = []
--> 167 for e in reader():
168 buf.append(e)
169 if len(buf) >= buf_size:
/tmp/ipykernel_270/4190344081.py in reader()
60 def readerGenerator(data, label):
61 def reader():
---> 62 for i in range(len(data)):
63 yield data[i], int(label[i])
64 return reader
TypeError: object of type 'function' has no len()
我的解答思路和尝试过的方法
我想不明白。。求指教