tensorflow.python.framework.errors_impl.InvalidArgumentError - Go语言中文社区

tensorflow.python.framework.errors_impl.InvalidArgumentError


问题描述

尝试使用一个for循环训练10次神经网络取10次结果作为均值,for循环第一次能够正常运行,当i =1时,报错:

tensorflow.python.framework.errors_impl.InvalidArgumentError:
You must feed a value for placeholder tensor ‘Placeholder’ with dtype float
[[node Placeholder (defined at D:PythonPyCharm_Projectspcg_segmentationDNN_Model.py:188) = Placeholder
dtype=DT_FLOAT, shape=, _device="/job:localhost/replica:0/task:0/device:CPU:0"]]

错误的原因

下面是代码:

train_set, train_set_label, val_set, val_set_label = get_trainset(path1, path2, path3, balance=0, category=3)
    test_set, test_set_label = get_testset(path4, path5, path6, 3)
    acc = np.zeros([10, 3])
    for i in range(10):
        acc[i, 0], acc[i, 1], acc[i, 2] = main(train_set, train_set_label, val_set, val_set_label, test_set, test_set_label)
    print(np.mean(acc, axis=0))

找到出错的地方:

_a[0] = tf.placeholder("float")

即使shape没有指定,但是***为什么在第一次运行的时候正确运行***。

我在训练的时候使用了并行加速:

from numba.npyufunc.parallel import NUM_THREADS
....
with tf.Session(config=tf.ConfigProto(intra_op_parallelism_threads=NUM_THREADS)) as sess:
...

有可能问题出在这里。
去掉之后运行还是发生同样的错误。
逐句运行:
bug
数据类型和shape是对应的。如果不对应,第一次运行就应该报错。

2个博客提供错误的原因:
https://blog.csdn.net/ichglauben/article/details/84897215
https://blog.csdn.net/u012436149/article/details/53894364
我的问题是第二篇博客提及的,使用tf.summary.merge_all()引起的血案。
当第一轮训练时merge_all只是管理了本轮的summary;
第二轮训练时,merge_all除了管理了本轮的模型summary和上一轮模型的Summary。
由于Summary的计算是需要feed数据的,所以会报错。

解决方法

替换掉merge_all或者在训练的时候讲merge去掉,不保存参数。

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_23869697/article/details/87020662
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢