rcmalli / keras-vggface

VGGFace implementation with Keras Framework
MIT License
933 stars 418 forks source link

Issue ImportError: cannot import name 'layer_utils' from 'keras.utils' #97

Open gelodefaultbrain opened 1 year ago

gelodefaultbrain commented 1 year ago

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

markusfloer commented 1 year ago

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?

markusfloer commented 1 year ago

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.

Kidkender commented 1 year ago

@markusfloer What version of tensorflow are you using?

Dead-Bytes commented 8 months ago

i have solved the same issue by doing some tweaks in importing packages

roycmeghna commented 6 months ago

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
cergo123 commented 6 months ago

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'

roycmeghna commented 6 months ago

Use : from keras.layers import BatchNormalization Tensorflow v2 should work

cergo123 commented 6 months ago

@roycmeghna That was helpful, I just needed to do the same in utils.py as well, now working https://github.com/JagarYousef/keras-vggface

zodwick commented 5 months ago

@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 ?

x4080 commented 3 months ago

@zodwick Did you find solution with it ? I get the same error

zodwick commented 3 months ago

@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

x4080 commented 3 months ago

@zodwick Ok, thanks anyway

Dead-Bytes commented 3 months ago

You tried changing the import as some libraries need to be corrected, from keras import to from tensorflow.python.utils import ?