keras-deeplab-v3-plus icon indicating copy to clipboard operation
keras-deeplab-v3-plus copied to clipboard

'int' object has no attribute 'value'

Open Jan-No opened this issue 4 years ago • 8 comments

Hi,

I just found the project and was very eager to try it. However, if I want to create the model with:

`import segmentation_models as sm from model import Deeplabv3

deeplab_model = Deeplabv3(input_shape=(256, 256, 3), classes=1)

deeplab_model.compile(optimizer=Adam(), loss=[LossFunction().my_loss],
                      metrics=['accuracy', sm.metrics.IOUScore(threshold=0.5)])

print(deeplab_model)

`

I get an error:

Traceback (most recent call last): File "D:/Documents/road_detection/workspace_new/deeplab-v3-plus/Model.py", line 64, in <module> deeplab_model = Deeplabv3(input_shape=(256, 256, 3), classes=1) File "D:\Documents\road_detection\workspace_new\deeplab-v3-plus\deeplab_model.py", line 328, in Deeplabv3 expansion=1, block_id=0, skip_connection=False) File "D:\Documents\road_detection\workspace_new\deeplab-v3-plus\deeplab_model.py", line 178, in _inverted_res_block in_channels = inputs.shape[-1].value # inputs._keras_shape[-1] AttributeError: 'int' object has no attribute 'value'

What am I doing wrong? I am using tensorflow-gpu 2.0.0 and other models compile fine.

Thanks for input.

Best,

Jan

Jan-No avatar Nov 21 '19 06:11 Jan-No

I think the fix is as simple as just modifying line 178 to:

in_channels = inputs.shape[-1]

Please let me know if this fix is valid.

Jan-No avatar Nov 22 '19 04:11 Jan-No

If you want to use it in tensorflow 2, I suggest changing

in_channels = inputs.shape[-1].value to in_channels = inputs.shape.as_list()[-1]

https://github.com/tensorflow/tensorflow/pull/28461

Datadote avatar Jan 13 '20 05:01 Datadote

It works good ! @Datadote

wjcheon avatar Mar 25 '20 04:03 wjcheon

Hello! I'm getting the same error as you, but both the solutions @Datadote and @Jan-No proposed aren't working for me. The only difference of my environment is my tensorflow version, which is 2.4.0. Any idea?

pimonteiro avatar Jan 11 '21 15:01 pimonteiro

I found a solution that worked for me.

For this problem, keep code statement as it is ( in_channels = inputs.shape[-1].value ).

Install below versions.

  1. numpy==1.17.2
  2. keras==2.2.5
  3. tensorflow==1.15

If you are trying for tensorflow==2.4.0. I have not tried it but i doubt that its because of keras version.

ADITYA964 avatar Jan 31 '21 06:01 ADITYA964

If Datadote's solution doesn't work. Maybe you can try just removing ".value" .

LuoXubo avatar Apr 19 '21 09:04 LuoXubo

If you want to use it in tensorflow 2, I suggest changing

in_channels = inputs.shape[-1].value to in_channels = inputs.shape.as_list()[-1]

tensorflow/tensorflow#28461

This worked in TF 2.7.

KarthiAru avatar Nov 21 '21 08:11 KarthiAru

Hello! I'm getting the same error as you, but both the solutions @Datadote and @Jan-No proposed aren't working for me. The only difference of my environment is my tensorflow version, which is 2.4.0. Any idea?

Use tensorflow==2.7.0 and keras==2.7.0 and also edit the file changes.. in_channels = inputs.shape[-1].value to in_channels = inputs.shape.as_list()[-1]

naseemap47 avatar Jun 29 '22 13:06 naseemap47