Skip to content

Commit

Permalink
Merge pull request #22 from hi-paris/add_sentinel_tops_model
Browse files Browse the repository at this point in the history
Add sentinel tops model
  • Loading branch information
brash6 authored Apr 9, 2024
2 parents 1fb3e0a + 8b42f43 commit af642db
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ In order to get the right model, the `model_name` has to be specified when build
This `model_name` can either be :
- `"spotlight"` for SAR images retrieved with spotlight mode
- `"stripmap"` for SAR images retrieved with stripmap mode
- `"Sentinel-TOPS"` for SAR images retrieved with TOPS mode


During the preprocessing steps of the noisy image for MERLIN, the real and the imaginary parts are <strong>"symetrised"</strong> (to match the theoretical assumptions of MERLIN). To skip this step, you can set the `symetrise` parameter to `False`

Expand All @@ -47,7 +49,7 @@ from deepdespeckling.merlin.merlin_denoiser import MerlinDenoiser

# Path to one image (cos or npy file)
image_path="path/to/cosar/image"
# Model name, can be "spotlight" or "stripmap"
# Model name, can be "spotlight", "stripmap" or "Sentinel-TOPS"
model_name = "spotlight"
symetrise = True

Expand Down
19 changes: 10 additions & 9 deletions deepdespeckling/despeckling.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
logging.basicConfig(level=logging.INFO)


def get_denoiser(model_name: str, symetrise: bool = True) -> Denoiser:
def _get_denoiser(model_name: str, symetrise: bool = True) -> Denoiser:
"""Get the right denoiser object from the model name
Args:
Expand All @@ -24,7 +24,7 @@ def get_denoiser(model_name: str, symetrise: bool = True) -> Denoiser:
Returns:
denoiser (Denoiser): the right denoiser, Sar2SarDenoiser or MerlinDenoiser
"""
if model_name in ["spotlight", "stripmap"]:
if model_name in ["spotlight", "stripmap", "Sentinel_TOPS"]:
denoiser = MerlinDenoiser(model_name=model_name, symetrise=symetrise)
elif model_name == "sar2sar":
denoiser = Sar2SarDenoiser()
Expand All @@ -41,7 +41,7 @@ def despeckle(sar_images_path: str, destination_directory_path: str, model_name:
Args:
sar_images_path (str): path of sar images
destination_directory_path (str): path of folder in which results will be stored
model_name (str): model name, either "spotlight" or "stripmap" to select MERLIN model on the
model_name (str): model name, either "spotlight", "stripmap" or "Sentinel_TOPS" to select MERLIN model on the
right cosar image format or "sar2sar" for SAR2SAR model. Default to "spotlight"
patch_size (int): patch size. Defaults to constant PATCH_SIZE.
stride_size (int): stride size. Defaults to constant STRIDE_SIZE.
Expand All @@ -60,7 +60,7 @@ def despeckle(sar_images_path: str, destination_directory_path: str, model_name:
logging.info(
f"Starting inference.. Collecting data from {sar_images_path} and storing test results in {destination_directory_path}")

denoiser = get_denoiser(model_name=model_name, symetrise=symetrise)
denoiser = _get_denoiser(model_name=model_name, symetrise=symetrise)
denoiser.denoise_images(images_to_denoise_path=processed_images_path, save_dir=destination_directory_path,
patch_size=patch_size, stride_size=stride_size)

Expand All @@ -73,7 +73,7 @@ def despeckle_from_coordinates(sar_images_path: str, coordinates_dict: dict, des
sar_images_path (str): path of sar images
coordinates_dict (dict): dictionary containing pixel boundaries of the area to despeckle (x_start, x_end, y_start, y_end)
destination_directory_path (str): path of folder in which results will be stored
model_name (str): model name, either "spotlight" or "stripmap" to select MERLIN model on the
model_name (str): model name, either "spotlight", "stripmap" or "Sentinel_TOPS" to select MERLIN model on the
right cosar image format or "sar2sar" for SAR2SAR model. Default to "spotlight"
patch_size (int): patch size. Defaults to constant PATCH_SIZE.
stride_size (int): stride size. Defaults to constant STRIDE_SIZE.
Expand All @@ -92,7 +92,7 @@ def despeckle_from_coordinates(sar_images_path: str, coordinates_dict: dict, des
logging.info(
f"Starting inference.. Collecting data from {sar_images_path} and storing test results in {destination_directory_path}")

denoiser = get_denoiser(model_name=model_name, symetrise=symetrise)
denoiser = _get_denoiser(model_name=model_name, symetrise=symetrise)
denoiser.denoise_images(images_to_denoise_path=processed_images_path, save_dir=destination_directory_path,
patch_size=patch_size, stride_size=stride_size)

Expand All @@ -106,7 +106,7 @@ def despeckle_from_crop(sar_images_path: str, destination_directory_path: str, m
destination_directory_path (str): path of folder in which results will be stored
patch_size (int): patch size. Defaults to constant PATCH_SIZE.
stride_size (int): stride size. Defaults to constant STRIDE_SIZE.
model_name (str): model name, either "spotlight" or "stripmap" to select MERLIN model on the
model_name (str): model name, either "spotlight", "stripmap" or "Sentinel_TOPS" to select MERLIN model on the
right cosar image format or "sar2sar" for SAR2SAR model. Default to "spotlight"
fixed (bool) : If True, crop size is limited to 256*256. Defaults to True
symetrise (bool) : if using spotlight or stripmap model, if True, will symetrise the real and
Expand All @@ -119,7 +119,8 @@ def despeckle_from_crop(sar_images_path: str, destination_directory_path: str, m
processed_images_path = create_empty_folder_in_directory(destination_directory_path=destination_directory_path,
folder_name="processed_images")

ext = "cos" if model_name in ["spotlight", "stripmap"] else "tiff"
ext = "cos" if model_name in ["spotlight",
"stripmap", "Sentinel_TOPS"] else "tiff"
images_paths = glob(os.path.join(sar_images_path, f"*.{ext}")) + \
glob(os.path.join(sar_images_path, "*.npy"))

Expand All @@ -139,6 +140,6 @@ def despeckle_from_crop(sar_images_path: str, destination_directory_path: str, m
logging.info(
f"Starting inference.. Collecting data from {sar_images_path} and storing results in {destination_directory_path}")

denoiser = get_denoiser(model_name=model_name, symetrise=symetrise)
denoiser = _get_denoiser(model_name=model_name, symetrise=symetrise)
denoiser.denoise_images(images_to_denoise_path=processed_images_path, save_dir=destination_directory_path,
patch_size=patch_size, stride_size=stride_size)
5 changes: 4 additions & 1 deletion deepdespeckling/merlin/merlin_denoiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, model_name, symetrise, **params):
"""Initialize MerlinDenoiser class
Args:
model_name (str): name to be used, can be "spotlight" or "stripmap"
model_name (str): name to be used, can be "spotlight", "stripmap" or "Sentinel_TOPS"
"""
super().__init__(**params)
self.model_name = model_name
Expand All @@ -42,6 +42,9 @@ def init_model_weights_path(self) -> str:
elif self.model_name == "stripmap":
model_weights_path = os.path.join(
current_dir, "saved_models/stripmap.pth")
elif self.model_name == "Sentinel_TOPS":
model_weights_path = os.path.join(
current_dir, "saved_models/sentinel_tops.pth")
else:
raise ValueError(
"The model name doesn't refer to an existing model ")
Expand Down
Binary file not shown.

0 comments on commit af642db

Please sign in to comment.