Project code for Udacity's AI Programming with Python 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 repository contains the following files:
-
Image Classifier Project.ipynb
: A Jupyter notebook where the image classifier is built using transfer learning with ResNet-18. This notebook includes visualizations of the training process, such as loss and accuracy metrics over time, to provide insights into the model's performance. -
train.py
: A command-line script to train a new network on a dataset and save the model as a checkpoint. -
predict.py
: A command-line script to use a trained network for predicting the class of an input image.
To train a new network on a dataset, use the train.py
command-line script. This script will print out the training loss, validation loss, and validation accuracy as the network trains.
python train.py data_dir --save_dir save_directory
- Set directory to save checkpoints:
python train.py data_dir --save_dir save_directory
- Choose architecture:
python train.py data_dir --arch "resnet18"
- Set hyperparameters:
python train.py data_dir --learning_rate 0.01 --hidden_units 250 --epochs 3
- Use GPU for training:
python train.py data_dir --gpu
python predict.py /path/to/image checkpoint
- Return top K most likely classes:
python predict.py input checkpoint --top_k 3
- Use a mapping of categories to real names:
python predict.py input checkpoint --category_names cat_to_name.json
- Use GPU for inference:
python predict.py input checkpoint --gpu
-
Ensure that the necessary Python libraries are installed.
-
Prepare your dataset and place it in the specified directory.
-
Use
train.py
to train the model and save the checkpoint. -
Use
predict.py
to make predictions on new images.
This project is licensed under the MIT License - see the LICENSE file for details.