I need to create a new model, by loading selected vgg filters.
I am using the following function inside VGG(nn.Module) class (Defined in torchvision example)
Here weights, bias are 2 dictionaries having selected filters from vgg
def _initialize_weights(self):
v = list(self.features)
for i in range(len(v)):
if i in [0,2,5,7,14,17,10,12,24,26,19,21,28]: #left last layer 28. Load original weights
if isinstance(i,nn.Conv2d):
w = self.weights['layer_'+str(i)]
w = torch.nn.parameter.Parameter(torch.from_numpy(np.array(w)))
b = self.bias['layer_'+str(i)]
b = torch.nn.parameter.Parameter(torch.from_numpy(np.array(b)))
self.features[i].weight = w
self.features[i].bias = b
But I am getting weird results. The output class obtained for the same image, changes everytime code is run.