[POC] classif step 4: fusion classification
Context
After implementing the ClassificationLayer base class, we now need to develop the FusionClassificationLayer. This class handles the fusion of multiple classification layers, combining the results of individual classifications (e.g., slope and segmentation) into a fused classification. The fusion layer takes the outputs from other classification layers and creates a combined class mask.
The FusionClassificationLayer will inherit from the ClassificationLayer and implement the specific logic for fusing multiple classification layers.
Code
In the same file (classification.py) as the ClassificationLayer base class, add the FusionClassificationLayer to define the fusion classification logic.
-
__init__()method:- Extend the initialization from the
ClassificationLayer. - Include additional attributes specific to fusion classification:
-
layers_to_fuse: A list ofMaskobjects that are being fused together (e.g., slope and segmentation layers). -
layers_class_names: A list of dictionaries where each dictionary represents the class names of the layers being fused.
-
- Extend the initialization from the
-
apply_classification()method:-
Combine the masks of the input classification layers using logical operations (e.g., intersection of masks) to create new fused classes.
-
Store the combined masks in the
classificationattribute, which is ageoutils.Mask3D object, where the first dimension represents the fused class, and the two others represent the mask values. The number of bands inclassificationshould be equal to the multiplication of the number of bands of all layers to fuse. -
Store the fused class names under the
class_namesattribute, which will combine the class names of the fused layers.Example:
-
self.class_names = {
"slope0_5_land": 0,
"slope5_10_land": 1,
"slope10_25_land": 2,
"slope0_5_water": 1
...
}
Tests
- Write unit tests for the
FusionClassificationLayerclass intest_classification.pyfile. - The unit tests should:
- Verify that the layer initializes properly with the provided configuration.
- Ensure that the classification logic works as expected.
- Confirm that statistics are computed as expected.
- Validate that the results are saved correctly.