Skip to content
Open
Changes from all commits
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
14 changes: 11 additions & 3 deletions preprocess_capture_data/calc_masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,24 @@ def calculate_mask(args):
normalize,
])

# Load existing state_dict and state_dict_old
state_dict = model.state_dict().copy()
state_dict_old = torch.load(args.CDGNET_ckpt, map_location='cpu')

# Create a temp dict to update state_dict while avoiding OrderedDict RuntimeError
updated_state_dict = {}

for key, nkey in zip(state_dict_old.keys(), state_dict.keys()):
if key != nkey:
# remove the 'module.' in the 'key'
state_dict[key[7:]] = deepcopy(state_dict_old[key])
# Remove 'module.' from 'key'
updated_state_dict[key[7:]] = deepcopy(state_dict_old[key])
else:
state_dict[key] = deepcopy(state_dict_old[key])
updated_state_dict[key] = deepcopy(state_dict_old[key])

# Update state_dict after the loop
state_dict.update(updated_state_dict)

# Load and set the model's state_dict
model.load_state_dict(state_dict)
model.eval()
model.cuda()
Expand Down