Using PyTorch and TorchVision to develop and image classification pipeline via the design of a CNN architecture
(extreme gratitude and appreciation to Dr. Catia Silva for being an amazing professor)
- Create a new conda environment
ml_experts
with the following dependencies.
conda create -n ml_experts python=3.7 torchvision cudatoolkit=11.3 pytorch=1.12.1=gpu_cuda* -c pytorch
conda install -c conda-forge matplotlib
conda install -c conda-forge imutils
conda install -c conda-forge tqdm
conda install -c anaconda scikit-learn
- Clone the repo.
git clone https://github.com/UF-FundMachineLearning-Sp23/final-project-ml-experts.git
- Setup and activate environment
conda activate ml_experts
- Put
data_train.npy
andlabels_train.npy
in the base directory. The shapes should be (270000, n_samples) and (n_samples, ) respetively. python prepare_train_data.py
python train.py
How it works:
prepare_train_data.py
creates images fromdata_train.npy
and save them inlogo_photos
folder. Next it createsdataset/train/
anddataset/val/
folders and put the images according toVAL_SPLIT
ratio.train.py
imports pretrainedResNet-50
model and finetune it on provided train and validation data. The model is saved atoutput/finetune_model.pth
.
Note: If you want to change any parameters of training, please do it in utils/config.py
. Here are some variables that you can change.
TRAIN_DATA
: Name of your data file. (a .npy file)TRAIN_LABELS
: Name of your labels file. (a .npy file)VAL_SPLIT
: Train/Validation ratio. (default is 70/30)IMAGE_SIZE
: Input image size to model. (default is 224, must be multiple of 32)FINETUNE_BATCH_SIZE
: Training batch size. (default is 64)EPOCH
: Training epoch. (default is 100)LR
: Learning rate. (default is 0.001)FINETUNE_MODEL
: Directory and name for saving the model
- Put
data_test.npy
andlabels_test.npy
in the base directory. The shapes should be (270000, n_samples) and (n_samples, ) respetively. python test.py
How it works:
- The
test.py
creates images fromdata_test.npy
and saves them indataset/test/
folder. Next it generatespred_list
that contains predicted labels. It also prints a classification report. - If you trained and saved a model with different name then use:
python test.py --path <path to your model>