Skip to content

Commit c65ad41

Browse files
committed
Update config.py, checks and old config translations
1 parent 026f9c9 commit c65ad41

File tree

2 files changed

+43
-33
lines changed

2 files changed

+43
-33
lines changed

biapy/biapy_check_configuration.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Copied from BiaPy commit: 280117ca2eef9abfa806040999b12e2548bdaa46 (3.5.3)
1+
## Copied from BiaPy commit: 49d58f6df308b11e49cd7ae8017c61047f4de5aa (3.5.5)
22
import os
33
import glob
44
import numpy as np
@@ -207,11 +207,11 @@ def check_configuration(cfg, jobname, check_data_paths=True):
207207
if not (
208208
len(cfg.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.PROPS)
209209
== len(cfg.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.VALUES)
210-
== len(cfg.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGN)
210+
== len(cfg.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGNS)
211211
):
212212
raise ValueError(
213213
"'TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.PROPS', 'TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.VALUES' and "
214-
"'TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGN' need to have same length"
214+
"'TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGNS' need to have same length"
215215
)
216216

217217
if (
@@ -245,21 +245,21 @@ def check_configuration(cfg, jobname, check_data_paths=True):
245245
"'TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.VALUES' need to be a list of list. E.g. [ [10], [15, 3] ]"
246246
)
247247
if not isinstance(
248-
cfg.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGN[i],
248+
cfg.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGNS[i],
249249
list,
250250
):
251251
raise ValueError(
252-
"'TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGN' need to be a list of list. E.g. [ ['gt'], ['le', 'gt'] ]"
252+
"'TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGNS' need to be a list of list. E.g. [ ['gt'], ['le', 'gt'] ]"
253253
)
254254

255255
if not (
256256
len(cfg.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.PROPS[i])
257257
== len(cfg.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.VALUES[i])
258-
== len(cfg.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGN[i])
258+
== len(cfg.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGNS[i])
259259
):
260260
raise ValueError(
261261
"'TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.PROPS', 'TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.VALUES' and "
262-
"'TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGN' need to have same length"
262+
"'TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGNS' need to have same length"
263263
)
264264

265265
# Check for unique values
@@ -308,14 +308,14 @@ def check_configuration(cfg, jobname, check_data_paths=True):
308308
"'sphericity' property can only be measured in 3D images. Delete it from 'TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.PROPS'. "
309309
"'sphericity'-kind property in 2D is 'circularity'"
310310
)
311-
if cfg.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGN[i][j] not in [
311+
if cfg.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGNS[i][j] not in [
312312
"gt",
313313
"ge",
314314
"lt",
315315
"le",
316316
]:
317317
raise ValueError(
318-
"'TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGN' can only be one among these: ['gt', 'ge', 'lt', 'le']"
318+
"'TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGNS' can only be one among these: ['gt', 'ge', 'lt', 'le']"
319319
)
320320
if cfg.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.PROPS[i][
321321
j
@@ -1512,7 +1512,7 @@ def check_configuration(cfg, jobname, check_data_paths=True):
15121512
"ADAMW",
15131513
], "TRAIN.OPTIMIZER not in ['SGD', 'ADAM', 'ADAMW']"
15141514

1515-
if cfg.TRAIN.LR_SCHEDULER.NAME != "":
1515+
if cfg.TRAIN.ENABLE and cfg.TRAIN.LR_SCHEDULER.NAME != "":
15161516
if cfg.TRAIN.LR_SCHEDULER.NAME not in [
15171517
"reduceonplateau",
15181518
"warmupcosine",
@@ -1973,15 +1973,25 @@ def convert_old_model_cfg_to_current_version(old_cfg):
19731973
old_cfg["TEST"]["POST_PROCESSING"]["MEDIAN_FILTER"] = True
19741974
old_cfg["TEST"]["POST_PROCESSING"]["MEDIAN_FILTER_AXIS"] = ["z"]
19751975
old_cfg["TEST"]["POST_PROCESSING"]["MEDIAN_FILTER_SIZE"] = [fsize]
1976+
1977+
if "MEASURE_PROPERTIES" in old_cfg["TEST"]["POST_PROCESSING"]:
1978+
if "REMOVE_BY_PROPERTIES" in old_cfg["TEST"]["POST_PROCESSING"]["MEASURE_PROPERTIES"]:
1979+
if "SIGN" in old_cfg["TEST"]["POST_PROCESSING"]["MEASURE_PROPERTIES"]["REMOVE_BY_PROPERTIES"]:
1980+
old_cfg["TEST"]["POST_PROCESSING"]["MEASURE_PROPERTIES"]["REMOVE_BY_PROPERTIES"]["SIGNS"] = old_cfg["TEST"]["POST_PROCESSING"]["MEASURE_PROPERTIES"]["REMOVE_BY_PROPERTIES"]["SIGN"]
1981+
del old_cfg["TEST"]["POST_PROCESSING"]["MEASURE_PROPERTIES"]["REMOVE_BY_PROPERTIES"]["SIGN"]
1982+
19761983
if "REMOVE_BY_PROPERTIES" in old_cfg["TEST"]["POST_PROCESSING"]:
19771984
old_cfg["TEST"]["POST_PROCESSING"]["MEASURE_PROPERTIES"] = {}
1978-
old_cfg["TEST"]["POST_PROCESSING"]["MEASURE_PROPERTIES"]["PROPS"] = old_cfg["TEST"]["POST_PROCESSING"]["REMOVE_BY_PROPERTIES"]
1985+
old_cfg["TEST"]["POST_PROCESSING"]["MEASURE_PROPERTIES"]["REMOVE_BY_PROPERTIES"] = {}
1986+
old_cfg["TEST"]["POST_PROCESSING"]["MEASURE_PROPERTIES"]["ENABLE"] = True
1987+
old_cfg["TEST"]["POST_PROCESSING"]["MEASURE_PROPERTIES"]["REMOVE_BY_PROPERTIES"]["ENABLE"] = True
1988+
old_cfg["TEST"]["POST_PROCESSING"]["MEASURE_PROPERTIES"]["REMOVE_BY_PROPERTIES"]["PROPS"] = old_cfg["TEST"]["POST_PROCESSING"]["REMOVE_BY_PROPERTIES"]
19791989
del old_cfg["TEST"]["POST_PROCESSING"]["REMOVE_BY_PROPERTIES"]
19801990
if "REMOVE_BY_PROPERTIES_VALUES" in old_cfg["TEST"]["POST_PROCESSING"]:
1981-
old_cfg["TEST"]["POST_PROCESSING"]["MEASURE_PROPERTIES"]["VALUES"] = old_cfg["TEST"]["POST_PROCESSING"]["REMOVE_BY_PROPERTIES_VALUES"]
1991+
old_cfg["TEST"]["POST_PROCESSING"]["MEASURE_PROPERTIES"]["REMOVE_BY_PROPERTIES"]["VALUES"] = old_cfg["TEST"]["POST_PROCESSING"]["REMOVE_BY_PROPERTIES_VALUES"]
19821992
del old_cfg["TEST"]["POST_PROCESSING"]["REMOVE_BY_PROPERTIES_VALUES"]
19831993
if "REMOVE_BY_PROPERTIES_SIGN" in old_cfg["TEST"]["POST_PROCESSING"]:
1984-
old_cfg["TEST"]["POST_PROCESSING"]["MEASURE_PROPERTIES"]["SIGNS"] = old_cfg["TEST"]["POST_PROCESSING"]["REMOVE_BY_PROPERTIES_SIGN"]
1994+
old_cfg["TEST"]["POST_PROCESSING"]["MEASURE_PROPERTIES"]["REMOVE_BY_PROPERTIES"]["SIGNS"] = old_cfg["TEST"]["POST_PROCESSING"]["REMOVE_BY_PROPERTIES_SIGN"]
19851995
del old_cfg["TEST"]["POST_PROCESSING"]["REMOVE_BY_PROPERTIES_SIGN"]
19861996

19871997
if "PROBLEM" in old_cfg:

biapy/biapy_config.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Copied from BiaPy commit: 280117ca2eef9abfa806040999b12e2548bdaa46 (3.5.3)
1+
## Copied from BiaPy commit: 49d58f6df308b11e49cd7ae8017c61047f4de5aa (3.5.4)
22
import os
33
from yacs.config import CfgNode as CN
44

@@ -259,9 +259,9 @@ def __init__(self, job_dir: str, job_identifier: str):
259259
# Order of the axes of the mask when using Zarr/H5 images in train data.
260260
_C.DATA.TRAIN.INPUT_MASK_AXES_ORDER = "TZCYX"
261261

262-
# Remove training images by the conditions based on their properties. When using Zarr each patch within the Zarr will be processed and not
263-
# the entire image.
264-
# The three variables, DATA.TRAIN.FILTER_SAMPLES.PROPS, DATA.TRAIN.FILTER_SAMPLES.VALUES and DATA.TRAIN.FILTER_SAMPLES.SIGN will compose a list of
262+
# Remove training images by the conditions based on their properties. When using Zarr each patch within the Zarr will be processed and will
263+
# not depend on 'DATA.FILTER_BY_IMAGE' variable
264+
# The three variables, DATA.TRAIN.FILTER_SAMPLES.PROPS, DATA.TRAIN.FILTER_SAMPLES.VALUES and DATA.TRAIN.FILTER_SAMPLES.SIGNS will compose a list of
265265
# conditions to remove the images. They are list of list of conditions. For instance, the conditions can be like this: [['A'], ['B','C']]. Then, if
266266
# the image satisfies the first list of conditions, only 'A' in this first case (from ['A'] list), or satisfy 'B' and 'C' (from ['B','C'] list)
267267
# it will be removed from the image. In each sublist all the conditions must be satisfied. Available properties are: ['foreground', 'mean', 'min', 'max'].
@@ -277,13 +277,13 @@ def __init__(self, job_dir: str, job_identifier: str):
277277
# declare the above three variables as follows:
278278
# _C.DATA.TRAIN.FILTER_SAMPLES.PROPS = [['foreground','mean']]
279279
# _C.DATA.TRAIN.FILTER_SAMPLES.VALUES = [[0.00001, 100]]
280-
# _C.DATA.TRAIN.FILTER_SAMPLES.SIGN = [['lt', 'gt']]
280+
# _C.DATA.TRAIN.FILTER_SAMPLES.SIGNS = [['lt', 'gt']]
281281
# You can also concatenate more restrictions and they will be applied in order. For instance, if you want to filter those
282282
# samples with a max value more than 1000, and do that before the condition described above, you can define the
283283
# variables this way:
284284
# _C.DATA.TRAIN.FILTER_SAMPLES.PROPS = [['max'], ['foreground','mean']]
285285
# _C.DATA.TRAIN.FILTER_SAMPLES.VALUES = [[1000], [0.00001, 100]]
286-
# _C.DATA.TRAIN.FILTER_SAMPLES.SIGN = [['gt'], ['lt', 'gt']]
286+
# _C.DATA.TRAIN.FILTER_SAMPLES.SIGNS = [['gt'], ['lt', 'gt']]
287287
# This way, the images will be removed by 'max' and then by 'foreground' and 'mean'
288288
_C.DATA.TRAIN.FILTER_SAMPLES = CN()
289289
# Whether to enable or not the filtering by properties
@@ -414,9 +414,9 @@ def __init__(self, job_dir: str, job_identifier: str):
414414
_C.DATA.TEST.RESOLUTION = (-1,)
415415
# Whether to apply argmax to the predicted images
416416
_C.DATA.TEST.ARGMAX_TO_OUTPUT = True
417-
# Remove test images by the conditions based on their properties. When using Zarr each patch within the Zarr will be processed and not
418-
# the entire image.
419-
# The three variables, DATA.TEST.FILTER_SAMPLES.PROPS, DATA.TEST.FILTER_SAMPLES.VALUES and DATA.TEST.FILTER_SAMPLES.SIGN will compose a
417+
# Remove test images by the conditions based on their properties. When using Zarr each patch within the Zarr will be processed and will
418+
# not depend on 'DATA.FILTER_BY_IMAGE' variable
419+
# The three variables, DATA.TEST.FILTER_SAMPLES.PROPS, DATA.TEST.FILTER_SAMPLES.VALUES and DATA.TEST.FILTER_SAMPLES.SIGNS will compose a
420420
# list of conditions to remove the images. They are list of list of conditions. For instance, the conditions can be like this: [['A'], ['B','C']].
421421
# Then, if the image satisfies the first list of conditions, only 'A' in this first case (from ['A'] list), or satisfy 'B' and 'C' (from ['B','C'] list)
422422
# it will be removed from the image. In each sublist all the conditions must be satisfied. Available properties are: ['foreground', 'mean', 'min', 'max'].
@@ -432,13 +432,13 @@ def __init__(self, job_dir: str, job_identifier: str):
432432
# declare the above three variables as follows:
433433
# _C.DATA.TEST.FILTER_SAMPLES.PROPS = [['foreground','mean']]
434434
# _C.DATA.TEST.FILTER_SAMPLES.VALUES = [[0.00001, 100]]
435-
# _C.DATA.TEST.FILTER_SAMPLES.SIGN = [['lt', 'gt']]
435+
# _C.DATA.TEST.FILTER_SAMPLES.SIGNS = [['lt', 'gt']]
436436
# You can also concatenate more restrictions and they will be applied in order. For instance, if you want to filter those
437437
# samples with a max value more than 1000, and do that before the condition described above, you can define the
438438
# variables this way:
439439
# _C.DATA.TEST.FILTER_SAMPLES.PROPS = [['max'], ['foreground','mean']]
440440
# _C.DATA.TEST.FILTER_SAMPLES.VALUES = [[1000], [0.00001, 100]]
441-
# _C.DATA.TEST.FILTER_SAMPLES.SIGN = [['gt'], ['lt', 'gt']]
441+
# _C.DATA.TEST.FILTER_SAMPLES.SIGNS = [['gt'], ['lt', 'gt']]
442442
# This way, the images will be removed by 'max' and then by 'foreground' and 'mean'
443443
_C.DATA.TEST.FILTER_SAMPLES = CN()
444444
# Whether to enable or not the filtering by properties
@@ -507,9 +507,9 @@ def __init__(self, job_dir: str, job_identifier: str):
507507
_C.DATA.VAL.INPUT_IMG_AXES_ORDER = "TZCYX"
508508
# Order of the axes of the mask when using Zarr/H5 images in validation data.
509509
_C.DATA.VAL.INPUT_MASK_AXES_ORDER = "TZCYX"
510-
# Remove validation images by the conditions based on their properties. When using Zarr each patch within the Zarr will be processed and not
511-
# the entire image.
512-
# The three variables, DATA.VAL.FILTER_SAMPLES.PROPS, DATA.VAL.FILTER_SAMPLES.VALUES and DATA.VAL.FILTER_SAMPLES.SIGN will compose a list of
510+
# Remove validation images by the conditions based on their properties. When using Zarr each patch within the Zarr will be processed and will
511+
# not depend on 'DATA.FILTER_BY_IMAGE' variable
512+
# The three variables, DATA.VAL.FILTER_SAMPLES.PROPS, DATA.VAL.FILTER_SAMPLES.VALUES and DATA.VAL.FILTER_SAMPLES.SIGNS will compose a list of
513513
# conditions to remove the images. They are list of list of conditions. For instance, the conditions can be like this: [['A'], ['B','C']]. Then,
514514
# if the image satisfies the first list of conditions, only 'A' in this first case (from ['A'] list), or satisfy 'B' and 'C' (from ['B','C'] list)
515515
# it will be removed from the image. In each sublist all the conditions must be satisfied. Available properties are: ['foreground', 'mean', 'min', 'max'].
@@ -525,13 +525,13 @@ def __init__(self, job_dir: str, job_identifier: str):
525525
# declare the above three variables as follows:
526526
# _C.DATA.VAL.FILTER_SAMPLES.PROPS = [['foreground','mean']]
527527
# _C.DATA.VAL.FILTER_SAMPLES.VALUES = [[0.00001, 100]]
528-
# _C.DATA.VAL.FILTER_SAMPLES.SIGN = [['lt', 'gt']]
528+
# _C.DATA.VAL.FILTER_SAMPLES.SIGNS = [['lt', 'gt']]
529529
# You can also concatenate more restrictions and they will be applied in order. For instance, if you want to filter those
530530
# samples with a max value more than 1000, and do that before the condition described above, you can define the
531531
# variables this way:
532532
# _C.DATA.VAL.FILTER_SAMPLES.PROPS = [['max'], ['foreground','mean']]
533533
# _C.DATA.VAL.FILTER_SAMPLES.VALUES = [[1000], [0.00001, 100]]
534-
# _C.DATA.VAL.FILTER_SAMPLES.SIGN = [['gt'], ['lt', 'gt']]
534+
# _C.DATA.VAL.FILTER_SAMPLES.SIGNS = [['gt'], ['lt', 'gt']]
535535
# This way, the images will be removed by 'max' and then by 'foreground' and 'mean'
536536
_C.DATA.VAL.FILTER_SAMPLES = CN()
537537
# Whether to enable or not the filtering by properties
@@ -1164,7 +1164,7 @@ def __init__(self, job_dir: str, job_identifier: str):
11641164
_C.TEST.POST_PROCESSING.MEASURE_PROPERTIES = CN()
11651165
_C.TEST.POST_PROCESSING.MEASURE_PROPERTIES.ENABLE = False
11661166
# Remove instances by the conditions based in each instance properties. The three variables, TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.PROPS,
1167-
# TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.VALUES and TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGN will compose a list
1167+
# TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.VALUES and TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGNS will compose a list
11681168
# of conditions to remove the instances. They are list of list of conditions. For instance, the conditions can be like this: [['A'], ['B','C']]. Then, if the instance satisfies
11691169
# the first list of conditions, only 'A' in this first case (from ['A'] list), or satisfy 'B' and 'C' (from ['B','C'] list) it will be
11701170
# removed from the image. In each sublist all the conditions must be satisfied. Available properties are: ['circularity', 'elongation',
@@ -1208,13 +1208,13 @@ def __init__(self, job_dir: str, job_identifier: str):
12081208
# declare the above three variables as follows:
12091209
# _C.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.PROPS = [['npixels', 'circularity']]
12101210
# _C.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.VALUES = [[100, 0.7]]
1211-
# _C.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGN = [['lt', 'le']]
1211+
# _C.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGNS = [['lt', 'le']]
12121212
# You can also concatenate more restrictions and they will be applied in order. For instance, if you want to remove those
12131213
# instances that are bigger than an specific area, and do that before the condition described above, you can define the
12141214
# variables this way:
12151215
# _C.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.PROPS = [['area'], ['npixels', 'circularity']]
12161216
# _C.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.VALUES = [[500], [100, 0.7]]
1217-
# _C.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGN = [['gt'], ['lt', 'le']]
1217+
# _C.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGNS = [['gt'], ['lt', 'le']]
12181218
# This way, the instances will be removed by 'area' and then by 'npixels' and 'circularity'
12191219
_C.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES = CN()
12201220
# Whether to enable or not the filtering by properties
@@ -1227,7 +1227,7 @@ def __init__(self, job_dir: str, job_identifier: str):
12271227
_C.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.VALUES = []
12281228
# List of list of signs to do the comparison. Options: ['gt', 'ge', 'lt', 'le'] that corresponds to "greather than", e.g. ">",
12291229
# "greather equal", e.g. ">=", "less than", e.g. "<", and "less equal" e.g. "<=" comparisons.
1230-
_C.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGN = []
1230+
_C.TEST.POST_PROCESSING.MEASURE_PROPERTIES.REMOVE_BY_PROPERTIES.SIGNS = []
12311231

12321232
# Whether to apply Voronoi using 'BC' or 'M' channels need to be present
12331233
_C.TEST.POST_PROCESSING.VORONOI_ON_MASK = False

0 commit comments

Comments
 (0)