I am on windows using Anaconda with python 3.6, I have installed keras by:
conda install -c conda-forge keras
and whene i try this code
from keras.models import Graph
I get this error message:
ImportError Traceback (most recent call last)
<ipython-input-4-74d2d1fd7bad> in <module>()
----> 1 from keras.models import Graph
ImportError: cannot import name 'Graph'
This is not a Python issue. This is because the latest version of keras has removed Graph module from models. You can surely check the documentation.
If you check this Github issue (Why Keras remove graph model?), you can use the following line of code:
from .legacy.models import Graph
However, it is suggested to use functional API instead. Please check The Functional API
Related
Code is running properly in local windows machine but gives error while importing spacy.training in collab
what can be the problem?
from spacy.training import Example
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-ebc5aa3cff21> in <module>()
3 from spacy.util import minibatch, compounding
4 from pathlib import Path
----> 5 from spacy.training import Example
6 # TRAINING THE MODEL
7 with nlp.disable_pipes(*unaffected_pipes):
ModuleNotFoundError: No module named 'spacy.training'
I believe You have spacy 2 on your colab.
You need to import spacy with all the modules again on colab.
It is independent from Windows spacy.
You can check your version of spacy and update it using below instructions:
Run this command on your Jupyter cell:
!pip show spacy
OR
spacy.__version__
Once you check the version, you can update to a latest version by:
!pip install -U spacy
Once, you get spacy 3 your problem will be resolved.
Example was introduced in spacy version 3.
Link to Example :
https://spacy.io/api/example#_title
Make sure to Restart Runtime from the menu bar in colab.
I was trying to kaggle kernel of Bayesian Hyperparam Optimization of RF. And I couldn't import sklearn.gaussian_process.GaussianProcess. Please help this poor scikit-learn newbie.
from sklearn.gaussian_process import GaussianProcess as GP
error:
Traceback (most recent call last):
File "C:/Users/Develop/PycharmProjects/reinforcement recommandation system/BNP/bayesianoptimization-of-random-forest.py", line 24, in <module>
from sklearn.gaussian_process import GaussianProcess as GP
ImportError: cannot import name 'GaussianProcess' from 'sklearn.gaussian_process' (C:\Users\Develop\PycharmProjects\reinforcement recommandation system\lib\site-packages\sklearn\gaussian_process\__init__.py)
Process finished with exit code 1
Depending on whether you need the regressor or classifier:
from sklearn.gaussian_process import GaussianProcessRegressor as GP
from sklearn.gaussian_process import GaussianProcessClassifier as GP
Also, have a look at the different modules
It seems that you have to use the old scikit-learn version 0.15-git
The documentation for sklearn.gaussian_process.GaussianProcess is located here:
https://scikit-learn.org/0.15/modules/generated/sklearn.gaussian_process.GaussianProcess.html
I just had the same problem, but I will move on to try to understand if sklearn.gaussian_process.GaussianProcessRegressor in the current version scikit-learn 1.0.2 will work for my purposes.
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn import svm
it gives the following error-
Traceback (most recent call last):
File "/home/songoku/PycharmProjects/untitled/sklearn.py", line 4, in <module>
from sklearn import datasets
File "/home/songoku/PycharmProjects/untitled/sklearn.py", line 4, in <module>
from sklearn import datasets
ImportError: cannot import name 'datasets'
Rename /home/songoku/PycharmProjects/untitled/sklearn.py to something that differs from the SKLearn module name: sklearn.py
Try checking the version of sklearn first. The modules like data-sets and svm is not a part of sklearn packages (0.19 <) i.e less than version number 0.19.0.
You can check this on the command line: pip3 list
it shows you the version of all libraries installed by pip3.
Note: Always double check if you istalled the libraries as a part of anaconda or pip3
Following the tutorial:
http://www.pyimagesearch.com/2016/08/10/imagenet-classification-with-python-and-keras/#comment-419896
Using these files:
https://github.com/fchollet/deep-learning-models
I get 2 separate errors depending on how I execute:
Running in PyCharm:
Using TensorFlow backend.
usage: test_imagenet.py [-h] -i IMAGE
test_imagenet.py: error: the following arguments are required: -i/--image
Running in cmd line:
C:\Users\AppData\Local\Programs\Python\Python35\Scripts>python deep-learning-models/test_imagenet.py --image deep-learning-models/images/dog.jpg
Traceback (most recent call last):
File "deep-learning-models/test_imagenet.py", line 2, in <module>
from keras.preprocessing import image as image_utils
ImportError: No module named keras.preprocessing
How do I resolve?
Its best if you solve this problem outside running the above script... Here is what you can try in your command line environment to make sure it works outside your script:
>>> import keras
Using TensorFlow backend.
>>> keras.__version__
'1.2.1'
>>> keras.preprocessing
<module 'keras.preprocessing' from '/usr/local/lib/python2.7/dist-packages/keras/preprocessing/__init__.pyc'>
>>> from keras.preprocessing import image as image_utils
>>>
Make sure you have latest version of keras installed. If you get above working then it could be the environment issue where above script is not able to find the keras package. However if above does not work or work partially you would need to install keras again by removing it first..
$ pip install keras --user
Every dependency in a python project need to be installed using pip or easy_install or from the source code. You will have to install the keras module as mentioned here.
This happened to me. It turned out I was working in a pyvenv which wasn't activated. Just run source bin/activate on Linux/Mac or Scripts\activate.bat on Windows
from keras.models import Sequential
from keras import legacy_tf_layer
from keras.preprocessing import image as image_utils
from keras.preprcessing.text import Toknizer
import pandas as pd
from sklearn.model_selection import train_test_spli
I'm following the instructions of the Deep Learning course by Google with TensorFlow. Unfortunately I'm stuck with this workbook right now.
I work in the docker vm with all the assignment code loaded as described here.
When I do all the imports everything works except for following line:
from sklearn.linear_model import LogisticRegression
it throws the following error:
>>> from sklearn.linear_model import LogisticRegression
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sklearn.linear_model
This SO answer sounds promising, but I did not find the source directory of sklearn.
Any help greatly aprreciated.
You can install and upgrade sklearn from the shell with pip. That may or may not be the problem - but at least you'll know its installed.
sudo pip install --upgrade scikit-learn
In your Jupyter notebook:
import pip
pip.main(['install', 'sklearn'])
Please take note that when you are writing your code, you'll import the sklearn package using import sklearn, but when installing the package it with, say, conda, you should do the following:
conda install scikit-learn