I searched how to predict my own digit image using Google TensorFlow.
I used 64bit Red Hat Linux.
I installed Python3.4.3, other related development environments and TensorFlow version 0.6.0.
Then, I tried to write code for digit prediction.
Firstly, I need to read images in my python program.
So, I searched how to read images in python then I found OpenCV (http://opencv.org/)
I installed OpenCV(version:3.1.0) using cmake.
After installing OpenCV, I tried to import cv2(OpenCV function) in order to read image.
But I cannot import cv2 and ImportError occured as the following.
ImportError: No module named 'cv2'
I tried to solve this problem by changing default PYTHONPATH.
For example:
export PYTHONPATH=/usr/local/python/lib/python3.4/site-packages:$PYTHONPATH
I tried to add some code in my python program.
import sys
sys.path.append('/usr/local/python/lib/python3.4')
But the above two steps cannot solve the problem ImportError: No module named 'cv2'.
So, I search how to solve this problem and I tried to solve with many other ways. But no success.
How can I import cv2 in my python program?
OpenCV Installation steps are as follow:
>>> yum install cmake
** Download OpenCV latest version from it's official site **
>>> cd /directory of OpenCV/
>>> mkdir release
>>> cd release
>>> cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..
>>> make && make install
>>> echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf
>>> ldconfig
>>> echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig" >> /etc/bash.bashrc
>>> echo "export PKG_CONFIG_PATH" >> /etc/bash.bashrc
This doesn't directly answer your question—perhaps an OpenCV expert can help with that—but TensorFlow includes reasonably comprehensive support for manipulating images. If your images are in JPEG format you can use tf.image.decode_jpeg() to convert them to tensors; likewise tf.image.decode_png() supports PNG images.
Related
Using python3, I am unable to import the imageio module into my python program, which I need, as I try to animate a list of PNG images I have. Thus far I have tried:
"pip3 install imageio" both running as myself and as root. The install succeeded, but it still errors out as in the subject line. I suppose I could try "apt-get install (package name)", but need to determine the package_name.
Any ideas more than welcome - TIA.
Try importing the last version.
import imageio.v3 as iio
im = iio.imread('imageio:chelsea.png')
print(im.shape) # (300, 451, 3)
ref https://imageio.readthedocs.io/en/stable/examples.html
I am new to python and I am trying to create an .exe from py script with pyinstaller but I get this error when trying to run the .exe: Could not find the matplotlib data files.
When i run the script in python idle i dont get this error.
I've tried:
import matplotlib
setup(
data_files=matplotlib.get_py2exe_datafiles(),
)
But i get an error saying that setup is not defined.
I've fixed the problem by downgrading matplotlib to version 3.0.3
Using this command:
python -m pip install matplotlib==3.0.3
The only thing that worked "sustainably" for me is to also downgrade to and earlier version of Matplotlib version 3.1.3. I can now use pyinstaller. I can also run all program without that horrible warnings and stuff that it gives.
I used pip install matplotlib==3.1.3. make sure you uninstall all previous matplotlib.
hi i faced the same problem too when generating script using pyinstaller (im using python 3.7). The problem is solved when i installed:
pip install matplotlib==3.0.3
Find and edit the hook-matplotlib.py inside of lib/site-packages/pyinstaller/hooks
edit the data section from:
datas = [
(mpl_data_dir, "mpl-data"),
]
to
datas = [
(mpl_data_dir, "matplotlib/mpl-data"),
]
Pyinstaller can't find the location of your mpl-data folder.
Please search for mpl-data directroy and export that in your program
as a workaround
import os
os.environ['MATPLOTLIBDATA'] = 'location of mpl-data folder'
I'm relatively new to python, so please excuse my ignorance on what could be a very easy fix. I am running python 3.6 through the Rodeo IDE, and it has been great, as it is similar to R-Studio (which I am very familiar with). As an aspiring data scientist, I am trying to learn how to fit regression and time series models to data, and all of the tutorials that I have found all say that I need various packages, all of which should be included in the Anaconda library. After downloading and re-downloading Python, Rodeo, and Anaconda, and trying various online fixes, I have been unable to successfully load the scikit-learn and the statsmodels modules.
#here is everything I have tried.
#using pip
! pip install 'statsmodels'
! pip install 'scikit-learn'
! pip install 'sklearn'
I don't get any errors here, and to be honest I'm kind of confused as to what this actually does, but I have seen many people online always suggest that this is a big problem when trying to import modules.
#using import
import sklearn
import statsmodels
from sklearn import datasets
import statsmodels.api as sm
all of the above give me the same error:
import statsmodels.api as sm
ImportError: No module named 'statsmodels'
ImportError: Traceback (most recent call last)
ipython-input-184-6030a6549dc0 in module()
----> 1 import statsmodels.api as sm
ImportError: No module named 'statsmodels'
I have tried to set my working directory to the Anaconda 3 file that has all of the packages and rerunning the above code with no success.
I'm thinking that the most likely problem has to do with my inexperience, and it is probably a simple fix. Is it possible that the IDE is bad or anaconda just doesn't like me?
So keeping all of the above in mind, the question is, how can I import these modules successfully so that I can access their functionality?
Option 1:
After installing packages with pip, try closing and reopening your IDE/Jupyter Notebook and try again.
This is a known bug that Jake VanderPlas outlined here
Option 2:
Don't put quotations around your pip messages.
!pip install -U statsmodels
!pip install scikit-learn
Option 3:
Also are you using Anaconda? If you are, you should already have scikit-learn. If you are trying inside Rodeo, I think you need to set your path inside Rodeo. Open Rodeo and set the Python Path to your fresh anaconda. See here
Previously ROS was installed in my system which requires opencv for its implementation and now I am using anaconda in which I need to use the opencv library once again. While writing python code import cv2 throws an error module not found.
Is there any way to use that opencv library which ROS installed in anaconda
Although I installed opencv once again using conda.
$conda install -c conda-forge opencv
however opencv-3.3 was installed using above command. Now my python code is showing different import error as shown below:
ImportError Traceback (most recent call last)
<ipython-input-9-6b49ad4d4ca5> in <module>()
1 from random import shuffle
2 import glob
----> 3 import cv2
4 shuffle_data = True # shuffle the addresses before saving
5 hdf5_path = 'dataset.hdf5' # address to where you want to save the hdf5 file
ImportError: /home/kamal/ros_catkin_ws/install_isolated/lib/python2.7/dist-packages/cv2.so: undefined symbol: PyCObject_Type
How can I particularly specify which opencv library to use. What env variables I need to change.
Any help will be appreciated.
uncommenting the line source /home/user/ros_catkin_ws/install_isolated/share/setup.bash in the .bashrc file dosen't help. You also need to remove the extrasys.path added by the ROS environment.
In a python console
import sys
print (sys.path)
you will see multiple paths related to ROS
then remove the unwanted part of the path by
sys.path.remove('unwanted_path')
This will solve the problem but now ROS will not work. To make it work you need to append the removed path again.
If someone has a better approach please answer.
I already copy the cv2 and complete the procedure installing opencv and python and I also think the default python installation is usr/lib64/python2.7 and there is also usr/lib/python2.7 and I also move the cv2 using copy -r usr/lib/python2.7/site-packages/cv2.so to usr/lib64/python2.7/site-packages/ it successfully move but when I run the $python
import cv2 [this is what happen1
am still wondering if there is a default directory for centos 64 bit or i did wrong on my steps? I followed this tutorial http://techieroop.com/install-opencv-in-centos/ and i find it simple and fast yet im still stuck installing opencv
Do the following
yum install numpy opencv*
yum check-update
then
import cv2
print cv2.__version__