I'm currently building a MLP network using the MNIST data set in python. My script can import the mnist module and access the datasets when it's running in the default runtime environment but whenever I try to run it using pypy I get the error
Traceback (most recent call last):
File "LearningProgram.py", line 1, in <module>
from mnist import MNIST
ModuleNotFoundError: No module named 'mnist'
This is how I import mnist if it matters
from mnist import MNIST
import random
import numpy as np
import math
from math import e
from math import log
I've tried uninstalling and reinstalling mnist but it didn't work. I'm also using python 3.8.1
Related
I am trying to use ImageAI’s model training to train an AI model.
This is the code:
from imageai.Prediction.Custom import ModelTraining
model_trainer = ModelTraining()
model_trainer.setModelTypeAsResNet()
model_trainer.setDataDirectory("idenprof")
model_trainer.trainModel(num_objects=2, num_experiments=3, enhance_data=True,
batch_size=32, show_network_summary=True)
This is the error I get when running:
Traceback (most recent call last):
File ".../FirstTraining.py", line 1, in <module>
from imageai.Prediction.Custom import ModelTraining
File ".../lib/python2.7/site-packages/imageai/Prediction/Custom/__init__.py", line 4, in <module>
from ..DenseNet.densenet import DenseNetImageNet121
File ".../PycharmProjects/bonez/venv/lib/python2.7/site-packages/imageai/Prediction/DenseNet/densenet.py", line 21, in <module>
from tensorflow.python.keras.utils import convert_all_kernels_in_model
ImportError: cannot import name convert_all_kernels_in_model
I have searched all over but I could not find the same issue or a way to solve the problem. I have the following dependencies installed: Tensorflow, OpenCV, Keras, and ImageAI.
Update: It turns out ImageAI does not support Tensorflow 2 yet. This issue does not happen with following tensorflow version: pip install tensorflow==1.15.2
I had the same issue and resolved it by replacing all tensorflow.python.keras imports with tensorflow.keras in ImageAI library. After this, from imageai.Prediction.Custom import ModelTraining import works fine.
If you want to follow, there is an open issue for problem in ImageAI: https://github.com/OlafenwaMoses/ImageAI/issues/494
I am following this tensorflow tutorial https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/install.html#protobuf-installation-compilation and I am facing some problems when testing the installation.
I installed everything except the COCO API in the tutorial and I am running the object detection demo in jupyter right now. For some reason, I get an error inside the notebook which tells me that there is "No module named 'tensorflow'". Can I still click on Run All or does this error has to be fixed?
Thanks! :)
import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile
from distutils.version import StrictVersion
from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image
# This is needed since the notebook is stored in the object_detection folder.
sys.path.append("..")
from object_detection.utils import ops as utils_ops
if StrictVersion(tf.__version__) < StrictVersion('1.12.0'):
raise ImportError('Please upgrade your TensorFlow installation to v1.12.*.')
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-34f5cdda911a> in <module>
4 import sys
5 import tarfile
----> 6 import tensorflow as tf
7 import zipfile
8
ModuleNotFoundError: No module named 'tensorflow'
Okay, for some reasons, I get this error now:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-34f5cdda911a> in <module>
10 from collections import defaultdict
11 from io import StringIO
---> 12 from matplotlib import pyplot as plt
13 from PIL import Image
14
ModuleNotFoundError: No module named 'matplotlib'
You might be facing the problem of a double version of Python installed on your computer. Jupyter is trying to compile the Tensorflow tutorial file but with the wrong kernel (which should be Python 3).
The same happened to me when trying to run ipynb files in which Tensorflow was included.
So I would first recommend you to do the following:
Check the output of this command in your command line:
jupyter kernelspec list
Then it should output something similar to this: (in case of Windows OS)
python3 c:\python 3.6.8\share\jupyter\kernels\python3
If you find "python2" or any other type of version, you should remove it manually or try by using the command :
jupyter kernelspec remove python_wrong_version
Finally, if the problem is still there you can also check the link https://github.com/jupyter/notebook/issues/397 for further discussions.
When I try to import tensorflow in my Python scripts, I have some weird results. For instance:
import tensorflow
from keras.datasets import imdb
gives me
ModuleNotFoundError
Traceback (most recent call last) <ipython-input-12-25cf0f878919> in <module>()
1 import tensorflow
----> 2 from keras.datasets import imdb
ModuleNotFoundError: No module named 'keras'
If I try:
import tensorflow as tf
from tf.keras.datasets import imdb
I get :
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-9-bd3db3d3567b> in <module>()
1 import tensorflow as tf
----> 2 from tf.keras.datasets import imdb
ModuleNotFoundError: No module named 'tf'
But, if I use :
from tensorflow.keras.datasets import imdb
it works.
I've been googling this for a full hour now, and I still don't understand what I'm doing wrong in the first two scripts.
Thanks
You haven't specified how and where you installed tensorflow, so I could be wrong, but:
(a) it appears that keras is installed with tensorflow, but not in a location that is in the default Python path (hence, you cannot do from keras.datasets import imdb).
(b) this combination:
import tensorflow as tf
from tf.keras.datasets import imdb
is invalid, because from x import y searches for x as a module and not as a symbol in your code's globals (and tf is NOT a module name but a global variable, import tensorflow as tf imports tensorflow and sets tf to point to the module object).
Therefore (unless you fix your install or your PYTHONPATH to make keras visible as a module), you should use this to import keras (or specific symbols from it):
# either this, to access keras.*, e.g., keras.datasets.imdb
import tensorflow.keras as keras
# or this, as you've done in your example
from tensorflow.keras.datasets import imdb
I am having trouble getting tensorflow to work using Jupiter notebooks. I am a complete noob so please keep responses as simple as possible and apologies if this is trivial.
I run the following code in the notebook:
import tensorflow as tf
from tensorflow.python.framework import ops
And get this error message:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-15-509396287076> in <module>()
1
2 import tensorflow as tf
----> 3 from tensorflow.python.framework import ops
4 from tf_utils import load_dataset, random_mini_batches, convert_to_one_hot, predict
5
ModuleNotFoundError: No module named 'tensorflow.python'
(I originally struggled to get the "import tensorflow as tf" line to work but have resolved that. The code runs fine without the second line...)
Thanks for your help!
Hello l tried to run my python code and the errors is:
Traceback (most recent call last):
File "/home/anelmad/Desktop/simulation/Theano-Tutorials-master/3_net.py", line 5, in <module>
from foxhound.utils.vis import grayscale_grid_vis, unit_scale
ImportError: No module named vis**
knowing that l have correctly installed foxhound.
import theano
from theano import tensor as T
import numpy as np
from load import mnist
from foxhound.utils.vis import grayscale_grid_vis, unit_scale
from scipy.misc import imsave
is Foxhound a scikit? if yes, it doe's not contains utils module. You can clone it on github https://github.com/IndicoDataSolutions/Foxhound
I have met with the same problem. from foxhound vis import grayscale_grid_vis is enough. And I just comment out the other part. And the program works well. It seems that the module is not used.