相同元组上的断言错误(Tensorflow keras)

2024-05-05 17:08:20 发布

您现在位置:Python中文网/ 问答频道 /正文

x = tf.keras.layers.Input((2,))
z = x.shape
y = (None, 2)
print("z: ", z)
print("y: ", y)
assert z == y

输出:

z: (None, 2)
y: (None, 2)
Traceback (most recent call last):
  File "", line 113, in <module>
    assert z == y
AssertionError

当z和y是同一形状时,为什么会给出断言错误?你知道吗


Tags: nonemostinputlayerstflineassertcall
2条回答

你知道吗tensor.shape.as\u列表()将以列表格式显示形状。你知道吗

assert tuple(z.as_list()) == y

我想出来了。元组有不同的类型。你知道吗

print(type(z))
print(type(y))

Output: 
<class 'tensorflow.python.framework.tensor_shape.TensorShape'>
<class 'tuple'>

相关问题 更多 >