錯誤:
Exception: in user code:
/opt/conda/lib/python3.7/site-packages/keras/engine/training.py:853 train_function *
return step_function(self, iterator)
/tmp/ipykernel_34/1396363757.py:53 class_loss_regr_fixed_num *
x = y_true[:, :, 4*num_classes:] - y_pred
/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py:1383 binary_op_wrapper
raise e
/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py:1367 binary_op_wrapper
return func(x, y, name=name)
/opt/conda/lib/python3.7/site-packages/tensorflow/python/util/dispatch.py:206 wrapper
return target(*args, **kwargs)
/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py:548 subtract
return gen_math_ops.sub(x, y, name)
/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/gen_math_ops.py:10654 sub
"Sub", x=x, y=y, name=name)
/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/op_def_library.py:558 _apply_op_helper
inferred_from[input_arg.type_attr]))
TypeError: Input 'y' of 'Sub' Op has type float32 that does not match type int64 of argument 'x'.
Exception: 'NoneType' object is not callable
此錯誤介於圖像類型和標籤類型之間。從上面的圖像類型是 int64 而標籤類型是 float32。你可以看看我的筆記本了解更多細節。我無法理解問題是什麼,因為我是這個領域的新手。
這個錯誤來自行x = y_true[:, :, 4*num_classes:] - y_pred
。
在這個TypeError: Input 'y' of 'Sub' Op has type float32 that does not match type int64 of argument 'x'
===>'y' = y_pred
和'x' = y_true[:, :, 4*num_classes:]
y_pred 有 dtype = 'float32'
y_true[:, :, 4*num_classes:] 有 dtype = 'int64'
當您嘗試dtype('float32')
從dtype('int64')
要解決這個問題,您需要更改兩個變量的數據類型。在我的情況下,y_pred
並且y_true
是 4D 張量,所以你需要tf.cast(y_pred|y_true, tf.float32|tf.int64)
. 這意味著您可以將兩者都轉換為int64
或float32
。兩者都會起作用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句