<jupyter_start><jupyter_text>Save the model<jupyter_code>torch.save(full_network.network.state_dict(), '../adapt_classification_net_1.pth')
torch.save(full_network.discriminator.state_dict(), '../adapt_discriminator_net_1.pth')<jupyter_output><empty_output><jupyter_text>Now have a module which will take a list of image paths and compare the segmentation output from domain adapted network and initial network<jupyter_code>base_network = segnet_vj.segnet_domain_adapt(config)
base_network.init_weights(config.MODEL.PRETRAINED)

pretrained_dict = torch.load('../hrnet_w48_cityscapes_cls19_1024x2048_ohem_trainvalset.pth')

model_dict = base_network.state_dict()
pretrained_dict = {k[6:]: v for k, v in pretrained_dict.items()
                    if k[6:] in model_dict.keys()}
model_dict.update(pretrained_dict)

base_network.load_state_dict(model_dict)

adapted_network = full_network.network


test_device = 'cuda:0'
base_network.to(test_device)
adapted_network.to(test_device)

base_network.eval()
adapted_network.eval()
print("Networks ready")
import matplotlib.pyplot as plt

img = img_loader.get_images(batch_size=1)
img = img.to(test_device)

op1 = base_network(img)
op2 = adapted_network(img)

fig_img1 = op1.detach().cpu().numpy().squeeze().argmax(axis=0)
fig_img2 = op2.detach().cpu().numpy().squeeze().argmax(axis=0)

# Ensure the color range is always same
fig_img1[0,0],fig_img1[0,1] = 0,18
fig_img2[0,0],fig_img2[0,1] = 0,18

img_trnsfm = transforms.ToPILImage()

plt.figure(figsize=(15,10))
plt.subplot(1,3,1)
plt.imshow(img_trnsfm(img.detach().cpu()[0]))
plt.title("Actual Image")

plt.subplot(1,3,2)
plt.imshow(fig_img1)
plt.title("Base network")

plt.subplot(1,3,3)
plt.imshow(fig_img2)
plt.title("Adapted network")
plt.show()
# To free memory
del op1, op2, base_network<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13696369636963696, 'fraction_numerical': 0.034103410341034104, 'mean_word_length': 7.230769230769231, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '497574', 'license': 'MIT', 'n_tokens_mistral': 742, 'n_tokens_neox': 710, 'n_words': 109, 'path': 'tools/train_vj.ipynb', 'repo_name': 'v1viswan/Domain_adaptation_in_HRNet', 'size': '1818'}