Beispiel #1
0
def seg_pth_to_my_pth():
    # from collections import OrderedDict
    # new_state_dict = OrderedDict()
    # state_dict = torch.load('./drn_d_38_cityscapes.pth')
    # for k, v in state_dict.items():
    #     name = k.replace("base.", "layer")
    #     name = name.replace("seg", "fc")
    #     if 'up' in name:
    #         print("pass a up")
    #         continue
    #     print(k, name)
    #     new_state_dict[name] = v
    # torch.save(new_state_dict, './new_drn_d_38_seg_pretrain.pth')
    import drn, models
    model = drn.drn_d_38()
    model.fc = None
    for k, v in model.state_dict().items():
        print("org model key:", k)

    model.load_state_dict(torch.load('./new_drn_d_38_seg_pretrain.pth'))
    img = torch.randn((1, 3, 512, 512))
    model.fc = models.conv1x1(512, 6)
    out = model(img)
    print(model)
    print(out.shape)
Beispiel #2
0
    def _build_network_head(self, outs):
        self.subnets = nn.ModuleList()
        for _ in range(self.num_subnets):
            # create the subnets
            self.subnets.append(SubUNet(self.subnet_config))

        if self.num_subnets == 2:
            # In case that we only have two subnets we produce only one output
            # with sigmoid, the second probability is implicit in this case
            count = self.num_subnets - 1
        else:
            count = self.num_subnets

        # create the probability weights, this can be seen as p(z|x), i.e. the probability
        # of a decision given the input image. To obtain a weighted "average" of the
        # predictions of the subnets, we multiply this weight to their output.
        self.weight_probabilities = conv1x1(outs, count)
Beispiel #3
0
 def _build_network_head(self, outs):
     self.subnets = nn.ModuleList()
     for _ in range(self.num_subnets):
         # We create each requested subnet
         self.subnets.append(SubUNet(self.subnet_config))
     self.final_conv = conv1x1(outs, self.num_subnets)
 def _build_network_head(self, outs):
     self.network_head = conv1x1(outs, self.in_channels)
 def _build_network_head(self, outs):
     # Mean and std as for each input channel
     self.conv_final = conv1x1(outs, self.in_channels * 2)