I am tying to rebuild my computer to run Spyder in a tensorflow environment for some image processing. In the past this worked and I had scikit-image working fully in that environment, and accessible from Spyder. Something has changed. I have:
1) re-installed Anaconda
2) re-installed tensorflow in a conda environment
3) installed libraries as needed, including Spyder.
Then I start Spyder from the Conda navigator, in the tensorflow environment. This seems to work, I can import tensorflow, keras, pandas, sklearn, etc. But skimage only works partially. for example:
import skimage
works fine. But,
import skimage.io as io
does not. The error comes out as 'from PIL import Image' Is this something about PIL/pillow not co-existing in the same environment? Can this be fixed easily or should I just use opencv for image io? I have tried other modules in skimage and they all import. So using another package to open an image would not be the end of the world, but it would be nice to get the entirety of skimage working.
Thanks
Related
I am following a tutorial in here https://www.youtube.com/watch?v=IQpP_cH8rrA
I followed all the initial steps (except I am in VS not in Colab) but I stop pretty soon because when running:
torchvision.datasets.MNIST('./', download=True)
I get only the raw folder, not the processed one (which should contain training.pt and test.pt).
Can anybody help?
I am running on python 3.8.10, torch version 1.10.1, torchvision 0.11.2
PS: I found the same issue here https://github.com/pytorch/vision/issues/4685
should I really downgrade torchvision to 0.9.1 to have both folders?
if yes, how can I just downgrade torchvision from cmd, without uninstall torch and install everything back?
I found this work around, downloading the data from tensorflow and then just switching the data types so you can follow along the tutorial again. hope this helps
import tensorflow as tf
import torch
import numpy as np
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
print(x_train.shape)
images = torch.from_numpy(x_train)
ground_truth = torch.from_numpy(y_train)
print(images.shape)
print(ground_truth.shape)
`
This works in my notebook, hopefully it does for you too
I am not sure if this answer will help anyone but this was my solution to it (after lots of trying and searching in the internet, I am not too experienced):
(I used anaconda prompt)
I created a virtual environment called "test" for python 3.6:
conda create -n test python=3.6
activate test
I installed the recommended torchvision version on it:
pip install torchvision==0.9.1
I ran my program in the virtual environment:
python yourprogram.py
I am sure this is not the best solution to exist but it worked for me and was very easy as it is just a few lines in anaconda prompt.
I'm running Ubuntu 18.04LTS:
Firstly, I couldn't install opencv from anaconda on my existing environment (base) as it kept searching for conflicts forever and then getting stuck with an empty window saying "these packages will be modified" while displaying absolutely nothing and with the only choice of pressing the "cancel" button.
I created a new virtual environment named env_opencv and was able to install opencv:
enter image description here
Then, I run a jupyter notebook that imports opencv:
import cv2
import matplotlib.pyplot as plt
import matplotlib.patches as patches
...
And here's what I get:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-8-31cd2c78c525> in <module>
----> 1 import cv2
2 import matplotlib.pyplot as plt
3 import matplotlib.patches as patches
4
5 from align import AlignDlib
ModuleNotFoundError: No module named 'cv2'
No matter what I tried, including reinstalling opencv directly from the conda prompt, I can't get past this error.
Incidentally, I was able to make it work on Windows 10 going through the Anaconda prompt and using conda. However, my Windows machine doesn't have an nVidia GPU and I can't use it for CNN training, so I really need to make it work on Ubuntu.
Any suggestions would be great. Thank you.
I found a workaround to this issue:
I activate the env_opencv environment from the command line, then I launch jupyter notebook and it works.
Maybe, there is a bug with anaconda-navigator that doesn't seem to switch environments from the GUI?
When I try:
>>> from skimage import io
I get at the end the following:
from ..color import rgb2gray
ImportError: cannot import name 'rgb2gray' from 'skimage.color' (C:\Users\user\A
ppData\Local\Programs\Python\Python37-32\lib\site-packages\skimage\color\__init_
_.py)
Although I have installed the packages: matplotlib, scipy, pillow, numpy and six
How can I fix it? Any help would be appreciated
In case you run into this error from inside a Jupyter Notebook, try restarting the kernel as suggested in this GitHub issue.
That solved the problem for me.
It looks like you haven't installed scikit-image package.
Try this on terminal:
pip install -U scikit-image
And then try importing like this:
from skimage import io
from skimage.color import rgb2gray
If you still got the error or you have installed the package previously,
try reinstalling the package first.
If it still don't resolve your issue, then try updating the following packages:
matplotlib, scipy, pil, numpy and six
However, try not to import all of the subpackages to improve loading time. You can however try something like:
from skimage import color
...
gray_img = color.rgb2gray(img)
If you still got errors, make sure that you are using the correct python kernel and dependent modules are updated and installed.
If that did not help either, then try Anaconda, it come with many pre-installed packages.
Leave a comment if you still have a problem :)
three ways to convert RGB2Gray:
opencv:
import cv2
img=cv2.imread("file.jpg",0) [enter link description here][1]
or you can do this:
img=cv2.imread("file.jpg")
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cv2.COLOR_BGR2GRAY beacause it reads BGR mode.
another methods you can look this link:
enter link description here
It happened to me once when I import skimage using env conda on Jupyter. I installed by pip or conda in env, that error happened. However, after restart the Jupyter, it worked.
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
I am trying to work with Keras on some small datasets locally, using my cpu.
I started a jupyter notebook, and selected what I think might be the right kernel, which would be the conda env:tensorflow:
So I try to import from the sandbox:
from theano.sandbox import cuda .
and I get
ImportError: No module named theano.sandbox
I don't get it. Theano is installed. Tensorflow is installed. Anaconda is installed. How can I figure out what is going on?