kobiso / CBAM-keras

CBAM implementation on Keras
MIT License
359 stars 134 forks source link

'KerasTensor' object has no attribute '_keras_shape #9

Open Vidhya-Vidhya opened 2 years ago

Vidhya-Vidhya commented 2 years ago

Respected sir, I am getting the following error while using your code.

**depth = 20 base_model = 'inception_resnet_v2'

Choose what attention_module to use: cbam_block / se_block / None

attention_module = 'cbam_block' model_type = base_model if attention_module=='cbam_block' else basemodel+''+attention_module model = InceptionResNetV2(input_shape=(299,299,3), classes=num_classes, attention_module=attention_module)

AttributeError Traceback (most recent call last) Input In [7], in <cell line: 7>() ----> 7 model = InceptionResNetV2(input_shape=(299,299,3), classes=num_classes, attention_module=attention_module)

Input In [3], in InceptionResNetV2(include_top, weights, input_tensor, input_shape, pooling, classes, attention_module) 144 x = Concatenate(axis=channel_axis, name='mixed_5b')(branches) 146 # squeeze and excite block --> 147 x = se_block(x) 149 # 10x block35 (Inception-ResNet-A block): 35 x 35 x 320 150 for block_idx in range(1, 11):

Input In [1], in se_block(input_feature, ratio) 15 def se_block(input_feature, ratio=8): 18 channel_axis = 1 if K.image_data_format() == "channels_first" else -1 ---> 19 channel = input_feature._keras_shape[channel_axis] 21 se_feature = GlobalAveragePooling2D()(input_feature) 22 se_feature = Reshape((1, 1, channel))(se_feature)

AttributeError: 'KerasTensor' object has no attribute '_keras_shape'

I am using jupyter command prompt in anaconda. my python version is 3.6, tensorflow =2.2.0, keras=2.3.1 while using tensorflow =1.13.1 keras=2.2.0 in colab the code is running. but in jupyter the same version and the above version is not running. so kindly guide me to fix the issues as soon as possible

junjie2008v commented 2 years ago

try replace '_keras_shape' to 'shape'

bolgoff commented 7 months ago

try replace '_keras_shape' to 'shape'

Yeah. That's worked