Flower Image Classifier with PyTorch
Application of neural networks for image classification—using torchvision
Example of inference:
This project is part of a Udacity program: Data Science degree, Project 2.
The objective of this project is to build an application that can be trained on any set of labeled images, using tools in PyTorch.
The network instance in the Jupyter notebook is trained on flower images—102 Category Flower Dataset—and provides predictions via a command line application. Below is an example of the type of images included in the dataset:
The project in the Jupyter notebook is broken down into three main steps:
- Load and pre-process the image datasets
- Train the image classifier on the training dataset
- Use the trained classifier to predict flower-image categories
Main files in the repository:
-
flower-classifier-PyTorch.ipynb
: Jupyter notebook including main Python code used in developing the tool. -
model_functions.py
: Python module with functions needed for core tasks of the model: network architecture, building a classifier, training, validation, and prediction. -
train.py
: Python module to train a new network on a dataset and then save the model as a checkpoint. -
utility_fs_train.py
: Utility functions fortrain.py
. -
predict.py
: Python module to predict flower category from image, along with the probability of that category. -
utility_fs_predict.py
: Utility functions forpredict.py
.
The objective of this project is to build an application that can be trained on any set of labeled images, using the tool in PyTorch.
The Jupyter Project highly recommends new users to install Anaconda; since it conveniently installs Python, the Jupyter Notebook, and other commonly used packages for scientific computing and data science.
Use the following installation steps:
-
Download Anaconda.
-
Install the version of Anaconda which you downloaded, following the instructions on the download page.
-
To run the notebook:
jupyter notebook flower-classifier-PyTorch.ipynb
python train.py <data_directory> \
--arch <network architecture> \
--save_dir <checkpoint directory> \
--learning_rate <learning rate> \
--hidden_units <units in hidden layer pre-classifier> \
--epochs <number of passes of the training data> \
--gpu
python train.py flowers/
python predict.py <path to image> <checkpoint> \
--top_k <number of most likely classes> \
--category_names <mapping of categories to real names> \
--gpu
python predict.py input_image checkpoint --top_k 3 --gpu \
--category_names cat_to_name.json
3.7.1 (default, Oct 23 2018, 14:07:42)
The Jupyter Notebook and the Python modules require the following Python libraries:
- argparse
- collections
- json
- matplotlib
- numpy
- os
- pandas
- PIL
- random
- sklearn
- sys
- time
- torch
- torchvision
- Udacity: Data Scientist Nanodegree program.
- Jupyter Documentation: Installing Jupyter Notebook
Juan Carlos Lopez
- Fork it (https://github.com/jclh/image-classifier-PyTorch/fork)
- Create your feature branch (git checkout -b feature/fooBar)
- Commit your changes (git commit -am 'Add some fooBar')
- Push to the branch (git push origin feature/fooBar)
- Create a new Pull Request