-
Notifications
You must be signed in to change notification settings - Fork 26
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
Unable to create basic model #8
Comments
I should mention that the command sm.set_framework('tf.keras') does not fix this error |
I added requirements.txt. And checked on my PC - working ok.
Please install them and check one more time. Also please uninstall keras:
|
Hello, thank you for your response. I have created a fresh environment with tensorflow==2.6.2. I uninstalled keras and have the aforementioned packages with the correct version. I imported tensorflow.keras as keras, and imported segmentation_models_3D, however I now get a different error: Traceback (most recent call last): |
I got the same error using tensorflow==1.15.0 |
Can you run file |
Hello, that ran successfully. The missing line that's critical for my environment is: os.environ["KERAS_BACKEND"] = "tensorflow" Perhaps that should be mentioned somewhere. Thanks very much for your help |
Thanks for info I will add it in README. |
Even after this, on python 3.8 I still get:
from running:
|
Can you post the full error trace? |
Sure:
Looks pretty similar to the original, coming from keras normalization.py.
|
Can you also print your versions of:
|
|
Can you try this:
|
Yep that works!
|
Hello, your example on the main page doesn't show you have to put in the input_shape, however when I do not specify this I get an error. If you do indeed need to specify the input_shape please update the example for future users :) |
It was resolved by adding
before importing unet. Also, do not import keras, just use tensorflow. |
ModuleNotFoundError: No module named 'keras.engine' when importing segmentation_models_3D |
I also had the same error while I was using There can be two solutions to this: Either roll back to a previous version of tensorflow (I rolled back to 2.12.0) or do the following:
|
Thank you so much for the solution.
…On Sun, Sep 24, 2023, 10:05 AM Navyansh Mahla ***@***.***> wrote:
ModuleNotFoundError: No module named 'keras.engine' when importing
segmentation_models_3D
I also had the same error while I was using tensorflow==2.13.0
I rolled back to version 2.12.0 and it's working all fine for me. This is
probably because Tensorflow 2.13.0 changed how we import keras modules
which are not part of public APIs. In these cases direct imports won't
work. keras.engine is not part of the public API.
There can be two solutions to this: Either roll back to a previous version
of tensorflow (I rolled back to 2.12.0) or do the following:
I'm stating this from the official git repository of tensorflow releases
<https://github.com/tensorflow/tensorflow/releases/tag/v2.13.0>:
If you were using import keras and you used keras functions that were not
public APIs, but were accessible in earlier versions with direct imports.
In those cases, please use the following guideline:
- The API may be available in the public Keras API under a different
name, so make sure to look for it on keras.io or TensorFlow docs and
switch to the public version.
segmentation-models-3D uses classification-models-3D where you can easily
see that it uses keras.engine. Sadly, that hasn't still been changed for
newer tf versions. So the best way is to roll back to previous versions.
—
Reply to this email directly, view it on GitHub
<#8 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZ34NESUKIQZRSSJG4A4UK3X37ZUHANCNFSM5MLNEDQA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Hello, I have the following environments:
tensorflow==1.15.0 and keras==2.3.1 and python==3.6
When I try to run the basic line:
model1 = sm.Unet('resnet34', encoder_weights='imagenet')
I get this error:
File "", line 1, in
File "/Users/karl.landheer/opt/anaconda3/envs/Seg3D/lib/python3.6/site-packages/segmentation_models_3D/init.py", line 34, in wrapper
return func(*args, **kwargs)
File "/Users/karl.landheer/opt/anaconda3/envs/Seg3D/lib/python3.6/site-packages/segmentation_models_3D/models/unet.py", line 231, in Unet
**kwargs,
File "/Users/karl.landheer/opt/anaconda3/envs/Seg3D/lib/python3.6/site-packages/segmentation_models_3D/backbones/backbones_factory.py", line 102, in get_backbone
model = model_fn(*args, **kwargs)
File "/Users/karl.landheer/opt/anaconda3/envs/Seg3D/lib/python3.6/site-packages/classification_models_3D/models_factory.py", line 74, in wrapper
return func(*args, **new_kwargs)
File "/Users/karl.landheer/opt/anaconda3/envs/Seg3D/lib/python3.6/site-packages/classification_models_3D/models/resnet.py", line 321, in ResNet34
**kwargs
File "/Users/karl.landheer/opt/anaconda3/envs/Seg3D/lib/python3.6/site-packages/classification_models_3D/models/resnet.py", line 231, in ResNet
x = layers.BatchNormalization(name='bn_data', **no_scale_bn_params)(img_input)
File "/Users/karl.landheer/opt/anaconda3/envs/Seg3D/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 824, in call
self._maybe_build(inputs)
File "/Users/karl.landheer/opt/anaconda3/envs/Seg3D/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 2146, in _maybe_build
self.build(input_shapes)
File "/Users/karl.landheer/opt/anaconda3/envs/Seg3D/lib/python3.6/site-packages/tensorflow_core/python/keras/layers/normalization.py", line 289, in build
raise ValueError('Invalid axis: %d' % x)
I have tried many permutations of different versions of keras and tensorflow, but to no avail. Any ideas?
The text was updated successfully, but these errors were encountered: