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

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

Open
Jan-No opened this issue Nov 21, 2019 · 8 comments
Open

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

Jan-No opened this issue Nov 21, 2019 · 8 comments

Comments

@Jan-No
Copy link

Jan-No commented Nov 21, 2019

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
Copy link
Author

Jan-No commented Nov 22, 2019

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
Copy link

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

@wjcheon
Copy link

wjcheon commented Mar 25, 2020

It works good ! @Datadote

@pimonteiro
Copy link

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
Copy link

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
Copy link

LuoXubo commented Apr 19, 2021

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

@KarthiAru
Copy link

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
Copy link

naseemap47 commented Jun 29, 2022

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]

Repository owner deleted a comment from technosoft-admin Mar 4, 2024
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

9 participants