brails.processors.chimney_detector.chimney_detector module
Class object to use and retrain the chimney detector model.
- class brails.processors.chimney_detector.chimney_detector.ChimneyDetector(input_data: dict | None = None)
Bases:
object
A class to manage and configure the system for detecting chimneys.
This class provides an organized structure to store system parameters and configurations required for training and inference tasks in a chimney detection system. It initializes a nested dictionary to hold various configurations and parameters for different stages of processing.
- Attributes:
- system_dict (dict):
A dictionary to store system configurations and parameters, initialized with nested dictionaries for training and inference settings.
- Methods:
- train(self, comp_coeff: int = 3, top_only: bool = False,
optim: str = “adamw”, lr: float = 1e-4, nepochs: int = 25, ngpu: int = 1) -> None:
Sets up parameters for training the chimney detection model.
- predict(images: ImageSet, model_path: str = 'tmp/models/efficientdet-d4_chimneyDetector.pth') dict
Predict the existence of chimneys in buildings from the given images.
- Args:
- images (ImageSet):
ImageSet object containing the collection of images to be analyzed.
- modelPath (str):
The file path to the pre-trained model. If the default path is used, the model will be downloaded (default is ‘tmp/models/efficientdet-d4_chimneyDetector.pth’).
- Returns_:
- predictions (dict):
Existence of chimneys with the keys being the same keys used in ImageSet.images.
This method processes the images provided, loads the specified model, and performs inference to determine the existence of chimneys in each building. It handles the setup of the inference environment, manages model loading, and provides a report on the execution time.
It also includes functions for polygon creation, intersection checks, and managing thresholds during inference to ensure accurate predictions.
The results of the predictions are also stored in the instance’s system dictionary under the key ‘predictions’.
- retrain(optim: str = 'adamw', learning_rate: float = 0.0001, nepochs: int = 25, ngpu: int = 1) None
Retrain the chimney detection model with specified parameters.
- Args:
- optim (str):
Optimizer to use for training (default is “adamw”).
- lr (float):
The learning rate for the optimizer (default is 1e-4).
- nepochs (int):
Number of epochs to train the model (default is 25).
- ngpu (int):
The number of GPUs to use for training (default is 1).
This method configures the training parameters, sets the training and validation datasets, initializes the model architecture, and starts the re-training process for the default chimney detector in BRAILS++.
- train(comp_coeff: int = 3, top_only: bool = False, optim: str = 'adamw', learning_rate: float = 0.0001, nepochs: int = 25, ngpu: int = 1) None
Train a chimney detection model.
- Args:
- comp_coeff (int):
Coefficient for comparison, default is 3.
- top_only (bool):
If True, only the top layers are trained, default is False.
- optim (str):
Optimizer type, default is “adamw”.
- lr (float):
Learning rate, default is 1e-4.
- nepochs (int):
Number of epochs for training, default is 25.
- ngpu (int):
Number of GPUs to use, default is 1.
- Updates:
- self.system_dict (dict[str, dict[str, Any]]):
Updates the model configuration parameters for training in the system dictionary.