TF 2.0创建模型“Tensor”对象没有属性“numpy”

2024-10-16 20:50:35 发布

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

我执行下面的代码时出现以下错误

AttributeError: 'Tensor' object has no attribute 'numpy'

源代码


    inp = Input(shape=(TIME_STEPS, INPUT_DIM,))
    inp_time = Input(shape=(1,))
    print(tf.executing_eagerly())  # return True
    
    print(inp_time.numpy()) # error
    # inp_time=inp_time.eval()/ K.get_value()/ x.numpy()/ K.eval()
    x = ConvAtteShare(inp_time=inp_time.numpy(),kernel=(32,32),stride=(16,16),filter_num=3)(inp)
    x = Dense(kind_num,activation='softmax')(x)
    m = Model(inputs=[inp,inp_time], outputs=[x], name='convatte-test')
    print(m.summary())

错误

print(inp_time.numpy())

AttributeError: 'Tensor' object has no attribute 'numpy'

如果我是正确的,.Numpy仅在我应该运行的急切模式下受支持(请参阅print(tf.executing_agreely())返回true)

需要帮助找出错误以及哪里可能出错

谢谢你的帮助


Tags: nonumpyinputobjecttimetf错误attribute