Use trained Network with fewer inputs

username: Filos92
cooked: <p>Hello, everyone,<br>
my question is not directly Pytorch special and of a more general nature, but i hope you can help me anyway.<br>
I would like to learn my network with data we collected in a test mode. (For example: A picture and data A, B, C, D). Now the network is trained and I leave the test mode. In the actual operation, however, only the data A, C and D are available. Do I have to thin it out before or can I replace the Inputs with Zeros? will the accuracy of the system suffer? Is it even possible to use the network? If Yes, How?<br>
The problem is, I can not do without the data of the test operation, because without it my accuracy is not high enough.</p>

username: Pranavan_Theivendira
cooked: <aside class="quote no-group" data-username="Filos92" data-post="1" data-topic="48132">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/f/a3d4f5/48.png" class="avatar"> Filos92:</div>
<blockquote>
<p>I would like to learn my network with data we collected in a test mode. (For example: A picture and data A, B, C, D). Now the network is trained and I leave the test mode. In the actual operation, however, only the data A, C and D are available. Do I have to thin it out before or can I replace the Inputs with Zeros? will the accuracy of the system suffer? Is it even possible to use the network? If Yes, How?</p>
</blockquote>
</aside>
<p>Hi,</p>
<p>In your case, you have missing data in the testing phase. There are scenarios where the missing data can be approximated using ideas based on distance. For example, you can use nearest neighbor to fill the missing data.  Or else, you can fill with the column average. Read the following article, it will give you a good idea to handle the missing data.</p>
<p><a href="https://towardsdatascience.com/how-to-handle-missing-data-8646b18db0d4" class="onebox" target="_blank" rel="noopener nofollow ugc">https://towardsdatascience.com/how-to-handle-missing-data-8646b18db0d4</a></p>
<p>Just replacing the missing values with zeros may affect your accuracy. Analyse the particular column data and use suitable replacement for the missing values properly. To use the network, you need all values A,B,C,D. Hence, you need some approximation. Yes, the accuracy will go down if you do not have a good method to handle missing data.</p>
<p>Thanks</p>

username: Filos92
cooked: <p>Thank you a lot!<br>
hope this will Help <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

username: Filos92
cooked: <p>I have a few problems implementing the suggestions I’ve read through.<br>
My Network has the Form:</p>
<pre><code>def __init__(self):
    super(Hybrid_Net, self).__init__()
    self.conv1 = nn.Conv2d(in_channels=1,out_channels=50, kernel_size=5, stride=1, padding=0)
    self.drop1=nn.Dropout2d(p=0.5)
    self.conv2 = nn.Conv2d(in_channels=50,out_channels=20,kernel_size=5, stride=1,padding=0)
    self.drop2=nn.Dropout2d(p=0.5)
    self.fc1 = nn.Linear(20 * 9 * 9, 200)   # End of Image Net1
    
    self.conv3 = nn.Conv2d(in_channels=1,out_channels=50, kernel_size=5, stride=1, padding=0)
    self.drop3=nn.Dropout2d(p=0.5)
    self.conv4 = nn.Conv2d(in_channels=50,out_channels=20,kernel_size=5, stride=1,padding=0)
    self.drop4=nn.Dropout2d(p=0.5)
    self.fc2 = nn.Linear(20 * 9 * 9, 200)   # End of Image Net2
    
    self.fc3 = nn.Linear(5, 5000)   
    self.fc4 = nn.Linear(5000, 500)
    self.fc5 = nn.Linear(500, 100)   
    self.drop5 =nn.Dropout(p=0.5)
            
    self.fc6 = nn.Linear(400 + 100, 100)
    self.drop6 =nn.Dropout(p=0.5)
    self.fc7 = nn.Linear(100, 2)   # output layer
   
def forward(self, image, data):
    x1 = F.relu(self.conv1(image))
    x1 = self.drop1(x1)
    x1 = F.max_pool2d(x1, 2, 2)
    x1 = F.relu(self.conv2(x1))
    x1 = self.drop2(x1)
    x1 = F.max_pool2d(x1, 2, 2)
    x1 = x1.view(-1, 20 * 9 * 9)
    x1 = F.relu(self.fc1(x1))
    
    x2 = F.relu(self.conv3(image))
    x2 = self.drop3(x2)
    x2 = F.avg_pool2d(x2, 2, 2)
    x2 = F.relu(self.conv4(x2))
    x2 = self.drop4(x2)
    x2 = F.avg_pool2d(x2, 2, 2)
    x2 = x2.view(-1, 20 * 9 * 9)
    x2 = F.relu(self.fc2(x2))
    
    x3 = torch.cat((x1, x2), dim=1)
    
    x4 = F.relu(self.fc3(data))
    x4 = F.relu(self.fc4(x4))
    x4 = F.relu(self.fc5(x4))
    x4 = self.drop5(x4)
    
    x = torch.cat((x3, x4), dim=1)
    x = F.relu(self.fc6(x))
    x = self.drop6(x)
    x = self.fc7(x)
    return x
</code></pre>
<p>I have two kinds of Inputs (Image and Data) and i want to get rid of the Image.<br>
To start a training without the image, I delete the convolutional layers and reduce the nodes in fc5 from 500 to 100. I have read that with</p>
<pre><code>modelB = TheModelBClass(*args, **kwargs)
modelB.load_state_dict(torch.load(PATH), strict=False)
</code></pre>
<p>you can still use the trained network, but I just can’t get it loaded. Do you have any Idea? <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

username: Filos92
cooked: <p>okay, i`ve got it. I filled the empty nodes with Zeros instead of removing them. Lets have a look if this help <img src="https://discuss.pytorch.org/images/emoji/apple/smiley.png?v=9" title=":smiley:" class="emoji" alt=":smiley:"><br>
…some time later…<br>
In a nutshell:<br>
I tried some imputations and an NN which was trained to fill the missing data worked the best for me.</p>