brails.processors.year_built_classifier.year_built_classifier module
Class object to predict era of construction of buildings.
- class brails.processors.year_built_classifier.year_built_classifier.YearBuiltClassifier(input_data=None)
Bases:
objectA classifier for predicting the construction era of buildings.
This model classifies images of buildings into one of several predefined construction eras based on the year they were built. It leverages a deep learning model to predict the building era based on visual features. The model is loaded from a checkpoint, which can either be pre-trained or provided by the user.
- checkpoint
Path to the model checkpoint. Defaults to an empty string, which uses a pre-trained model.
- Type:
str
- work_dir
Directory where model files and outputs are stored. Defaults to ‘tmp’.
- Type:
str
- print_res
If True, prints additional debug information. Defaults to False.
- Type:
bool
- classes
List of construction era class labels (e.g., [1960, 1975, 1985, 1995, 2005, 2015]).
- Type:
list
- device
The device on which the model will run, either ‘cpu’ or ‘cuda’ (GPU).
- Type:
str
- checkpoints_dir
Directory for saving and loading model checkpoints.
- Type:
str
- model_file
Path to the model file.
- Type:
str
- model
The loaded PyTorch model.
- Type:
torch.nn.Module
- test_transforms
The transformation pipeline for input preprocessing.
- Type:
torchvision.transforms.Compose
- predict(images
ImageSet): Predicts the construction era for a set of input images.
- evaluate_to_stats(testloader
torch.utils.data.DataLoader): Evaluates the model on a dataset and collects predictions and probabilities.
- construct_confusion_matrix_image(classes
list, con_mat: np.ndarray): Constructs a confusion matrix heatmap for evaluation.
- construct_confusion_matrix_image(con_mat)
Construct a confusion matrix heatmap image.
- Parameters:
classes (list) – List of class labels.
con_mat (np.ndarray) – Confusion matrix.
- Returns:
Matplotlib figure containing the confusion matrix heatmap.
- Return type:
plt.Figure
- evaluate_to_stats(testloader)
Evaluate the model on a dataset & collect predictions & probabilities.
- Parameters:
testloader (torch.utils.data.DataLoader) – The DataLoader for the test dataset.
- Returns:
A list of dictionaries containing predictions, probabilities, and optionally ground truth.
- Return type:
list[dict[str, [str | int | float]]]
- predict(images)
Predict construction era for a set of images provided in an ImageSet.
- Parameters:
images (ImageSet) – An object containing a collection of images, where images.dir_path specifies the directory of images and images.images contains a dictionary of image objects with filenames.
- Raises:
NotADirectoryError – If the provided directory path does not exist or is not a directory.
- Returns:
A dictionary where keys are the image identifiers from images.images, and values are the predicted class labels (construction era) for each image.
- Return type:
dict