PyTorch transfer learning example developed as part of Udacity's AI Programming with Python Nanodegree program.
Environment Python 3.6.5:
Numpy PyTorch TorchVision
python train.py [-h] [--save_dir SAVE_DIR] [--arch ARCH]
[--learning_rate LEARNING_RATE]
[--hidden_features HIDDEN_FEATURES] [--gpu]
data_dirdata_dir Directory used to locate source images
-h, --help show this help message and exit --save_dir SAVE_DIR Directory used to save checkpoints --arch {vgg19, alexnet} Model architecture to use for training --learning_rate LEARNING_RATE Learning rate hyperparameter --hidden_features HIDDEN_Features Number of hidden units hyperparameter
--gpu Use GPU for training
The following will train a vgg model on the GPU:
python train.py flowers --arch VGG --gpu python predict.py [-h] [--top_k TOP_K] [--gpu] image_path filepathimage_path Input image filepath Model checkpoint file to use for prediction
-h, --help show this help message and exit --top_k TOP_K Return top k most likely classes --gpu Use GPU for prediction
The following will return the most likely class using a VGG checkpoint executing on the GPU:
python predict.py flowers/test/14/image_0814.jpg VGG_checkpoint.pth --gpu