Trouble with Installing Keras - python

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.

Related

Keras not being imported

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) ```

cant install Adam from keras.optimizer

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

import error of ArcFace using python in jupyternotebbok

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')

How can I fix this error in python 3.8 pycharm? It is about importing packages

This is the error it gives me when I try to run it:
Traceback (most recent call last):
File "/Users/kids/Library/Mail/V5/E60CBF1C-9021-4A10-8D60-06C96C141AF1/Outbox.mbox/E7C72E99-E3DB-4CDC-B1C9-15116F3478D8/Data/Attachments/405/2/ASL-Finger-Spelling-Recognition-master/main.py", line 10, in <module>
from keras.layers.convolutional import Convolution3D, MaxPooling3D
This is the code error which it is showing:
from keras.layers.convolutional import Convolution3D, MaxPooling3D
Keras version is 2.3.1. Python version is Python 3.8. Running on MacOS.
Your import statement
from keras.layers.convolutional import Convolution3D, MaxPooling3D
attempts to import MaxPooling3D from keras.layers.convolutional. MaxPooling3D is actually part of the pooling module, i.e. keras.layers.pooling.
According to the keras source and docs, the best way to import these two classes in a single statement would be
from keras.layers import Convolution3D, MaxPooling3D
Alternatively, you could import them separately:
from keras.layers.convolutional import Convolution3D
from keras.layers.pooling import MaxPooling3D
but in general, you should pay attention to what is purposefully exposed via the package; that is, the classes accessible from keras.layers.

I am using keras and I get an error message saying "No module named 'lstm'"

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

Categories

Resources