Paddle book python3运行问题 - (fit_a_line, recognize_digit)
Created by: OliverLPH
线性回归的示例代码中,主循环里使用了 plot_prompt调用了 ploter中使用了“basestring”。然后报错未定义 “basestring”,因为python3没有basestring。
报错如下
for pass_id in range(num_epochs):
for data_train in train_reader():
avg_loss_value, = exe.run(main_program,
feed=feeder.feed(data_train),
fetch_list=[avg_loss])
if step % 10 == 0: # 每10个批次记录并输出一下训练损失
plot_prompt.append(train_prompt, step, avg_loss_value[0])
plot_prompt.plot()
print("%s, Step %d, Cost %f" %
(train_prompt, step, avg_loss_value[0]))
if step % 100 == 0: # 每100批次记录并输出一下测试损失
test_metics = train_test(executor=exe_test,
program=test_program,
reader=test_reader,
fetch_list=[avg_loss.name],
feeder=feeder)
plot_prompt.append(test_prompt, step, test_metics[0])
plot_prompt.plot()
print("%s, Step %d, Cost %f" %
(test_prompt, step, test_metics[0]))
if test_metics[0] < 10.0: # 如果准确率达到要求,则停止训练
break
step += 1
if math.isnan(float(avg_loss_value[0])):
sys.exit("got NaN loss, training failed.")
#保存训练参数到之前给定的路径中
if params_dirname is not None:
fluid.io.save_inference_model(params_dirname, ['x'], [y_predict], exe)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-8-4379eae5beee> in <module>
5 fetch_list=[avg_loss])
6 if step % 10 == 0: # 每10个批次记录并输出一下训练损失
----> 7 plot_prompt.append(train_prompt, step, avg_loss_value[0])
8 plot_prompt.plot()
9 print("%s, Step %d, Cost %f" %
/anaconda3/lib/python3.7/site-packages/paddle/utils/plot.py in append(self, title, step, value)
73 plot_curve.append(title="Curve 1",step=1,value=1)
74 """
---> 75 assert isinstance(title, basestring)
76 assert self.__plot_data__.has_key(title)
77 data = self.__plot_data__[title]
NameError: name 'basestring' is not defined