When downloading MNIST, I can't get the "processed" folder - pytorch

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.

Related

working with Keras on a Jupyter lab using Tensorflow

I'm trying to use keras on a jupyter lab using tensorflow (python 3.6) through miniconda.
Jupyter lab keeps give me a restarting error(Kernel Restarting The kernel for Desktop/Transfer/Untitled.ipynb appears to have died. It will restart automatically.)
Because the kernel restarting error is evident whenever I try to import keras. The code I used is (from keras.preprocessing.image import ImageDataGenerator, load_img, img_to_array, array_to_img).
Code
Therefore, I assume that there is a problem between keras and kernel even though I already installed ipykernel in my tensorflow directory ((tensorflow) C:\Users\user).
Pip_list
Still couldn't figure out this kernel and keras problem :(.

Conflict between tensorflow/PIL/pillow and scikit-image?

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

Unable to import sklearn and statsmodels from Anaconda from windows 10 pro

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

How do I use a previous version of Keras (0.3.1) on Colaboratory?

I tried pip installing 0.3.1, but when I print the version it outputs 2.1.4.
!pip install keras==0.3.1
import keras
print keras._version__
I am trying to train deepmask (https://github.com/abbypa/NNProject_DeepMask/) for which I specifically need 0.3.1.
Note that if you've already loaded keras, then the second import statement has no effect.
So first !pip install keras==0.3.1, then restart your kernel (ctrl-m . or Runtime -> Restart runtime) and then things should work as expected.

Not able to import PolynomialFeatures, make_pipeline in Scikit-learn

I'm not able to import the following modules in an ipython notebook:
from sklearn.preprocessing import PolynomialFeatures
from sklearn.pipeline import make_pipeline
The following error pops up
ImportError: cannot import name PolynomialFeatures
The same error also appears for make_pipeline.
I'm a newbie in scikit-learn, please help out.
I'm using the miniconda installation of python and the version number for scikit-learn is 0.14.1.
Polynomial Features is included for next version of scikit-learn and is not available in 0.14.1. Please update to 0.15-git if you want to use it. The same holds for make pipeline.
To get the bleeding edge version:
git clone git://github.com/scikit-learn/scikit-learn.git
python setup.py build_ext --inplace
Please read: http://scikit-learn.org/stable/developers/index.html#git-repo
You have to check your current version of scikit:
import sklearn
print sklearn.__version__
if it is less than 0.15.0, then you have to upgrade it. In addition to an excellent answer of Abhishek, you can follow official installation process (which is described for various OS).
If you are using pyCharm, it can be done even simpler: File -> Settings -> Project Interpreter and then select your package and click upgrade
(I selected another one, be cause my scikitlearn is the newest)

Resources