titu1994 / keras-squeeze-excite-network

Implementation of Squeeze and Excitation Networks in Keras
MIT License
400 stars 118 forks source link

SEInceptionResNetV2 is not working, encountered two errors #22

Closed Arlan2191 closed 4 years ago

Arlan2191 commented 4 years ago

I tried to use the function SEInceptionResNetV2() within model.py as shown below, and the import was successful but when called raises a Type Error: () got an unexpected keyword argument 'scale' . The error traced the problem to be caused by this particular Lambda function call within the inception_resnet_block(), as shown below.

I then hypothesized maybe its related to my local installation of tensorflow being 2.2.0, so I proceeded to run model.py within Google Colab, which has tensorflow version == 2.3.0. But then I encountered a different error, it is still a Type Error but with details: 'NoneType' object is not subscriptable, as shown below.

Inside model.py local Machine

from keras_squeeze_excite_network.se_inception_resnet_v2 import SEInceptionResNetV2

model = SEInceptionResNetV2()

Error encountered in local:

File "model.py", line 3, in <module>
    model = SEInceptionResNetV2()
  File "C:\Users\acer\Anaconda3\python_scripts\keras-squeeze-excite-network\keras_squeeze_excite_network\se_inception_resnet_v2.py", line 280, in SEInceptionResNetV2
    block_idx=block_idx)
  File "C:\Users\acer\Anaconda3\python_scripts\keras-squeeze-excite-network\keras_squeeze_excite_network\se_inception_resnet_v2.py", line 161, in inception_resnet_block
    name=block_name)([x, up])
  File "C:\Users\acer\Anaconda3\envs\Resnet\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 922, in __call__
    outputs = call_fn(cast_inputs, *args, **kwargs)
  File "C:\Users\acer\Anaconda3\envs\Resnet\lib\site-packages\tensorflow\python\keras\layers\core.py", line 888, in call
    result = self.function(inputs, **kwargs)
TypeError: <lambda>() got an unexpected keyword argument 'scale'

Within inception_resnet_block that caused the error:

x = Lambda(lambda inputs, scale_: inputs[0] + inputs[1] * scale_,
               output_shape=K.int_shape(x)[1:],
               arguments={'scale': scale},
               name=block_name)([x, up])

Inside model.py in Google Colab:

from keras_squeeze_excite_network.se_inception_resnet_v2 import SEInceptionResNetV2

model = SEInceptionResNetV2()

Error encountered in Colab:

TypeError                                 Traceback (most recent call last)
<ipython-input-4-858f80a24425> in <module>()
----> 1 model = SEInceptionResNetV2()

1 frames
/content/drive/My Drive/test/keras_squeeze_excite_network/se.py in squeeze_excite_block(input_tensor, ratio)
     24     init = input_tensor
     25     channel_axis = 1 if K.image_data_format() == "channels_first" else -1
---> 26     filters = _tensor_shape(init)[channel_axis]
     27     se_shape = (1, 1, filters)
     28 

TypeError: 'NoneType' object is not subscriptable

And I want to point out that this is the only model that raised an error, the other models worked for both 2.3.0 and 2.2.0 versions of tensorflow.

Arlan2191 commented 4 years ago

I have fixed the issue, I simply changed the string 'scale' to 'scale_', as shown below. And did the same in colab and had to downgrade tensorflow=2.3.0 to tensorflow=2.2.0, and now it's working.

x = Lambda(lambda inputs, scale_: inputs[0] + inputs[1] * scale_,
               output_shape=K.int_shape(x)[1:],
               arguments={'scale_': scale_},
               name=block_name)([x, up])