From 2b6c0b6ad7e6b19ab9cea26e78020d9bf1b2af8d Mon Sep 17 00:00:00 2001 From: Bartosz Date: Fri, 22 Mar 2024 19:59:20 +0100 Subject: [PATCH 1/3] Update requirements path --- .readthedocs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index eb3ffca..574f4fb 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -18,4 +18,4 @@ sphinx: # Optionally declare the Python requirements required to build your docs python: install: - - requirements: requirements_development.txt + - requirements: ./src/deepness/python_requirements/requirements_development.txt From c206f4a742a530f64421c98785bdd50893c20195 Mon Sep 17 00:00:00 2001 From: Bartosz Date: Sat, 13 Apr 2024 16:13:27 +0200 Subject: [PATCH 2/3] Fix shifted values, updated test for them --- .../map_processor/map_processor_segmentation.py | 10 ++++------ test/test_map_processor_segmentation.py | 16 ++++++++-------- test/test_map_processor_segmentation_sigmoid.py | 7 ++++--- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/deepness/processing/map_processor/map_processor_segmentation.py b/src/deepness/processing/map_processor/map_processor_segmentation.py index ac9b825..635cd47 100644 --- a/src/deepness/processing/map_processor/map_processor_segmentation.py +++ b/src/deepness/processing/map_processor/map_processor_segmentation.py @@ -87,8 +87,7 @@ def _create_result_message(self, result_img: np.ndarray) -> str: total_area = number_of_pixels_in_processing_area * self.params.resolution_m_per_px**2 for channel_id in range(layer_sizes): - # See note in the class description why are we adding/subtracting 1 here - pixels_count = counts_map.get(channel_id, 0) + pixels_count = counts_map.get(channel_id + 1, 0) # we add 1 to avoid 0 values, find the MADD1 code for explanation area = pixels_count * self.params.resolution_m_per_px**2 if total_area > 0 and not np.isnan(total_area) and not np.isinf(total_area): @@ -110,8 +109,7 @@ def _create_vlayer_from_mask_for_base_extent(self, mask_img) -> Callable: for output_id, layer_sizes in enumerate(self._get_indexes_of_model_output_channels_to_create()): output_vlayers = [] for channel_id in range(layer_sizes): - # See note in the class description why are we adding/subtracting 1 here - local_mask_img = np.uint8(mask_img[output_id] == channel_id) + local_mask_img = np.uint8(mask_img[output_id] == (channel_id + 1)) # we add 1 to avoid 0 values, find the MADD1 code for explanation contours, hierarchy = cv2.findContours(local_mask_img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) contours = processing_utils.transform_contours_yx_pixels_to_target_crs( @@ -177,10 +175,10 @@ def _process_tile(self, tile_img_batched: np.ndarray) -> np.ndarray: result = np.expand_dims(result, axis=1) if (result.shape[1] == 1): - result = (result != 0).astype(int) + result = (result != 0).astype(int) + 1 # we add 1 to avoid 0 values, find the MADD1 code for explanation else: shape = result.shape - result = np.argmax(result, axis=1).reshape(shape[0], 1, shape[2], shape[3]) + 1 + result = np.argmax(result, axis=1).reshape(shape[0], 1, shape[2], shape[3]) + 1 # we add 1 to avoid 0 values, find the MADD1 code for explanation assert len(result.shape) == 4 assert result.shape[1] == 1 diff --git a/test/test_map_processor_segmentation.py b/test/test_map_processor_segmentation.py index 77cb2f6..552f7af 100644 --- a/test/test_map_processor_segmentation.py +++ b/test/test_map_processor_segmentation.py @@ -144,10 +144,10 @@ def test_generic_processing_test__specified_extent_from_vlayer_one_channel(): # just check a few pixels assert all(result_img.ravel()[[365, 41234, 59876, 234353, 111222, 134534, 223423, 65463, 156451]] == - np.asarray([0, 1, 1, 1, 1, 0, 0, 1, 0])) + np.asarray([0, 2, 2, 2, 2, 0, 0, 2, 0])) # and counts of different values - np.testing.assert_allclose(np.unique(result_img, return_counts=True)[1], np.array([178063, 206029]), atol=3) + np.testing.assert_allclose(np.unique(result_img, return_counts=True)[1], np.array([166903, 11159, 206030]), atol=3) def test_generic_processing_test__specified_extent_from_vlayer_two_channels(): qgs = init_qgis() @@ -188,10 +188,10 @@ def test_generic_processing_test__specified_extent_from_vlayer_two_channels(): # just check a few pixels assert all(result_img.ravel()[[365, 41234, 59876, 234353, 111222, 134534, 223423, 65463, 156451]] == - np.asarray([0, 1, 1, 1, 1, 0, 0, 1, 0])) + np.asarray([0, 2, 2, 2, 2, 0, 0, 2, 0])) # and counts of different values - np.testing.assert_allclose(np.unique(result_img, return_counts=True)[1], np.array([356126, 412058]), atol=3) + np.testing.assert_allclose(np.unique(result_img, return_counts=True)[1], np.array([333806, 22318, 412060]), atol=3) def test_generic_processing_test__specified_extent_from_vlayer_crs3857_one_channel(): @@ -233,9 +233,9 @@ def test_generic_processing_test__specified_extent_from_vlayer_crs3857_one_chann # just check a few pixels assert all(result_img.ravel()[[365, 41234, 59876, 234353, 111222, 134534, 223423, 65463, 156451]] == - np.asarray([0, 0, 1, 1, 1, 0, 0, 1, 0])) + np.asarray([0, 0, 2, 2, 2, 0, 0, 2, 0])) # and counts of different values - np.testing.assert_allclose(np.unique(result_img, return_counts=True)[1], np.array([193853, 203797]), atol=3) + np.testing.assert_allclose(np.unique(result_img, return_counts=True)[1], np.array([182693, 11159, 203798]), atol=3) def test_generic_processing_test__specified_extent_from_vlayer_crs3857_two_channels(): qgs = init_qgis() @@ -279,9 +279,9 @@ def test_generic_processing_test__specified_extent_from_vlayer_crs3857_two_chann # just check a few pixels assert all(result_img.ravel()[[365, 41234, 59876, 234353, 111222, 134534, 223423, 65463, 156451]] == - np.asarray([0, 0, 1, 1, 1, 0, 0, 1, 0])) + np.asarray([0, 0, 2, 2, 2, 0, 0, 2, 0])) - np.testing.assert_allclose(np.unique(result_img, return_counts=True)[1], np.array([387706, 407594]), atol=3) + np.testing.assert_allclose(np.unique(result_img, return_counts=True)[1], np.array([365386, 22318, 407596]), atol=3) def test_generic_processing_test__specified_extent_from_active_map_extent_one_channel(): diff --git a/test/test_map_processor_segmentation_sigmoid.py b/test/test_map_processor_segmentation_sigmoid.py index 46d74f3..45a0c23 100644 --- a/test/test_map_processor_segmentation_sigmoid.py +++ b/test/test_map_processor_segmentation_sigmoid.py @@ -1,6 +1,7 @@ from test.test_utils import (create_default_input_channels_mapping_for_rgba_bands, create_rlayer_from_file, create_vlayer_from_file, get_dummy_fotomap_area_crs3857_path, get_dummy_fotomap_area_path, - get_dummy_fotomap_small_path, get_dummy_segmentation_model_path, get_dummy_sigmoid_model_path, init_qgis) + get_dummy_fotomap_small_path, get_dummy_segmentation_model_path, + get_dummy_sigmoid_model_path, init_qgis) from unittest.mock import MagicMock import matplotlib.pyplot as plt @@ -56,8 +57,8 @@ def test_sigmoid_model_processing__entire_file(): result_img = map_processor.get_result_img() assert result_img.shape == (1, 561, 829) - non_zero_pixels = np.count_nonzero(result_img) - assert abs(non_zero_pixels - 25002) < 50 # number of RED pixels in the image + pixels = np.unique(result_img, return_counts=True) + assert abs(pixels[1][1] - 25002) < 50 # number of RED pixels in the image # you should see only the part of RASTER_FILE_PATH that is pure red pixels. Use snippet below for debugging # from matplotlib import pyplot as plt From 0722bd83d293afd92431d72f7cafb9b031cee0f6 Mon Sep 17 00:00:00 2001 From: Bartosz Ptak Date: Sat, 13 Apr 2024 16:15:37 +0200 Subject: [PATCH 3/3] Bump version to 0.6.3 --- src/deepness/metadata.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/deepness/metadata.txt b/src/deepness/metadata.txt index 803762f..dcaa04a 100644 --- a/src/deepness/metadata.txt +++ b/src/deepness/metadata.txt @@ -6,7 +6,7 @@ name=Deepness: Deep Neural Remote Sensing qgisMinimumVersion=3.22 description=Inference of deep neural network models (ONNX) for segmentation, detection and regression -version=0.6.2 +version=0.6.3 author=PUT Vision email=przemyslaw.aszkowski@gmail.com