bonlime / keras-deeplab-v3-plus

Keras implementation of Deeplab v3+ with pretrained weights
MIT License
1.35k stars 428 forks source link

'int' object has no attribute 'value' #125

Open Jan-No opened 4 years ago

Jan-No commented 4 years ago

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 commented 4 years ago

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.

Datadote commented 4 years ago

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

wjcheon commented 4 years ago

It works good ! @Datadote

pimonteiro commented 3 years ago

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?

ADITYA964 commented 3 years ago

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.

LuoXubo commented 3 years ago

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

KarthiAru commented 2 years ago

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.

naseemap47 commented 2 years ago

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]