When I am importing the package ArcFace.
from arcface.metrics import ArcFace
It is showning the import error. Like this,
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-4-fe2759a1802e> in <module>
15 from keras.layers.convolutional import MaxPooling2D
16 from keras.layers.core import Activation, Flatten, Dropout, Dense
---> 17 from arcface.metrics import ArcFace
18 from keras.layers import Input
19 from keras import backend as K
ModuleNotFoundError: No module named 'arcface'
I have searched for importing it for Anaconda and pip too. I have not found any results. Please help me to solve this.
This is part of project keras-arcface but it is not part of keras so you have to install/copy it separatelly.
If you put it in your project in subfolder arcface then it should work.
You can run ArcFace within deepface. The framework is mainly based on keras and tensorflow. It handles model building and downloading pre-trained weights in the background. Besides, it covers face recognition pipeline stages includign detect, align.
#!pip install deepface
from deepface import DeepFace
resp = DeepFace.verify("img1.jpg", "img2.jpg", model_name = 'ArcFace')
Related
I was trying to run this code, first time using Tensorflow API in Python. Donwloaded latest version of tensorflow and pip through terminal. However, when I attempt to import from keras subpackage, an error is returned
from keras.models import Model
from keras.layers import Dense
from keras.layers import Input
ImportError: cannot import name 'pywrap_tensorflow' from partially initialized module 'tensorflow.python' (most likely due to a circular import) (/Users/macbook/Library/Python/3.9/lib/python/site-packages/tensorflow/python/__init__.py) ```
Was working on google colab yesterday and everything works fine. but now I got a problem when trying to import Adam.
this is what I try to import
from keras.optimizers import Adam, SGD, RMSprop
this is what I got
ImportError Traceback (most recent call last)
<ipython-input-1-36a1fe725448> in <module>()
30 from keras.layers import GlobalAveragePooling2D
31 from keras.layers import BatchNormalization, Activation, MaxPooling2D
---> 32 from keras.optimizers import Adam, SGD, RMSprop
ImportError: cannot import name 'Adam' from 'keras.optimizers' (/usr/local/lib/python3.7/dist-packages/keras/optimizers.py)
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
Try to import from tf.keras as follows
from tensorflow.keras.optimizers import Adam, SGD, RMSprop
You can call the Adam optimizer function using TensorFlow:
from tensorflow.keras.optimizers import Adam
I have been running several deep learning models in google colab using Keras.
My codes worked perfectly but suddenly, today, a lot of errors appeared reporting problemas with the imports. Pasting one here.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-3-745bb0894037> in <module>()
19 from keras.preprocessing.image import ImageDataGenerator
20 from keras.utils import np_utils
---> 21 from keras_contrib.applications.densenet import DenseNetFCN
22 from keras_contrib.losses.jaccard import jaccard_distance
1 frames
/usr/local/lib/python3.7/dist-packages/keras_contrib/applications/densenet.py in <module>()
66 from keras.layers import BatchNormalization
67 from keras.regularizers import l2
---> 68 from keras.utils.layer_utils import convert_all_kernels_in_model
69 from keras.utils.data_utils import get_file
70 from keras.engine.topology import get_source_inputs
ImportError: cannot import name 'convert_all_kernels_in_model' from 'keras.utils.layer_utils' (/usr/local/lib/python3.7/dist-packages/keras/utils/layer_utils.py)
so I am answering my question for anyone who might have trouble with it.
They updated Tensorflow and Keras in Colab to 2.5 versions, and some functions are not migrated (i.e. convert_all_kernels_in_model).
For me, the solution was to paste the code of the NN architecture and comment the line with that function as I was not using it.
I know it is not the best solution but it got me through what I needed.
The final release of TensorFlow version 2.5 requires a nightly dev build of keras that seems to be the source of these issues.
https://github.com/tensorflow/tensorflow/blob/v2.5.0/tensorflow/tools/pip_package/setup.py#L107
The relevant TensorFlow issue to report your experience is:
https://github.com/tensorflow/tensorflow/issues/49823
I have tried several things, and I am experiencing many difficulties in trying to install keras to Python.
First, I tried by simply trying to import it into my Jupyter Notebook using the following:
from keras.models import Sequential
from keras.layers import Dense
which resulted in the following error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-17-b9e2c8277ae4> in <module>
----> 1 from keras.models import Sequential
2 from keras.layers import Dense
ModuleNotFoundError: No module named 'keras'
Then, I tried importing tensorflow.
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense,Dropout,Activation, Flatten, Conv2D, MaxPooling2D
This didn't work either, for I received a similar error as before.
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-18-9d4e366b5092> in <module>
----> 1 from tensorflow.keras.models import Sequential #used for model building
2 from tensorflow.keras.layers import Dense,Dropout,Activation, Flatten, Conv2D, MaxPooling2D #used for model building
ModuleNotFoundError: No module named 'tensorflow'
I finally tried to use the terminal through Anaconda. This failed as well.
UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:
I have Python 3.8, but apparently keras requires python[version='>=2.7,<2.8.0a0|>=3.5,<3.6.0a0|>=3.6,<3.7.0a0']. What can I do to import keras?
For whatever reason, keras and tensorflow don't work well with Python 3.8. I would try reverting to Python 3.7.
I am trying to set up Keras with the following code:
from keras.layers.core import Dense, Activation, Dropout
from keras.layers.recurrent import LSTM
from keras.models import Sequential
import lstm, time #helper libraries
Unfortunately it gives me two error message and I can't get my head around it:
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap.py:205: RuntimeWarning: compiletime version 3.5 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.6
return f(*args, **kwds)
and
ModuleNotFoundError Traceback (most recent call last)
ModuleNotFoundError: No module named 'lstm'
Thanks in advance,
Victor
Use one of the following two:
pip install seq2seq-lstm
or
pip install phased-lstm-keras
For me, the following solved the issue:
from keras.layers import LSTM