Row 77593
Content Data
This page contains data entry 77593 from the Axioma AXP content repository. The structured data below represents the complete record for this entry.
I made a 2 step model with a u net and a gan as 2 consecutive steps.
the output that i get from the u net , i apply thresholding to get a mask , and pass the output and mask to the gan for inpainting. i want to make the threshold also learnable . i kept the threshold as nn.Parameter() , and also set required\_grad = True , but then when I checkked while training the model , the parameter value is not getting updated at all.
The same init value of 0.5 is only coming.
class Combined\_Model(nn.Module):
def \_\_init\_\_(self , options):
super(Combined\_Model, self).\_\_init\_\_()
​
self.pretrained\_state\_dict = torch.load(os.path.join(options.pretrained, '[G0000000.pt](https://G0000000.pt)'), map\_location=torch.device('cuda'))
self.unet = UNet().to(options.device)
​
​
if options.with\_prompts:
self.inpainter = Prompted\_InpaintGenerator(options)
self.org\_gan = InpaintGenerator(options)
\#self.inpainter.load\_state\_dict(load\_pretrained\_weights(self.org\_gan, self.pretrained\_state\_dict), strict=False)
self.inpainter.load\_state\_dict(load\_pretrained\_weights(self.org\_gan , self.inpainter) , strict=True)
else:
self.inpainter = InpaintGenerator(options)
self.inpainter.load\_state\_dict(torch.load(os.path.join(options.pretrained, '[G0000000.pt](https://G0000000.pt)'), map\_location=options.device), strict=False)
​
self.models = \[self.unet, self.inpainter\]
​
self.learnable\_threshold = nn.Parameter(torch.tensor(0.5), requires\_grad=True)
​
def forward(self , x):
​
unet\_output = self.unet(x)
unet\_output\_gray = tensor\_to\_cv2\_gray(unet\_output)
flary\_img\_gray = tensor\_to\_cv2\_gray(x)
print(self.learnable\_threshold)
difference = (torch.from\_numpy(flary\_img\_gray) - torch.from\_numpy(unet\_output\_gray))
\#difference\_tensor = torch.tensor(difference, dtype=torch.float32).to(options.device)
difference\_tensor = difference.clone().to(options.device)
binary\_mask = torch.where(difference\_tensor > self.learnable\_threshold, torch.tensor(1.0).to(options.device), torch.tensor(0.0).to(options.device))
binary\_mask = binary\_mask.unsqueeze(1)
​
inpainted\_output = self.inpainter(unet\_output , binary\_mask)
​
return inpainted\_output
​
| Field | Value |
|---|---|
| text | I made a 2 step model with a u net and a gan as 2 consecutive steps. the output that i get from the u net , i apply thresholding to get a mask , and pass the output and mask to the gan for inpainting. i want to make the threshold also learnable . i kept the threshold as nn.Parameter() , and also set required\_grad = True , but then when I checkked while training the model , the parameter value is not getting updated at all. The same init value of 0.5 is only coming. class Combined\_Mod… |
| label | r/pytorch |
| dataType | post |
| communityName | r/pytorch |
| datetime | 2024-05-24 |
| username_encoded | Z0FBQUFBQm5Lak1qSk1ycnA3YjJRNWRQODFqT2xib1RzX0N4Q1lRejU3MnVKZGN1d1JMb2RfMHhaa200WkR1WXY2OFUxUFhjNlg3OWVPdGM1bWxCaGZXVHpmRzdDNGhjOS1TS1h6aDhONUYxUFBsZnRXQVNPalU9 |
| url_encoded | Z0FBQUFBQm5Lak8waVFLaVl1UFc3M2NURm9sc2RaY3dZUWc3ME1wRlR1LTFZdHh6NEd2RzY4dDF5amp1WFAtMlRQOEtFdndRbHphMXZMUWg1Qld6b1ZHWWlqWl9OXzBfTXpSc1ZpRE9WckV2OGxJdGlFTHgzc2FvUi10WmxHSkZ6TDlzRldEbUNwTVotSm5RdTdwT2l2Tl9XNEpNRTN2U3FTRGNBX3I3ZzRWaUtUOS0xQWR0N0Frb0JRWGNva2tOb3BnUHF0bUhEeHBw |
Raw Record
{
"text": " \n\nI made a 2 step model with a u net and a gan as 2 consecutive steps.\n\nthe output that i get from the u net , i apply thresholding to get a mask , and pass the output and mask to the gan for inpainting. \ni want to make the threshold also learnable . \ni kept the threshold as nn.Parameter() , and also set required\\_grad = True , but then when I checkked while training the model , the parameter value is not getting updated at all.\n\nThe same init value of 0.5 is only coming. \n\n\nclass Combined\\_Model(nn.Module): \n\n\ndef \\_\\_init\\_\\_(self , options):\n\nsuper(Combined\\_Model, self).\\_\\_init\\_\\_()\n\n​\n\nself.pretrained\\_state\\_dict = torch.load(os.path.join(options.pretrained, '[G0000000.pt](https://G0000000.pt)'), map\\_location=torch.device('cuda'))\n\nself.unet = UNet().to(options.device)\n\n​\n\n​\n\nif options.with\\_prompts:\n\nself.inpainter = Prompted\\_InpaintGenerator(options)\n\nself.org\\_gan = InpaintGenerator(options)\n\n\\#self.inpainter.load\\_state\\_dict(load\\_pretrained\\_weights(self.org\\_gan, self.pretrained\\_state\\_dict), strict=False)\n\nself.inpainter.load\\_state\\_dict(load\\_pretrained\\_weights(self.org\\_gan , self.inpainter) , strict=True)\n\nelse:\n\nself.inpainter = InpaintGenerator(options)\n\nself.inpainter.load\\_state\\_dict(torch.load(os.path.join(options.pretrained, '[G0000000.pt](https://G0000000.pt)'), map\\_location=options.device), strict=False)\n\n​\n\nself.models = \\[self.unet, self.inpainter\\]\n\n​\n\nself.learnable\\_threshold = nn.Parameter(torch.tensor(0.5), requires\\_grad=True)\n\n​\n\ndef forward(self , x):\n\n​\n\nunet\\_output = self.unet(x)\n\nunet\\_output\\_gray = tensor\\_to\\_cv2\\_gray(unet\\_output)\n\nflary\\_img\\_gray = tensor\\_to\\_cv2\\_gray(x)\n\nprint(self.learnable\\_threshold)\n\ndifference = (torch.from\\_numpy(flary\\_img\\_gray) - torch.from\\_numpy(unet\\_output\\_gray))\n\n\\#difference\\_tensor = torch.tensor(difference, dtype=torch.float32).to(options.device)\n\ndifference\\_tensor = difference.clone().to(options.device)\n\nbinary\\_mask = torch.where(difference\\_tensor > self.learnable\\_threshold, torch.tensor(1.0).to(options.device), torch.tensor(0.0).to(options.device))\n\nbinary\\_mask = binary\\_mask.unsqueeze(1)\n\n​\n\ninpainted\\_output = self.inpainter(unet\\_output , binary\\_mask)\n\n​\n\nreturn inpainted\\_output\n\n​",
"label": "r/pytorch",
"dataType": "post",
"communityName": "r/pytorch",
"datetime": "2024-05-24",
"username_encoded": "Z0FBQUFBQm5Lak1qSk1ycnA3YjJRNWRQODFqT2xib1RzX0N4Q1lRejU3MnVKZGN1d1JMb2RfMHhaa200WkR1WXY2OFUxUFhjNlg3OWVPdGM1bWxCaGZXVHpmRzdDNGhjOS1TS1h6aDhONUYxUFBsZnRXQVNPalU9",
"url_encoded": "Z0FBQUFBQm5Lak8waVFLaVl1UFc3M2NURm9sc2RaY3dZUWc3ME1wRlR1LTFZdHh6NEd2RzY4dDF5amp1WFAtMlRQOEtFdndRbHphMXZMUWg1Qld6b1ZHWWlqWl9OXzBfTXpSc1ZpRE9WckV2OGxJdGlFTHgzc2FvUi10WmxHSkZ6TDlzRldEbUNwTVotSm5RdTdwT2l2Tl9XNEpNRTN2U3FTRGNBX3I3ZzRWaUtUOS0xQWR0N0Frb0JRWGNva2tOb3BnUHF0bUhEeHBw"
}
Entry Information
- Entry ID: 77593
- Repository: Axioma AXP
- Dataset: arrmlet/reddit_dataset_36
- Total Entries: 100,000