TypeError: Input 'y' of 'Sub' Op has type float32 that does not match type int64 of argument 'x'
TypeError: Input 'y' of 'Sub' Op has type float32 that does not match type int64 of argument 'x'
错误:
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 有数据类型 = 'float32'
y_true[:, :, 4*num_classes:] dtype = 'int64'
当您尝试从 dtype('int64')
中减去 dtype('float32')
时出现错误
要解决这个问题,您需要更改两个变量的数据类型。在我的例子中,y_pred
和 y_true
是 4D 张量,所以你需要 tf.cast(y_pred|y_true, tf.float32|tf.int64)
。这意味着您可以将两者都转换为 int64
或 float32
。两者都可以。
错误:
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 有数据类型 = 'float32'
y_true[:, :, 4*num_classes:] dtype = 'int64'
当您尝试从 dtype('int64')
dtype('float32')
时出现错误
要解决这个问题,您需要更改两个变量的数据类型。在我的例子中,y_pred
和 y_true
是 4D 张量,所以你需要 tf.cast(y_pred|y_true, tf.float32|tf.int64)
。这意味着您可以将两者都转换为 int64
或 float32
。两者都可以。