How to modify Pretrained Torchvision Models in PyTorch to return two outputs for multilabel Image Classification
Input: Set of ten "Vowels", set of ten "Consonents", Image dataset where in every image both, one vowel and one consonent, are written.

Task: To identify the vowel and consonent from given image.

Approach: First apply CNN hidden layers on image, then apply two parallel fully connected/dense layers where one will classify vowel in image and other will classify consonent in image.

Problem: I am taking Pretrained Model like VGG or GoogleNet. How to modify that pretrained model to apply two parallel dense layers and return two outputs.

I have tried two different models but my query is can we modify pretrained model for this task.

Right now my model is having only one "fc" layer. I have modified number of neurons in final "fc" layer, like this

final_in_features = googlenet.fc.in_features

googlenet.fc = nn.Linear(final_in_features, 10)


But I need to add one more fc layer so that both "fc" layers are connecting with hidden layers parallel.

Right now model is returning only one output.

outputs1 = googlenet(inputs)


Task is to return two outputs from both "fc" layers, so that it should be look like this 

outputs1, outputs2 = googlenet(inputs)


Here is the source for a Linear Layer in Pytorch : 

class Linear(Module):
    r"""Applies a linear transformation to the incoming data: :math:`y = xA^T + b`

    Args:
        in_features: size of each input sample
        out_features: size of each output sample
        bias: If set to ``False``, the layer will not learn an additive bias.
            Default: ``True``

    Shape:
        - Input: :math:`(N, *, H_{in})` where :math:`*` means any number of
          additional dimensions and :math:`H_{in} = \text{in\_features}`
        - Output: :math:`(N, *, H_{out})` where all but the last dimension
          are the same shape as the input and :math:`H_{out} = \text{out\_features}`.

    Attributes:
        weight: the learnable weights of the module of shape
            :math:`(\text{out\_features}, \text{in\_features})`. The values are
            initialized from :math:`\mathcal{U}(-\sqrt{k}, \sqrt{k})`, where
            :math:`k = \frac{1}{\text{in\_features}}`
        bias:   the learnable bias of the module of shape :math:`(\text{out\_features})`.
                If :attr:`bias` is ``True``, the values are initialized from
                :math:`\mathcal{U}(-\sqrt{k}, \sqrt{k})` where
                :math:`k = \frac{1}{\text{in\_features}}`

    Examples::

        &gt;&gt;&gt; m = nn.Linear(20, 30)
        &gt;&gt;&gt; input = torch.randn(128, 20)
        &gt;&gt;&gt; output = m(input)
        &gt;&gt;&gt; print(output.size())
        torch.Size([128, 30])
    """
    __constants__ = ['bias']

    def __init__(self, in_features, out_features, bias=True):
        super(Linear, self).__init__()
        self.in_features = in_features
        self.out_features = out_features
        self.weight = Parameter(torch.Tensor(out_features, in_features))
        if bias:
            self.bias = Parameter(torch.Tensor(out_features))
        else:
            self.register_parameter('bias', None)
        self.reset_parameters()

    def reset_parameters(self):
        init.kaiming_uniform_(self.weight, a=math.sqrt(5))
        if self.bias is not None:
            fan_in, _ = init._calculate_fan_in_and_fan_out(self.weight)
            bound = 1 / math.sqrt(fan_in)
            init.uniform_(self.bias, -bound, bound)

    @weak_script_method
    def forward(self, input):
        return F.linear(input, self.weight, self.bias)

    def extra_repr(self):
        return 'in_features={}, out_features={}, bias={}'.format(
            self.in_features, self.out_features, self.bias is not None
        )


You can create a class DoubleLinear like this : 

class DoubleLinear(Module):
    def __init__(self, Linear1, Linear2):
        self.Linear1 = Linear1
        self.Linear2 = Linear2
    @weak_script_method
    def forward(self, input):
        return self.Linear1(input), self.Linear2(input)


Then, create your two Linear layers : 

Linear_vow = nn.Linear(final_in_features, 10)
Linear_con = nn.Linear(final_in_features, 10)
final_layer = DoubleLinear(Linear_vow, Linear_con)


now outputs1, outputs2 = final_layer(inputs) will work as expected.
