brails.processors.occupancy_classifier.occupancy_classifier module
- class brails.processors.occupancy_classifier.occupancy_classifier.OccupancyClassifier(input_data: dict | None = None)
Bases:
ImageClassifier
The OccupancyClassifier classifier attempts to predict occupancy types of buildings as 1 of 2 types: Residential or Other. The classification is done by the ImageClassifier class. This class is a wrapper that just sets up the inputs for that class.
- Variables
model_path: str Path to the model file
- Methods:
- predict(ImageSet): To return the predictions for the set of images
provided
- predict(images: ImageSet) dict
The method that predicts building occupancy type.
- Args
- images: ImageSet containing the set of images for which a
prediction is required
- Returns
- dict: Dictionary with keys set to image names in ImageSet.images
and values set to the predicted occupancy types
- retrain(dataDir, batchSize=8, nepochs=100, plotLoss=True)
Retrain existing model using training dataset and hyperparameters.
Parameters__ - model_path (str): Path to the pre-trained model to be fine-tuned.
Default is ‘tmp/models/trained_model.pth’.
- train_data_dir (str): Directory containing the training and
validation datasets. Default is ‘tmp/hymenoptera_data’.
- model_inp_size (int): Input size for the model, used for resizing
images in the dataset. Default is 384.
batch_size (int): Batch size for data loading. Default is 32.
- nepochs (Union[int, List[int]]): Number of epochs for training.
Should be an integer for retraining. Default is 100.
- es_tolerance (int): Early stopping tolerance; the number of epochs
without improvement before stopping. Default is 10.
- plot_accuracy (bool): Whether to plot the validation accuracy over
epochs. Default is True.
Returns__ - None
Raises__ - ValueError: If nepochs is not provided as an integer during
retraining.
Procedure__ 1. Loads the model from the specified path. 2. Applies data augmentation and normalization to the training dataset
and normalization to the validation dataset.
- If the default training data directory is used, downloads a sample
dataset.
- Prepares PyTorch DataLoader objects for the training and
validation datasets.
- Sends the model to the GPU and fine-tunes it using Stochastic
Gradient Descent (SGD) optimization.
After training, the model is saved at the specified path.
- If plot_accuracy is True, plots the validation accuracy versus
training epochs.
Example__ >>> classifier = ImageClassifier() >>> classifier.retrain(model_path=’model.pth’,
train_data_dir=’my_data’, nepochs=50)