运行时报错,
tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [256] vs. [252]
[[{{node gradients/logistic_loss_3/mul_grad/BroadcastGradientArgs}}]]
是在代码的
File "train.py", line 118, in main
loss = model.train(sess, [user, tgt, hist, mask, label, LEARNING_RATE])
File "/media/sdb2/AAAA_sdb2/zjp/MGNM/MGNM-main/code/model.py", line 79, in train
loss, _ = sess.run([self.loss, self.optimizer], feed_dict=feed_dict)
Mar 08
'23 04:03
wy-0
@lichenliang-whu
I want to ask you some questions about the operation. When I am running, I will report an error of
"
tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [256] vs. [252]
[[{{node gradients/logistic_loss_3/mul_grad/BroadcastGradientArgs}}]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "train.py", line 144, in
main()
File "train.py", line 118, in main
loss = model.train(sess, [user, tgt, hist, mask, label, LEARNING_RATE])
File "/media/sdb2/AAAA_sdb2/zjp/MGNM/MGNM-main/code/model.py", line 79, in train
loss, _ = sess.run([self.loss, self.optimizer], feed_dict=feed_dict)
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 950, in run
run_metadata_ptr)
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1173, in _run
feed_dict_tensor, options, run_metadata)
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1350, in _do_run
run_metadata)
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1370, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [256] vs. [252]
[[node gradients/logistic_loss_3/mul_grad/BroadcastGradientArgs (defined at /media/sdb2/AAAA_sdb2/zjp/MGNM/MGNM-main/code/model.py:60) ]]
Original stack trace for 'gradients/logistic_loss_3/mul_grad/BroadcastGradientArgs':
File "train.py", line 144, in
main()
File "train.py", line 99, in main
model = modelTy(item_count, user_count, DIMENSION, BATCH_SIZE, SEQ_LEN, NEG_NUM, HIDDEN_SIZE, NUM_PREFERENCE, NUM_LAYER, SE_NUM)
File "/media/sdb2/AAAA_sdb2/zjp/MGNM/MGNM-main/code/model.py", line 301, in init
self.build_multi_ce_loss(self.item_eb, user_eb_list)
File "/media/sdb2/AAAA_sdb2/zjp/MGNM/MGNM-main/code/model.py", line 60, in build_multi_ce_loss
self.optimizer = tf.train.AdamOptimizer(learning_rate=self.lr).minimize(self.loss)
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/training/optimizer.py", line 403, in minimize
grad_loss=grad_loss)
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/training/optimizer.py", line 512, in compute_gradients
colocate_gradients_with_ops=colocate_gradients_with_ops)
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/ops/gradients_impl.py", line 158, in gradients
unconnected_gradients)
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/ops/gradients_util.py", line 731, in _GradientsHelper
lambda: grad_fn(op, *out_grads))
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/ops/gradients_util.py", line 403, in _MaybeCompile
return grad_fn() # Exit early
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/ops/gradients_util.py", line 731, in
lambda: grad_fn(op, *out_grads))
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/ops/math_grad.py", line 1044, in _MulGrad
rx, ry = gen_array_ops.broadcast_gradient_args(sx, sy)
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py", line 829, in broadcast_gradient_args
"BroadcastGradientArgs", s0=s0, s1=s1, name=name)
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 788, in _apply_op_helper
op_def=op_def)
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3616, in create_op
op_def=op_def)
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2005, in init
self._traceback = tf_stack.extract_stack()
...which was originally created as op 'logistic_loss_3/mul', defined at:
File "train.py", line 144, in
main()
[elided 1 identical lines from previous traceback]
File "/media/sdb2/AAAA_sdb2/zjp/MGNM/MGNM-main/code/model.py", line 301, in init
self.build_multi_ce_loss(self.item_eb, user_eb_list)
File "/media/sdb2/AAAA_sdb2/zjp/MGNM/MGNM-main/code/model.py", line 51, in build_multi_ce_loss
loss.append(tf.reduce_sum(tf.nn.sigmoid_cross_entropy_with_logits(labels=tf.reshape(self.label, (-1, )), logits=tf.reshape(logits_tmp, (-1, )))))
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/ops/nn_impl.py", line 183, in sigmoid_cross_entropy_with_logits
relu_logits - logits * labels,
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", line 884, in binary_op_wrapper
return func(x, y, name=name)
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", line 1180, in _mul_dispatch
return gen_math_ops.mul(x, y, name=name)
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/ops/gen_math_ops.py", line 6490, in mul
"Mul", x=x, y=y, name=name)
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 788, in _apply_op_helper
op_def=op_def)
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3616, in create_op
op_def=op_def)
File "/home/ps/anaconda3/envs/zjp-mgnm/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2005, in init
self._traceback = tf_stack.extract_stack()
".
How to solve this problem?
thank you
Mar 10
'23 02:03
wy-0
Hi, I also ran into the problem. Have you fixed it? If so, could you please share how you fix it? Thank you in advance!
Edited on Aug. 3, 2023:
Hi, I fixed this and opened an issue. You can check it and hope it'll help.
Hi, I also ran into the problem. Have you fixed it? If so, could you please share how you fix it? Thank you in advance!
Edited on Aug. 3, 2023: Hi, I fixed this and opened an issue. You can check it and hope it'll help.
Hi, what's the meaning of se_num in this model?
Hi, I also ran into the problem. Have you fixed it? If so, could you please share how you fix it? Thank you in advance!
Edited on Aug. 3, 2023: Hi, I fixed this and opened an issue. You can check it and hope it'll help.
Hi, what's the meaning of se_num in this model?
I have no idea actually, but L21 in train.py says, quote, 'don't care this parameter', so I just left it to 0.