Tensorflow 2.3: AttributeError: 'Tensor' object has no attribute 'numpy' with eager mode enabled

Viewed 279

I have seen other similar questions here but they didn't help me. I'm using tensorflow 2.3 and I'm having an issue when i try to call a function that returns a keras.Model .

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

I write here a snippet of my model

    inputs = Input(shape=(n_ch, height, width), batch_size=batchSize)

    conv_1 = Conv2D(16, (5, 5), kernel_initializer='he_normal', padding='same',data_format='channels_first')(inputs)
    conv_1 = BatchNormalization(axis=1)(conv_1)
    conv_1 = Activation("relu")(conv_1)
    conv_2 = Conv2D(16, (5, 5), kernel_initializer='he_normal', padding='same',data_format='channels_first')(conv_1)

    conv_2 = BatchNormalization(axis=1)(conv_2)
    conv_2 = Activation("relu")(conv_2)


    pool_1 = MaxPooling2D(pool_size=(2, 2), data_format='channels_first')(conv_2)


    unpool_1 = Lambda(unpool)(pool_1)

    conv_25 = Conv2D(16, (5, 5), kernel_initializer='he_normal', padding='same',data_format='channels_first')(unpool_1)
    conv_25 = BatchNormalization(axis=1)(conv_25)
    conv_25 = Activation("relu")(conv_25)
    conv_26 = Conv2D(1, (1, 1),data_format="channels_first",activation="sigmoid")(conv_25)
    print("Build decoder done..")

    model = Model(inputs=inputs, outputs=conv_26, name="SegNet")

    return model

I get an error here:

def unpool(pool):
    updates = pool.numpy()
    [...]

It says that pool is a Tensor object but I don't understand why. I want to use eager mode and tf.executing_eagerly() returns True. I also tried to set run_eagerly=True and/or tf.config.run_functions_eagerly(True) but nothing.

Any suggestions? I don't know what to do. Thank you

0 Answers
Related