Having error with Tensorflow Mnist - python

I have just started to use Tensorflow and I have done "hello world" with my test.py file. Moving on to next step, I started to do tutorial(https://www.tensorflow.org/versions/master/tutorials/mnist/beginners/index.html).
This is what I have done
$ git clone https://github.com/tensorflow/tensorflow
and run the file of "fully_connected_feed.py "
python tensorflow/examples/tutorials/mnist/fully_connected_feed.py
I got the error like
Traceback (most recent call last):
File "tensorflow/examples/tutorials/mnist/fully_connected_feed.py",
line 27, in
from tensorflow.examples.tutorials.mnist import input_data
ImportError: No module named examples.tutorials.mnist
so I changed code from
from tensorflow.examples.tutorials.mnist import input_data
from tensorflow.examples.tutorials.mnist import mnist
to
import input_data
import mnist
but I got error again.
Traceback (most recent call last):
File "tensorflow/examples/tutorials/mnist/fully_connected_feed.py", line 27, in
import input_data
File
"/Users/naggi/Documents/ML/tensorflow/tensorflow/examples/tutorials/mnist/input_data.py", line 29, in
from tensorflow.contrib.learn.python.learn.datasets.mnist import read_data_sets
ImportError: No module named contrib.learn.python.learn.datasets.mnist
Could someone help me?
Thanks

Install via pip :
$ sudo apt-get install python-pip python-dev
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl

update pip to latest version
sudo easy_install --upgrade six
sudo pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0-py2-none-any.whl
It works for Mac os

Related

error: cannot import name 'model_lib_v2' from 'object_detection' [duplicate]

I'm trying to train TF2 for object detection. When I run model_main_tf2.py, I get the following error:
Traceback (most recent call last):
File "C:\Python_venv\trained_models\model_main_tf2.py", line 32, in <module>
from object_detection import model_lib_v2
ImportError: cannot import name 'model_lib_v2' from 'object_detection' (c:\Python_venv\tensorflow\lib\site-packages\object_detection\__init__.py)
How do I install model_lib_v2?
I tried reinstalling TF and reinstalling TensorFlow-object-detection-API but no luck. I went all over the internet looking for answers.
I found:
https://github.com/tensorflow/models/issues/7920
But they don't say how to install model_lib_v2
Unfortunately I cannot use TF1, the goal is to use TF2.
see https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2.md
git clone https://github.com/tensorflow/models.git
## Python Package Installation
cd models/research
### Compile protos.
protoc object_detection/protos/*.proto --python_out=.
### Install TensorFlow Object Detection API.
cp object_detection/packages/tf2/setup.py .
python3 -m pip install --user --use-feature=2020-resolver .
You should be able to just go to line 32 in "C:\Python_venv\trained_models\model_main_tf2.py" and remove "from object_detection", since you are already inside the package.
replace:
"from object_detection import model_lib_v2"
by:
"import model_lib_v2"

Numpy issue for racecar simulator: No module named 'numpy.core._multiarray_umath'

I am taking a course that uses a racecar simulator and I need to run some pre-built code that uses a custom library and also numpy. When I try to run the code on Ubuntu I get the following error:
Traceback (most recent call last):
File "/mnt/c/Users/seb/documents/Racecar/racecar-seb-h-s/labs/../library/numpy/core/__init__.py", line 22, in <module>
from . import multiarray
File "/mnt/c/Users/seb/documents/Racecar/racecar-seb-h-s/labs/../library/numpy/core/multiarray.py", line 12, in <module>
from . import overrides
File "/mnt/c/Users/seb/documents/Racecar/racecar-seb-h-s/labs/../library/numpy/core/overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "demo.py", line 16, in <module>
import racecar_core
File "/mnt/c/Users/seb/documents/Racecar/racecar-seb-h-s/labs/../library/racecar_core.py", line 13, in <module>
import camera
File "/mnt/c/Users/seb/documents/Racecar/racecar-seb-h-s/labs/../library/camera.py", line 11, in <module>
import numpy as np
File "/mnt/c/Users/seb/documents/Racecar/racecar-seb-h-s/labs/../library/numpy/__init__.py", line 150, in <module>
from . import core
File "/mnt/c/Users/seb/documents/Racecar/racecar-seb-h-s/labs/../library/numpy/core/__init__.py", line 48, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.8 from "/usr/bin/python3"
* The NumPy version is: "1.21.2"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
I have tried all the other potential duplicates that I could find and used the link but none worked. I have also tried uninstalling and reinstalling and updating numpy to no avail.
The output of running the command echo $PATH was the following:
/home/seb/.local/bin
:/usr/local/sbin
:/usr/local/bin
:/usr/sbin
:/usr/bin
:/sbin
:/bin
:/usr/games
:/usr/local/games
:/mnt/c/Program Files/WindowsApps/CanonicalGroupLimited.UbuntuonWindows_2004.2021.825.0_x64__79rhkp1fndgsc:/mnt/c/Program Files/Java/jdk-13.0.1/bin.
:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath
:/mnt/c/Program Files (x86)/Common Files/Intel/Shared Libraries/redist/intel64/compiler:/mnt/c/WINDOWS/system32
:/mnt/c/WINDOWS
:/mnt/c/WINDOWS/System32/Wbem
:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/
:/mnt/c/WINDOWS/System32/OpenSSH/
:/mnt/c/Users/seb/anaconda3
:/mnt/c/Users/seb/anaconda3/Library/mingw-w64/bin
:/mnt/c/Users/seb/anaconda3/Library/usr/bin
:/mnt/c/Users/seb/anaconda3/Library/bin
:/mnt/c/Users/seb/anaconda3/Scripts
:/mnt/c/Users/seb/AppData/Local/Microsoft/WindowsApps
:/snap/bin
The output of running the command python3 -m site was the following:
sys.path = [
'/mnt/c/Users/seb/documents/Racecar/racecar-seb-h-s/labs',
'/usr/lib/python38.zip',
'/usr/lib/python3.8',
'/usr/lib/python3.8/lib-dynload',
'/home/seb/.local/lib/python3.8/site-packages',
'/usr/local/lib/python3.8/dist-packages',
'/usr/lib/python3/dist-packages',
]
USER_BASE: '/home/seb/.local' (exists)
USER_SITE: '/home/seb/.local/lib/python3.8/site-packages' (exists)
ENABLE_USER_SITE: True
This has happened to me as well because I am taking the same course. I solved it by uninstalling all the libraries and installing them again. Here is the link to the setup instructions: https://mitll-racecar-mn.readthedocs.io/en/latest/gettingStarted/computerSetup/python.html. These are the commands you have to run to install the libraries:
sudo apt update
sudo apt install python3.8
sudo apt install python3-pip
pip3 install --upgrade pip
pip3 install numpy
pip3 install matplotlib
pip3 install mypy
pip3 install nptyping
pip3 install opencv-contrib-python
pip3 install jupyter
pip3 install ipywidgets
jupyter nbextension enable --py widgetsnbextension

Cannot import tensorflow_probability

When I try to import tensorflow_probability, I get this error:
Traceback (most recent call last):
File "PATH", line 1, in <module>
import tensorflow_probability
File "PATH", line 75, in <module>
from tensorflow_probability.python import * # pylint: disable=wildcard-import
File "PATH", line 24, in <module>
from tensorflow_probability.python import edward2
File "PATH", line 32, in <module>
from tensorflow_probability.python.experimental.edward2.generated_random_variables import *
File "PATH", line 34, in <module>
from tensorflow_probability.python.experimental import auto_batching
File "PATH", line 24, in <module>
from tensorflow_probability.python.experimental.auto_batching import frontend
File "PATH", line 46, in <module>
from tensorflow.python.autograph.pyct import compiler
ImportError: cannot import name 'compiler' from 'tensorflow.python.autograph.pyct' (PATH)
I don't know why Python can't import this module because when I type pip list in cmd, it tells me that I have tensorflow-probability 0.8.0rc0 installed. Any help would be greatly appreciated.
Try to install the tf_agents package.
I had a few import errors appear when trying to import tensorflow_probability. These include:
module 'tensorflow.python.ops.linalg.linear_operator' has no attribute 'make_composite_tensor'
cannot import name 'all_util' from 'tensorflow_probability.python.internal'.
These issues were resolved when I installed and imported tf_agents.
pip install --upgrade tf_agents
If you're using jupyter, add the following to a cell and then run it:
import sys
!{sys.executable} -m pip install --upgrade tf_agents
I have tried to import in Google colab and Ubuntu 18 version. In colab it worked directly, in ubuntu I faced issues.
Upgrading to the latest pip and TensorFlow version resolved my issue.
Colab:
import tensorflow_probability as tfp
Ubuntu 18:
Upgrade pip
pip install --upgrade pip
install the latest version of TensorFlow
pip install tensorflow
install tensorflow_probability
pip install --upgrade tensorflow-probability
tensorflow-probability version 0.11.1
Had the exact same problem. Removing older tensorflow version and installing everything nightly solved my problem.
pip uninstall tensorflow
pip uninstall tensorflow-probability
pip install tf-nightly
pip install tfp-nightly

I have installed opencv-python using command pip, but am facing importError while executing import cv2 on aws

I have installed Opencv on AWS ec2-instance using pip3 install opencv-python but while importing cv2 it throws an error
import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib64/python3.7/site-packages/cv2/__init__.py", line 5, in
<module>
from .cv2 import *
ImportError: libSM.so.6: cannot open shared object file: No such file or
directory`
I have also tried to download some modules using below command to solve the issue but it also not working
sudo yum install -y libsm6 libxext6 libxrender-dev`
sudo yum install libXtst

ImportError when importing Basemap

I have problems importing basemap, even though I just installed it via pip install basemap. I've tried both with python2.7 and python3:
python3
>>> from mpl_toolkits.basemap import Basemap
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'mpl_toolkits'
python2.7
>>> from mpl_toolkits.basemap import Basemap
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.py", line 37, in <module>
import _geoslib
ImportError: libgeos_c.so.1: cannot open shared object file: No such file or directory
I'm on a ubuntu OS.
What worked for me on ubuntu:
sudo apt-get install libgeos-3.4.2
sudo apt-get install libgeos-dev
sudo pip install https://github.com/matplotlib/basemap/archive/master.zip
It worked for me in python3 with v3.1.2 of matplotlib:
sudo apt-get update -y
sudo apt-get install -y python3-mpltoolkits.basemap
Check matplotlib module version running in python:
>>>import matplotlib
>>>matplotlib.__version__
'3.1.2'
Upgrade module:
sudo pip3 install matplotlib --upgrade

Categories