Project code for Udacity's Data Scientist Nanodegree program. In this project, students first develop code for an image classifier built with PyTorch, then convert it into a command line application.
The Code is written in Python 3.6.5 . If you don't have Python installed you can find it here. If you are using a lower version of Python you can upgrade using the pip package, ensuring you have the latest version of pip.
To install pip run in the command Line
python -m ensurepip -- default-pip
to upgrade it
python -m pip install -- upgrade pip setuptools wheel
to upgrade Python
pip install python -- upgrade
Additional Packages that are required are: Numpy, Pandas, MatplotLib, Pytorch, PIL and json.
You can donwload them using pip
pip install numpy pandas matplotlib pil
or conda
conda install numpy pandas matplotlib pil
In order to install PyTorch head over to the PyTorch site select your specs and follow the instructions given.
Image Classifier Project.ipynb
Jupyter NotebookImage Classifier Project.html
HTML export of the Jupyter Notebook above.setup.py
Main Scripttrain.py
Command line tool to train a new network on a data set.predict.py
Command line tool to to predict flower name from an image.Image categories are found in cat_to_name.json and flower images you can get in this repository itself or can be downloaded in the gziped tar file flower_data.tar.gz from Udacity.
Get flower images:
mkdir -p flowers && cd flowers
curl https://s3.amazonaws.com/content.udacity-data.com/nd089/flower_data.tar.gz | tar xz
You should now have test, train and valid directories containing classification directories and flower images under the flowers directory.
In order to better view and work on the Jupyter Notebook I encourage you to use nbviewer . You can simply copy and paste the link to this website and you will be able to see it without any problem. Alternatively you can clone the repository using
git clone https://github.com/rowhitswami/Image-Classification-with-PyTorch/
cd Image-Classification-with-PyTorch/
Open terminal in current folder and type:
jupyter notebook
locate the notebook and run it.
Train a new network on a data set with train.py
python train.py data_directory
python train.py data_dir --save_dir save_directory
pytnon train.py data_dir --arch "vgg16"
python train.py data_dir --learning_rate 0.001 --hidden_units 512 256 --epochs 20
python train.py data_dir --gpu
Predict flower name from an image with predict.py
along with the probability of that name. That is you'll pass in a single image /path/to/image
with /path/to/checkpoint
and return the flower name and class probability
python predict.py /path/to/image checkpoint
python predict.py input checkpoint ---top_k 3
python predict.py input checkpoint --category_names cat_to_name.json
python predict.py input checkpoint --gpu
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。