Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1349 breaking change SSIMLoss #1351

Merged
merged 2 commits into from
Apr 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions reconstruction/MRI_reconstruction/varnet_demo/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ def trainer(args):
model.load_state_dict(torch.load(args.checkpoint_dir))
print("resume training from a given checkpoint...")

# create the loss function
loss_function = SSIMLoss(spatial_dims=2).to(device)

# create the optimizer and the learning rate scheduler
optimizer = torch.optim.Adam(model.parameters(), lr=args.lr, weight_decay=args.weight_decay)
scheduler = torch.optim.lr_scheduler.StepLR(optimizer, args.lr_step_size, args.lr_gamma)
Expand All @@ -166,6 +163,9 @@ def trainer(args):
final_shape = target.shape[-2:]
max_value = torch.tensor(max_value).unsqueeze(0).to(device)

# create the loss function with data_range
loss_function = SSIMLoss(spatial_dims=2, data_range=max_value).to(device)
wyli marked this conversation as resolved.
Show resolved Hide resolved

# iterate through all slices
slice_dim = 1 # change this if another dimension is your slice dimension
num_slices = input.shape[slice_dim]
Expand All @@ -183,7 +183,7 @@ def trainer(args):
cropper = SpatialCrop(roi_center=roi_center, roi_size=final_shape)
output_crp = cropper(output).unsqueeze(0)

loss = loss_function(output_crp, tar, max_value)
loss = loss_function(output_crp, tar)

loss.backward()
optimizer.step()
Expand Down