keras vgg16:InvalidArgumentError (see above for traceback): Matrix size-incompatible: In[0]: [32,167

网友投稿 362 2022-08-25

keras vgg16:InvalidArgumentError (see above for traceback): Matrix size-incompatible: In[0]: [32,167

我们在使用python的时候总会出现各种各样奇怪的问题,那么我将一一的记录下来。

我在利用vgg提取的特征来进行迁移学习的时候,发现模型报了一个未知的错误:

Caused by op u'dense_2/MatMul', defined at: File "HARRISON_feature_model.py", line 50, in model.add(Dense(4096)) File "/home/idc/anaconda3/envs/hashtag/lib/python2.7/site-packages/keras/models.py", line 489, in add output_tensor = layer(self.outputs[0]) File "/home/idc/anaconda3/envs/hashtag/lib/python2.7/site-packages/keras/engine/topology.py", line 603, in __call__ output = self.call(inputs, **kwargs) File "/home/idc/anaconda3/envs/hashtag/lib/python2.7/site-packages/keras/layers/core.py", line 843, in call output = K.dot(inputs, self.kernel) File "/home/idc/anaconda3/envs/hashtag/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 1057, in dot out = tf.matmul(x, y) File "/home/idc/anaconda3/envs/hashtag/lib/python2.7/site-packages/tensorflow/python/ops/math_ops.py", line 1891, in matmul a, b, transpose_a=transpose_a, transpose_b=transpose_b, name=name) File "/home/idc/anaconda3/envs/hashtag/lib/python2.7/site-packages/tensorflow/python/ops/gen_math_ops.py", line 2437, in _mat_mul name=name) File "/home/idc/anaconda3/envs/hashtag/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "/home/idc/anaconda3/envs/hashtag/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2956, in create_op op_def=op_def) File "/home/idc/anaconda3/envs/hashtag/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1470, in __init__ self._traceback = self._graph._extract_stack() # pylint: disable=protected-accessInvalidArgumentError (see above for traceback): Matrix size-incompatible: In[0]: [32,16777216], In[1]: [4096,4096] [[Node: dense_2/MatMul = MatMul[T=DT_FLOAT, transpose_a=false, transpose_b=false, _device="/job:localhost/replica:0/task:0/device:GPU:0"](dropout_1/cond/Merge, dense_2/kernel/read)]] [[Node: metrics/acc/Mean/_101 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_666_metrics/acc/Mean", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

经过查资料发现,这是因为我用的是tf后端训练的模型,而现在我又用th后端来进行训练,因此报了错,要换成tf后端,只需要在代码里面加上:

from keras import backend as KK.set_image_dim_ordering('tf')

就行了

参考资料

[1].Keras vgg16: Matrix size-incompatible: In[0]: [16,18432], In[1]: [25088,4096].

​​ https://stackoverflow.com/questions/45043332/keras-vgg16-matrix-size-incompatible-in0-16-18432-in1-25088-4096 ​​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:mac opencv4出现 sift = cv2.xfeatures2d.SIFT_create()出现错误
下一篇:蹭空难热度做内容营销,“脸都不要了”!
相关文章

 发表评论

暂时没有评论,来抢沙发吧~