解决“Can not convert a ndarray into a Tensor or Operation.”

背景:用tensorflow做训练时,feed数据的环节报错
“Can not convert a ndarray into a Tensor or Operation.”

报错代码:

label,count,label_p,count_p,label_c,count_c,accuracy=sess.run \
      ([label,count,label_p,count_p,label_c,count_c,accuracy],{x: batch[0], y_: batch[1], keep_prob:1.0})

原因:这个feeddict可能时写在一个循环里的,比如分批喂数据做训练或做预测,这时如果接收的参数名和run()里面的参数名一样,这样第一次不会报错,下一次循环时,label, count, label_p, count_p, label_c, count_c, accuracy,这些变量名已有了,直接跑会和你前面定义的运算冲突。

解决办法:修改接收的变量名。

t_label,t_count,t_label_p,t_count_p,t_label_c,t_count_c,t_acc=sess.run \
      ([label,count,label_p,count_p,label_c,count_c,accuracy],{x: batch[0], y_: batch[1], keep_prob:1.0})

你可能感兴趣的:(tensorflow)