keras-team / keras-applications

Reference implementations of popular deep learning models.
Other
2k stars 910 forks source link

Trouble loading new ResNet models #100

Closed mazatov closed 5 years ago

mazatov commented 5 years ago

I updated Keras to the latest version with pip install -U git+https://github.com/keras-team/keras git+https://github.com/keras-team/keras-applications

I can now load the new ResNet libraries like ResNet101 or ResNet152, but I cannot create a model with them yet. I'm guessing I am forgetting something trivial but I've been cracking my head on this for 2 days and cannot figure it out. Any help would be appreciated!!

Thanks

`from keras.applications import resnet

net = resnet.ResNet101(weights = 'imagenet', include_top=False)
Traceback (most recent call last):

  File "<ipython-input-24-73ad73bb4594>", line 1, in <module>
    net = resnet.ResNet101(weights = 'imagenet', include_top=False)

  File "c:\users\popeye\appdata\local\programs\python\python35\lib\site-packages\keras\applications\__init__.py", line 28, in wrapper
    return base_fun(*args, **kwargs)

  File "c:\users\popeye\appdata\local\programs\python\python35\lib\site-packages\keras\applications\resnet.py", line 19, in ResNet101
    return resnet.ResNet101(*args, **kwargs)

AttributeError: 'NoneType' object has no attribute 'ResNet101'`
see-- commented 5 years ago

Duplicate of #79 pip install -U git+https://github.com/keras-team/keras git+https://github.com/keras-team/keras-applications

mazatov commented 5 years ago

As I mentioned in the post, I already did that and got the error after the install. Also, I don't get the error during the import of the resnet. I only get the error when I create the model.

Duplicate of #79 pip install -U git+https://github.com/keras-team/keras git+https://github.com/keras-team/keras-applications

taehoonlee commented 5 years ago

@mazatov, Can you share the error message for from keras_applications import resnet?

mazatov commented 5 years ago

@taehoonlee, that's the weird part. I do NOT get an error for import part. Check the code in my first comment. I only get an error when creating the model.

taehoonlee commented 5 years ago

@mazatov, I need from keras_applications import resnet NOT from keras.applications import resnet.

mazatov commented 5 years ago

Sorry!

Here's the error:

from keras_applications import resnet
Traceback (most recent call last):

  File "<ipython-input-26-4d556de68345>", line 1, in <module>
    from keras_applications import resnet

ImportError: cannot import name 'resnet'
taehoonlee commented 5 years ago

Then, maybe your keras-app is not the bleeding edge. Please make sure pip install -U git+https://github.com/keras-team/keras-applications,

see-- commented 5 years ago

@mazatov The problem is that you did not install the bleeding edge. Maybe you have multiple python versions. pip3 instead of pip might fix your problem.

mazatov commented 5 years ago

Thanks, everybody! After uninstalling and installing everything a few times I got it to work. Not sure what was the issue, but it seems to work now.

EstelleAlemy commented 5 years ago

Hello ! I use keras 2.2.4. I have the same issue, does anyone have the solution.

detkov commented 5 years ago

Hello ! I use keras 2.2.4. I have the same issue, does anyone have the solution.

I'm having same issue. Tried Google Colab and Kaggle Kernels - same result: ImportError: cannot import name 'resnet

You should do pip install -U git+https://github.com/keras-team/keras git+https://github.com/keras-team/keras-applications and then from keras_applications import <what_you_need>. So i solved this problem like that

DarkDetectiv commented 5 years ago

I'm having same issue, i've install pip install -U git+https://github.com/keras-team/keras git+https://github.com/keras-team/keras-applications but found error. here is the error

Tempat Install package atau module

!pip install -U git+https://github.com/keras-team/keras git+https://github.com/keras-team/keras-application

Collecting git+https://github.com/keras-team/keras Cloning https://github.com/keras-team/keras to c:\users\lenovo\appdata\local\temp\pip-req-build-54p30x38

Error [WinError 2] The system cannot find the file specified while executing command git clone -q https://github.com/keras-team/keras C:\Users\LENOVO\AppData\Local\Temp\pip-req-build-54p30x38 Cannot find command 'git' - do you have 'git' installed and in your PATH?

thanks for any helps :D

taehoonlee commented 5 years ago

@DarkDetectiv, It doesn't seem to be a Keras issue. The error message is Cannot find command 'git' - do you have 'git' installed and in your PATH?. You should install git first.

ya332 commented 4 years ago

For people who come in late, lates keras docs have the folllowing ResNet models:

keras.applications.resnet.ResNet50(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.resnet.ResNet101(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.resnet.ResNet152(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.resnet_v2.ResNet50V2(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.resnet_v2.ResNet101V2(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.resnet_v2.ResNet152V2(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)

This means to import the models (lets say ResNet50), one has to do the following: from keras.applications.resnet50 import ResNet50 model = ResNet50(weights='imagenet') etc

Source:Keras Docs

zerzavot commented 3 years ago

Use this one from keras.applications.resnet import ResNet101 or u can import another version of resnet according to your selection from keras.applications.resnet50 import ResNet50