Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'KerasTensor' object has no attribute '_keras_shape #9

Open
Vidhya-Vidhya opened this issue Apr 18, 2022 · 2 comments
Open

'KerasTensor' object has no attribute '_keras_shape #9

Vidhya-Vidhya opened this issue Apr 18, 2022 · 2 comments

Comments

@Vidhya-Vidhya
Copy link

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 base_model+'_'+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
Copy link

try replace '_keras_shape' to 'shape'

@bolgoff
Copy link

bolgoff commented Jan 20, 2024

try replace '_keras_shape' to 'shape'

Yeah. That's worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants