Applying a Model to new Data

You can use a pre-trained model on data to extract features, or to obtain classification results on the data.

Extract Features from a Model

The following command can be used to extract features from a saved checkpoint/model.

python template/RunMe.py --runner-class apply_model --dataset-folder <path_to_dataset> --load-model <path_to_checkpoint> --output-channels <number_of_outputs_in_final_layer>

The dataset should be in the format:

root_folder/<img>.jpg

For example:

root_folder/img1.png
root_folder/img_abc.png
root_folder/cat.jpg

An output file (results.pkl) is generated in the output folder. The output file contains a list of lists with the following format:

[0] - features
[1] - None
[2] - None
[3] - filenames

features refer to the activation values of the final layer of the model. In the case of a model trained to produce N-dim embeddings applied on a folder with 1001 images, it will be an array of size 1001x256.

filenames contains corresponding filenames for the embeddings.

Note: The entries [1] and [2] are empty in the case of feature extraction by design. These are used when a model is applied on a folder to generate classification values.

Use a Model for Classification

The following command should be used when you want to use a saved checkpoint to classify a folder. For e.g., you trained your model on CIFAR and want to test it out on your own dataset of CIFAR classes.

python template/RunMe.py --runner-class apply_model --dataset-folder <path_to_dataset> --load-model <path_to_checkpoint> --classify

The dataset should be in the format:

root_folder/<folder_name>/<class_name>/<image>.jpg

For example:

root_folder/evaluate_me/cat/001.jpg
root_folder/evaluate_me/cat/cat101.jpg
root_folder/evaluate_me/cat/a.jpg

root_folder/evaluate_me/dog/dog_001.jpg

An output file (results.pkl) is generated in the output folder. The output file contains a list of lists with the following format:

[0] - features
[1] - preds
[2] - labels
[3] - filenames

`features contain the raw activation values of the final layer of the model.

preds contain single integers that indicate the class predicted by the Model

labels contain single integers that indicate the ground truth class

filenames contain the filenames for the corresponding images.

Note: To obtain optimal results, always place the analytics.csv that was generated during training time in the folder on which to apply the model.