Documentation for evaluate
Path: image_classification/evaluate.py
Functions
get_model
Get the specified model with the correct number of output classes
load_model
Load a trained model with weights.
Args: model_name (str): Name of the model architecture weights_path (str): Path to the weights file num_classes (int): Number of classes device (torch.device): Device to load the model on
Returns: tuple: (model, class_to_idx) - Loaded model and class mapping
get_all_images
Get all images from the input folder structure. Each subfolder name represents a class.
Args: input_folder (str): Path to the input folder containing class subfolders class_to_idx (dict, optional): Pre-defined class to index mapping from training
Returns: tuple: (image_files, class_to_idx) - List of image tuples and class mapping
load_class_mapping_from_file
Load class mapping from a JSON file.
Args: mapping_file (str): Path to JSON file containing class mapping
Returns: dict: Class name to index mapping
save_class_mapping_to_file
Save class mapping to a JSON file.
Args: class_to_idx (dict): Class name to index mapping output_file (str): Path to output JSON file
main
Main evaluation function.
Args: input_folder (str): Path to the input folder containing images to evaluate output_csv (str): Path to the output CSV file for results model (str): Model name/type to use for evaluation weights_path (str): Path to the model weights file num_classes (int): Number of classes for classification device (str): Device to use ('auto', 'cpu', 'cuda') class_mapping_file (str): Path to JSON file containing class mapping