Issue ImportError: cannot import name 'layer_utils' from 'keras.utils'
Opened this issue · 13 comments
I'm simply having an Import error
Try running this code
>>> from keras_vggface import utils
Traceback (most recent call last):
....
ImportError: cannot import name 'layer_utils' from 'keras.utils' ...
from keras.utils import layer_utils
ImportError: cannot import name 'layer_utils' from 'keras.utils'
It seems that there seems to be an update needed with the modules. Probably anyone might be experiencing the same thing? Any solutions? Thanks
same issue for me. I think this package (last updated 2019?) is less compatible with the latest versions of tensorflow & keras.
I assume one would have to set up a package environment with tf and keras from around 2019-2020 to avoid this issue?
I solved this issue by reverting to keras version 2.12
The issue arose for me with tensorflow version 2.13.0 and keras version 2.13.1
My fix:
pip uninstall keras
pip install keras==2.12
now it imports layer_utils as well.
Seems like keras moved or deprecated layer_utils in the latest version of keras. Hope this helps.
@markusfloer What version of tensorflow are you using?
i have solved the same issue by doing some tweaks in importing packages
Use tensorflow while importing packages in keras_vggface/models.py
from tensorflow.python.keras.layers import Flatten, Dense, Input, GlobalAveragePooling2D, \
GlobalMaxPooling2D, Activation, Conv2D, MaxPooling2D, BatchNormalization, \
AveragePooling2D, Reshape, Permute, multiply
from keras_applications.imagenet_utils import _obtain_input_shape
from tensorflow.python.keras.utils.data_utils import get_file
from tensorflow.python.keras import backend as K
from keras_vggface import utils
from tensorflow.python.keras.utils.layer_utils import get_source_inputs
import warnings
from tensorflow.python.keras.models import Model
from tensorflow.python.keras import layers
Use tensorflow while importing packages in keras_vggface/models.py
from tensorflow.python.keras.layers import Flatten, Dense, Input, GlobalAveragePooling2D, \ GlobalMaxPooling2D, Activation, Conv2D, MaxPooling2D, BatchNormalization, \ AveragePooling2D, Reshape, Permute, multiply from keras_applications.imagenet_utils import _obtain_input_shape from tensorflow.python.keras.utils.data_utils import get_file from tensorflow.python.keras import backend as K from keras_vggface import utils from tensorflow.python.keras.utils.layer_utils import get_source_inputs import warnings from tensorflow.python.keras.models import Model from tensorflow.python.keras import layers
What tensorflow version? I am getting ImportError: cannot import name 'BatchNormalization' from 'tensorflow.python.keras.layers'
Use :
from keras.layers import BatchNormalization
Tensorflow v2 should work
@roycmeghna
That was helpful, I just needed to do the same in utils.py as well, now working
https://github.com/JagarYousef/keras-vggface
@roycmeghna That was helpful, I just needed to do the same in utils.py as well, now working https://github.com/JagarYousef/keras-vggface
hey your fork throws a new error now
ValueError: Argument name
must be a string and cannot contain character /
. Received: name=conv1/7x7_s2/bn (of type <class 'str'>)
any idea on how to fix this ?
@zodwick Did you find solution with it ? I get the same error
nope. couldn't spend too much time on it unfortunately. Needed this for a simple face recognition system for a collage project ended up using something else
You tried changing the import as some libraries need to be corrected, from keras import <lib_name> to from tensorflow.python.utils import <lib_name>?