-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add standardization_parameters metaparameter handle
- Loading branch information
1 parent
8c02bfd
commit 089cd88
Showing
5 changed files
with
92 additions
and
15 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/deepness/common/processing_parameters/standardization_parameters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import numpy as np | ||
|
||
|
||
class StandardizationParameters: | ||
mean: float | ||
std: float | ||
|
||
def __init__(self): | ||
self.mean = np.array([0.0, 0.0, 0.0], dtype=np.float32) | ||
self.std = np.array([1.0, 1.0, 1.0], dtype=np.float32) | ||
|
||
def set_mean_std(self, mean: np.array, std: np.array): | ||
self.mean = np.array(mean, dtype=np.float32) | ||
self.std = np.array(std, dtype=np.float32) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import cv2 | ||
import numpy as np | ||
|
||
from deepness.common.processing_parameters.standardization_parameters import StandardizationParameters | ||
|
||
|
||
def limit_channels_number(tiles_batched: np.array, limit: int) -> np.array: | ||
""" Limit the number of channels in the input image to the model | ||
:param tiles_batched: Batch of tiles | ||
:param limit: Number of channels to keep | ||
:return: Batch of tiles with limited number of channels | ||
""" | ||
return tiles_batched[:, :, :, :limit] | ||
|
||
|
||
def normalize_values_to_01(tiles_batched: np.array) -> np.array: | ||
""" Normalize the values of the input image to the model to the range [0, 1] | ||
:param tiles_batched: Batch of tiles | ||
:return: Batch of tiles with values in the range [0, 1], in float32 | ||
""" | ||
return np.float32(tiles_batched * 1./255.) | ||
|
||
|
||
def standardize_values(tiles_batched: np.array, params: StandardizationParameters) -> np.array: | ||
""" Standardize the input image to the model | ||
:param tiles_batched: Batch of tiles | ||
:param params: Parameters for standardization of type STANDARIZE_PARAMS | ||
:return: Batch of tiles with standardized values | ||
""" | ||
return (tiles_batched - params.mean) / params.std | ||
|
||
|
||
def transpose_nhwc_to_nchw(tiles_batched: np.array) -> np.array: | ||
""" Transpose the input image from NHWC to NCHW | ||
:param tiles_batched: Batch of tiles in NHWC format | ||
:return: Batch of tiles in NCHW format | ||
""" | ||
return np.transpose(tiles_batched, (0, 3, 1, 2)) |