def test_memory(self, input_param, expected_key_size): input_data = dict() for i in range(50): input_data[str(i)] = [time.time()] * 100000 result = DeleteItemsd(**input_param)(input_data) self.assertEqual(len(result.keys()), expected_key_size) self.assertGreaterEqual( sys.getsizeof(input_data) * float(expected_key_size) / len(input_data), sys.getsizeof(result))
def test_memory(self, input_param, expected_key_size): input_data = {"image": {}} if "sep" in input_param else {} for i in range(50): if "sep" in input_param: input_data["image"][str(i)] = [time.time()] * 100000 else: input_data[str(i)] = [time.time()] * 100000 result = DeleteItemsd(**input_param)(input_data) if "sep" in input_param: self.assertEqual(len(result["image"].keys()), expected_key_size) else: self.assertEqual(len(result.keys()), expected_key_size) self.assertGreaterEqual( sys.getsizeof(input_data) * float(expected_key_size) / len(input_data), sys.getsizeof(result) )
def get_xforms(mode="train", keys=("image", "label"), keys2=("image", "label", "synthesis"), path_synthesis='', decreasing_sequence='', scans_syns=[], texture=[], GEN=15): """returns a composed transform for train/val/infer.""" xforms = [ LoadImaged(keys), AddChanneld(keys), Orientationd(keys, axcodes="LPS"), Spacingd(keys, pixdim=(1.25, 1.25, 5.0), mode=("bilinear", "nearest")[:len(keys)]), ScaleIntensityRanged(keys[0], a_min=-1000.0, a_max=500.0, b_min=0.0, b_max=1.0, clip=True), ] if mode == "train": xforms.extend([ SpatialPadd(keys, spatial_size=(192, 192, -1), mode="reflect"), # ensure at least 192x192 RandAffined( keys, prob=0.15, rotate_range=( 0.05, 0.05, None ), # 3 parameters control the transform on 3 dimensions scale_range=(0.1, 0.1, None), mode=("bilinear", "nearest"), as_tensor_output=False, ), RandCropByPosNegLabeld(keys, label_key=keys[1], spatial_size=(192, 192, 16), num_samples=3), RandGaussianNoised(keys[0], prob=0.15, std=0.01), RandFlipd(keys, spatial_axis=0, prob=0.5), RandFlipd(keys, spatial_axis=1, prob=0.5), RandFlipd(keys, spatial_axis=2, prob=0.5), ]) dtype = (np.float32, np.uint8) if mode == "synthesis": print('DOING SYNTHESIS') xforms.extend([ CopyItemsd(keys, 1, names=['image_1', 'label_1']), # PrintTypesShapes(keys, '======SHAPE LOAD'), SpatialPadd(keys, spatial_size=(192, 192, -1), mode="reflect"), # ensure at least 192x192 RandCropByPosNegLabeld(keys, label_key=keys[1], spatial_size=(192, 192, 16), num_samples=3), TransCustom(keys, path_synthesis, read_cea_aug_slice2, pseudo_healthy_with_texture, scans_syns, decreasing_sequence, GEN=GEN, POST_PROCESS=True, mask_outer_ring=True, texture=np.empty(shape=(456, 456)), new_value=.5), RandAffined( keys2, prob=0.15, rotate_range=( 0.05, 0.05, None ), # 3 parameters control the transform on 3 dimensions scale_range=(0.1, 0.1, None), mode=("bilinear", "nearest", "bilinear"), # mode=("bilinear", "nearest"), as_tensor_output=False), RandGaussianNoised((keys2[0], keys2[2]), prob=0.15, std=0.01), # RandGaussianNoised(keys[0], prob=0.15, std=0.01), RandFlipd(keys, spatial_axis=0, prob=0.5), RandFlipd(keys, spatial_axis=1, prob=0.5), RandFlipd(keys, spatial_axis=2, prob=0.5), TransCustom2(keys2), SpatialPadd(keys, spatial_size=(192, 192, -1), mode="reflect"), DeleteItemsd(('image_1', 'label_1')), # PrintTypesShapes(('image_1', 'label_1','synthetic_lesion', 'synthetic_label'), '=syn='), ]) dtype = (np.float32, np.uint8) if mode == "val": dtype = (np.float32, np.uint8) if mode == "infer": dtype = (np.float32, ) xforms.extend([CastToTyped(keys, dtype=dtype), EnsureTyped(keys)]) return monai.transforms.Compose(xforms)
def test_re(self, input_param): input_data = {"image": [1, 2, 3], PostFix.meta(): {"0008|0005": 1, "0008|1050": 2, "0008test": 3}} result = DeleteItemsd(**input_param)(input_data) self.assertEqual(result[PostFix.meta()]["0008test"], 3) self.assertTrue(len(result[PostFix.meta()]), 1)