ZFTurbo / segmentation_models_3D

Set of models for segmentation of 3D volumes
MIT License
125 stars 26 forks source link

import error #4

Closed menari123 closed 2 years ago

menari123 commented 3 years ago

Hello, I'm using tensorflow 2.5.0 and keras 2.4.3 and i get the error in import: ImportError: You need to first import keras in order to use keras_applications. For instance, you can do: import keras from keras_applications import vgg16 Or, preferably, this equivalent formulation: ``` from keras import applications

ZFTurbo commented 3 years ago

1) Please post full error stack. 2) Try to set "sm.set_framework('tf.keras')"

menari123 commented 3 years ago

I'm using tensorflow 2.5.0, keras 2.4.3, python 3.8 and anaconda3. I run pip install segmentation-models-3d and when i run import segmentation_models_3d i get this error:


ImportError Traceback (most recent call last) ~/anaconda3/lib/python3.8/site-packages/segmentation_models_3D/init.py in 97 try: ---> 98 set_framework(_framework) 99 except ImportError:

~/anaconda3/lib/python3.8/site-packages/segmentation_models_3D/init.py in set_framework(name) 70 from tensorflow import keras ---> 71 import efficientnet_3D.tfkeras # init custom objects 72 else:

~/anaconda3/lib/python3.8/site-packages/efficientnet_3D/tfkeras.py in 1 from . import inject_tfkeras_modules, init_tfkeras_custom_objects ----> 2 from . import model 3

~/anaconda3/lib/python3.8/site-packages/efficientnet_3D/model.py in 33 from six.moves import xrange ---> 34 from keras_applications.imagenet_utils import _obtain_input_shape 35 from keras_applications.imagenet_utils import preprocess_input as _preprocess_input

~/anaconda3/lib/python3.8/site-packages/keras_applications/imagenet_utils.py in 12 ---> 13 backend = get_keras_submodule('backend') 14 keras_utils = get_keras_submodule('utils')

~/anaconda3/lib/python3.8/site-packages/keras_applications/init.py in get_keras_submodule(name) 38 if _KERAS_BACKEND is None: ---> 39 raise ImportError('You need to first import keras ' 40 'in order to use keras_applications. '

ImportError: You need to first import keras in order to use keras_applications. For instance, you can do:

import keras
from keras_applications import vgg16

Or, preferably, this equivalent formulation:

from keras import applications

During handling of the above exception, another exception occurred:

ImportError Traceback (most recent call last)

in ----> 1 import segmentation_models_3D as sm ~/anaconda3/lib/python3.8/site-packages/segmentation_models_3D/__init__.py in 99 except ImportError: 100 other = _TF_KERAS_FRAMEWORK_NAME if _framework == _KERAS_FRAMEWORK_NAME else _KERAS_FRAMEWORK_NAME --> 101 set_framework(other) 102 103 print('Segmentation Models: using `{}` framework.'.format(_KERAS_FRAMEWORK)) ~/anaconda3/lib/python3.8/site-packages/segmentation_models_3D/__init__.py in set_framework(name) 66 if name == _KERAS_FRAMEWORK_NAME: 67 import keras ---> 68 import efficientnet_3D.keras # init custom objects 69 elif name == _TF_KERAS_FRAMEWORK_NAME: 70 from tensorflow import keras ~/anaconda3/lib/python3.8/site-packages/efficientnet_3D/keras.py in 1 from . import inject_keras_modules, init_keras_custom_objects ----> 2 from . import model 3 4 from .preprocessing import center_crop_and_resize 5 ~/anaconda3/lib/python3.8/site-packages/efficientnet_3D/model.py in 32 33 from six.moves import xrange ---> 34 from keras_applications.imagenet_utils import _obtain_input_shape 35 from keras_applications.imagenet_utils import preprocess_input as _preprocess_input 36 ~/anaconda3/lib/python3.8/site-packages/keras_applications/imagenet_utils.py in 11 from . import get_keras_submodule 12 ---> 13 backend = get_keras_submodule('backend') 14 keras_utils = get_keras_submodule('utils') 15 ~/anaconda3/lib/python3.8/site-packages/keras_applications/__init__.py in get_keras_submodule(name) 37 'Requested: %s' % name) 38 if _KERAS_BACKEND is None: ---> 39 raise ImportError('You need to first `import keras` ' 40 'in order to use `keras_applications`. ' 41 'For instance, you can do:\n\n' ImportError: You need to first `import keras` in order to use `keras_applications`. For instance, you can do: ``` import keras from keras_applications import vgg16 ``` Or, preferably, this equivalent formulation: ``` from keras import applications
menari123 commented 3 years ago

image

ZFTurbo commented 3 years ago

Try to uninstall keras completely.

pip uninstall keras
mavaylon1 commented 2 years ago

You should make a requirements file