MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / resample_datalist

Function resample_datalist

monai/data/utils.py:1310–1332  ·  view source on GitHub ↗

Utility function to resample the loaded datalist for training, for example: If factor < 1.0, randomly pick part of the datalist and set to Dataset, useful to quickly test the program. If factor > 1.0, repeat the datalist to enhance the Dataset. Args: data: original datalist

(data: Sequence, factor: float, random_pick: bool = False, seed: int = 0)

Source from the content-addressed store, hash-verified

1308
1309
1310def resample_datalist(data: Sequence, factor: float, random_pick: bool = False, seed: int = 0):
1311 """
1312 Utility function to resample the loaded datalist for training, for example:
1313 If factor < 1.0, randomly pick part of the datalist and set to Dataset, useful to quickly test the program.
1314 If factor > 1.0, repeat the datalist to enhance the Dataset.
1315
1316 Args:
1317 data: original datalist to scale.
1318 factor: scale factor for the datalist, for example, factor=4.5, repeat the datalist 4 times and plus
1319 50% of the original datalist.
1320 random_pick: whether to randomly pick data if scale factor has decimal part.
1321 seed: random seed to randomly pick data.
1322
1323 """
1324 scale, repeats = math.modf(factor)
1325 ret: list = list()
1326
1327 for _ in range(int(repeats)):
1328 ret.extend(list(deepcopy(data)))
1329 if scale > 1e-6:
1330 ret.extend(partition_dataset(data=data, ratios=[scale, 1 - scale], shuffle=random_pick, seed=seed)[0])
1331
1332 return ret
1333
1334
1335def select_cross_validation_folds(partitions: Sequence[Iterable], folds: Sequence[int] | int) -> list:

Callers 1

test_value_shapeMethod · 0.90

Calls 2

partition_datasetFunction · 0.85
extendMethod · 0.80

Tested by 1

test_value_shapeMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…