Skip to content

WIP Code for ISMRM23 (Sourcery refactored)#3

Open
sourcery-ai[bot] wants to merge 1 commit intoWIP_ISMRM23from
sourcery/pull-2
Open

WIP Code for ISMRM23 (Sourcery refactored)#3
sourcery-ai[bot] wants to merge 1 commit intoWIP_ISMRM23from
sourcery/pull-2

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented May 21, 2023

Pull Request #2 refactored by Sourcery.

Since the original Pull Request was opened as a fork in a contributor's
repository, we are unable to create a Pull Request branching from it.

To incorporate these changes, you can either:

  1. Merge this Pull Request instead of the original, or

  2. Ask your contributor to locally incorporate these commits and push them to
    the original Pull Request

    Incorporate changes via command line
    git fetch https://github.com/soumickmj/DS6 pull/2/head
    git merge --ff-only FETCH_HEAD
    git push

NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from soumickmj May 21, 2023 21:15
@@ -2,6 +2,7 @@
"""
"""

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 184-210 refactored with the following changes:

self.model_type = cmd_args.model
self.lr_1 = cmd_args.learning_rate
self.logger.info("learning rate " + str(self.lr_1))
self.logger.info(f"learning rate {str(self.lr_1)}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Pipeline.__init__ refactored with the following changes:

Comment on lines -120 to +138
trainDS = SRDataset(logger=self.logger, patch_size=self.patch_size,
dir_path=vol_path,
label_dir_path=label_path,
# TODO: implement non-iso patch-size, now only using the first element
stride_depth=self.stride_depth, stride_length=self.stride_length,
stride_width=self.stride_width, Size=None, fly_under_percent=None,
# TODO: implement fly_under_percent, if needed
patch_size_us=self.patch_size, pre_interpolate=None, norm_data=False,
pre_load=True,
return_coords=True,
files_us=crossvalidation_set) # TODO implement patch_size_us if required - patch_size//scaling_factor
if get_subjects_only:
return trainDS
# sampler = tio.data.UniformSampler(self.patch_size)
# patches_queue = tio.Queue(
# trainDS,
# max_length=(self.samples_per_epoch // len(trainDS.pre_loaded_data['pre_loaded_img'])) * 2,
# samples_per_volume=1,
# sampler=sampler,
# num_workers=0,
# start_background=True
# )
# return patches_queue
return trainDS
return SRDataset(
logger=self.logger,
patch_size=self.patch_size,
dir_path=vol_path,
label_dir_path=label_path,
# TODO: implement non-iso patch-size, now only using the first element
stride_depth=self.stride_depth,
stride_length=self.stride_length,
stride_width=self.stride_width,
Size=None,
fly_under_percent=None,
# TODO: implement fly_under_percent, if needed
patch_size_us=self.patch_size,
pre_interpolate=None,
norm_data=False,
pre_load=True,
return_coords=True,
files_us=crossvalidation_set,
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Pipeline.create_TIOSubDS refactored with the following changes:

This removes the following comments ( why? ):

#     num_workers=0,
#     max_length=(self.samples_per_epoch // len(trainDS.pre_loaded_data['pre_loaded_img'])) * 2,
# return patches_queue
# TODO implement patch_size_us if required - patch_size//scaling_factor
# )
#     start_background=True
# sampler = tio.data.UniformSampler(self.patch_size)
#     samples_per_volume=1,
# patches_queue = tio.Queue(
#     sampler=sampler,
#     trainDS,

union = torch.sum(y_true_f + y_pred_f) - intersection
score = (intersection + self.smooth) / (union + self.smooth)
return score
return (intersection + self.smooth) / (union + self.smooth)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function IOU.forward refactored with the following changes:

Comment on lines -84 to +92
torch.save(param, os.path.join(self.output_dir, 'nan_floss_{}_param.pt'.format(name)))
raise RuntimeError(" classname " + self.__class__.__name__ + "i " + str(
i) + f" module: {module} classname {self.__class__.__name__} Found NAN in output {i} at indices: ",
nan_mask.nonzero(), "where:", out[nan_mask.nonzero()[:, 0].unique(sorted=True)])
torch.save(param, os.path.join(self.output_dir, f'nan_floss_{name}_param.pt'))
raise RuntimeError(
(
f" classname {self.__class__.__name__}i {str(i)}"
+ f" module: {module} classname {self.__class__.__name__} Found NAN in output {i} at indices: "
),
nan_mask.nonzero(),
"where:",
out[nan_mask.nonzero()[:, 0].unique(sorted=True)],
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FocalTverskyLoss.nan_hook refactored with the following changes:

underKSPVol = performUndersamplingKSP(fullKSPVol, mask, maskmatpath, zeropad)
underImgVol = ifft2c(underKSPVol)
return underImgVol
return ifft2c(underKSPVol)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function performUndersampling refactored with the following changes:

Comment on lines -92 to +103
underKSPVol = np.multiply(fullKSPVol.transpose((2, 0, 1)), mask).transpose((1, 2, 0))
else:
temp = []
for i in range(mask.shape[0]):
maskline = mask[i, :]
if maskline.any():
temp.append(fullKSPVol[i, ...])
temp = np.array(temp)
underKSPVol = []
for i in range(mask.shape[1]):
maskline = mask[:, i]
if maskline.any():
underKSPVol.append(temp[:, i, ...])
underKSPVol = np.array(underKSPVol).swapaxes(0, 1)
return underKSPVol
return np.multiply(fullKSPVol.transpose((2, 0, 1)), mask).transpose((1, 2, 0))
temp = []
for i in range(mask.shape[0]):
maskline = mask[i, :]
if maskline.any():
temp.append(fullKSPVol[i, ...])
temp = np.array(temp)
underKSPVol = []
for i in range(mask.shape[1]):
maskline = mask[:, i]
if maskline.any():
underKSPVol.append(temp[:, i, ...])
return np.array(underKSPVol).swapaxes(0, 1)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function performUndersamplingKSP refactored with the following changes:

if closure is not None:
loss = closure()

loss = closure() if closure is not None else None
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Madam.step refactored with the following changes:

Comment on lines -121 to +127
print('convert_and_save_tif:size of image:'+ str(len(image_list)))
print(f'convert_and_save_tif:size of image:{len(image_list)}')
with TiffImagePlugin.AppendingTiffWriter(output_path + filename, True) as tifWriter:
for im in image_list:
# with open(DATASET_FOLDER+tiff_in) as tiff_in:
im.save(tifWriter)
tifWriter.newFrame()
print("Conversion to tiff completed, image saved as {}".format(filename))
print(f"Conversion to tiff completed, image saved as {filename}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function convert_and_save_tif refactored with the following changes:

Comment on lines -140 to +146
print('convert_and_save_tif:size of image:' + str(len(image_list)))
print(f'convert_and_save_tif:size of image:{len(image_list)}')
with TiffImagePlugin.AppendingTiffWriter(output_path + filename, True) as tifWriter:
for im in image_list:
# with open(DATASET_FOLDER+tiff_in) as tiff_in:
im.save(tifWriter)
tifWriter.newFrame()
print("Conversion to tiff completed, image saved as {}".format(filename))
print(f"Conversion to tiff completed, image saved as {filename}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function convert_and_save_tif_greyscale refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants