Hello Sai_tharun,
I need to have two outputs from a single input, In the above case classifier[6] output is fed as input to classifier[7], i don’t want that to happen , i want classifier[6] to give 10 outputs and classifier[7] to give 10 outputs, how can i write a custom function to achieve that ?
here are the code snipets.
#adding new layer
num_features = model_vowel.classifier[6].in_features
features = list(model_vowel.classifier.children())[:-1]
features.extend([nn.Linear(num_features, 10),nn.Linear(num_features, 10)])
model_vowel.classifier = nn.Sequential(*features)
model_vowel.to(device)
loss_fn = nn.CrossEntropyLoss()
opt = optim.SGD(model.parameters(),lr=0.1,momentum=0.9)
for i, data in enumerate(train_loader):
images, labels = data
images = images.to(device)
vowel_labels = torch.max(labels[:,0],1)[-1]
consonant_labels = torch.max(labels[:,1],1)[-1]
vowel_labels = vowel_labels.to(device)
consonant_labels = consonant_labels.to(device)
opt.zero_grad()
ouput = model_vowel(images)
How do i write a custom function to get two outputs, i tried this code,
class vgg_net(nn.Module):
def init(self,original_model):
super().init()
self.original_model = original_model
self.features = nn.Sequential(*list(self.original_model.children())[:-1])
def forward(self,x):
x = self.features(x)
x = x.view(x.size(0),-1)
vowel = what should i write here?
consonant = what should i write here?
return vowel,consonant