Use trained Network with fewer inputs

Hello, everyone,
my question is not directly Pytorch special and of a more general nature, but i hope you can help me anyway.
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?
The problem is, I can not do without the data of the test operation, because without it my accuracy is not high enough.

Hi,

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.

https://towardsdatascience.com/how-to-handle-missing-data-8646b18db0d4

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.

Thanks

1 Like

Thank you a lot!
hope this will Help :slight_smile:

I have a few problems implementing the suggestions I’ve read through.
My Network has the Form:

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

I have two kinds of Inputs (Image and Data) and i want to get rid of the Image.
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

modelB = TheModelBClass(*args, **kwargs)
modelB.load_state_dict(torch.load(PATH), strict=False)

you can still use the trained network, but I just can’t get it loaded. Do you have any Idea? :slight_smile:

okay, i`ve got it. I filled the empty nodes with Zeros instead of removing them. Lets have a look if this help :smiley:
…some time later…
In a nutshell:
I tried some imputations and an NN which was trained to fill the missing data worked the best for me.