Python Tensorflow Assign 需要两个张量的形状匹配。lhs 形状= [20] rhs 形状= [48]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40601975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tensorflow Assign requires shapes of both tensors to match. lhs shape= [20] rhs shape= [48]
提问by Pradeep Banavara
I am a TensorFlow noob. I have trained a TensorFlow model from the open source implementation of deeppose and have to now run the model against a new set of images.
我是 TensorFlow 菜鸟。我已经从 deeppose 的开源实现中训练了一个 TensorFlow 模型,现在必须针对一组新图像运行该模型。
The model was trained on images of size 100 * 100
so I have resized the new set of images to the same size. I have 149
new images to run the model against. When I run the model, I get the following error.
该模型是在图像大小上进行训练的,100 * 100
因此我将新图像集的大小调整为相同的大小。我有149
新的图像来运行模型。当我运行模型时,出现以下错误。
InvalidArgumentError (see above for traceback): Assign requires shapes
of both tensors to match. lhs shape= [20] rhs shape= [48]
At the line
在一线
saver = tf.train.Saver(tf.all_variables())
I suspect the trained model size and the test image sizes are not matching. I am not clear how to fix this issue. I printed out the list of variables from the tf.all_variables()
call. Here it is
我怀疑训练后的模型大小和测试图像大小不匹配。我不清楚如何解决这个问题。我从tf.all_variables()
调用中打印出变量列表。这里是
Tensor("Placeholder:0", shape=(128, 100, 100, 3), dtype=float32)
(11, 11, 3, 20)
conv1/weights:0
(20,)
conv1/biases:0
(5, 5, 20, 35)
conv2/weights:0
(35,)
conv2/biases:0
(3, 3, 35, 50)
conv4/weights:0
(50,)
conv4/biases:0
(3, 3, 50, 75)
conv5/weights:0
(75,)
conv5/biases:0
(300, 1024)
local1/weights:0
(1024,)
local1/biases:0
(1024, 1024)
local2/weights:0
(1024,)
local2/biases:0
(1024, 0)
softmax_linear/weights:0
(0,)
softmax_linear/biases:0
I am not sure where the RHS parameter is coming from. I've looked at all config files and there doesn't seem to be any parameter specifying this config.
我不确定 RHS 参数来自哪里。我查看了所有配置文件,似乎没有任何参数指定此配置。
Any help in resolving this will be greatly appreciated.
任何解决此问题的帮助将不胜感激。
回答by maurice
Try deleting any checkpoints that were saved from previous runs. Sometimes when changing the architecture and running again, TF will pick up from the old checkpoint (but with new definition), and you get this error.
尝试删除从以前的运行中保存的任何检查点。有时,当更改架构并再次运行时,TF 会从旧检查点(但具有新定义)中恢复,并且您会收到此错误。
回答by user1623454
I also ran into this problem, the problem was that the labels and class numbers didn't matched so I changed and fix the class number cound and labels everywhere.
我也遇到了这个问题,问题是标签和班级编号不匹配,所以我改变并修复了班级编号和标签。
In my case it was to change the "num_classes" parameter in the faster_rcnn.config and the "label_map.pbtxt" file to match with the real values.
就我而言,它是更改 fast_rcnn.config 和“label_map.pbtxt”文件中的“num_classes”参数以匹配实际值。
回答by Yesus Becerril
If deleting checkpoints didn't work, this error is due to dimensions, so chek if the number of classes correspond to the same, as well as the dimensions of the image
如果删除checkpoint没有成功,这个错误是由于尺寸,所以检查类的数量是否相同,以及图像的尺寸
回答by Pradeep Banavara
So as it happens, I had updated the TensorFlow code but had failed to train it. So I rolled back to the previous version, made the appropriate new changes to the run script and got it working.
碰巧的是,我更新了 TensorFlow 代码,但未能对其进行训练。所以我回滚到以前的版本,对运行脚本进行了适当的新更改并使其正常工作。