brails.processors.occupancy_classifier.occupancy_classifier module
Class object to use and retrain the occupancy classifier model.
- class brails.processors.occupancy_classifier.occupancy_classifier.OccupancyClassifier(input_data: dict | None = None)
Bases:
ImageClassifier
Class for predicting building occupancy types from street-level imagery.
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
Predict building occupancy type.
- Args:
- images (ImageSet):
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(data_dir: str, batch_size: int = 8, nepochs: int = 100, plot_loss: bool = True)
Retrain the current occupancy model using new data.
- Args:
- data_dir (str):
Path to the directory containing the new training data. The directory should be structured with subdirectories for each class, each containing the respective images.
- batch_size (int, optional, default=8):
The number of samples per batch used during training.
- nepochs (int, optional, default=100):
The number of epochs for which the model will be retrained.
- plot_loss (bool, optional, default=True):
If True, displays a plot of the training loss over epochs.
Notes:
- This method uses an instance of ImageClassifier to perform the
retraining.
- The current model is loaded from self.modelPath and updated with
the new data.
- Ensure data_dir is properly prepared and contains sufficient data
for effective retraining.
Example:
retrainer = OccupancyClassifier({‘modelPath’:’path/to/current/model’}) retrainer.retrain(data_dir=”path/to/new/data”,
batch_size=16, nepochs=50, plot_loss=True)