Need advice after training data

username: rizal_alfarizi
cooked: <p>So i have a network for image classification, for now there are just 2 classes, here is my network</p>
<pre><code class="lang-auto">class ActionNet(Module):
    def __init__(self, num_class=4):
        super(ActionNet, self).__init__()
        
        self.cnn_layer = Sequential(
            #conv1
            Conv2d(in_channels=1, out_channels=32, kernel_size=1, bias=False),
            BatchNorm2d(32),
            PReLU(num_parameters=32),
            MaxPool2d(kernel_size=3),
            #conv2
            Conv2d(in_channels=32, out_channels=64, kernel_size=1, bias=False),
            BatchNorm2d(64),
            PReLU(num_parameters=64),
            MaxPool2d(kernel_size=3),
            #flatten
            Flatten(),
            Linear(576, 128),
            BatchNorm1d(128),
            ReLU(inplace=True),
            Dropout(0.5),
            Linear(128, num_class)
        )
    
    def forward(self, x):
        x = self.cnn_layer(x)
        return x
</code></pre>
<p>then i train with 600 images without augmentation , 300 images each class. i split the data to 8:2 train:test. the result is good enough i get 87% accuracy for test data but the training loss and validation loss is far.<br>
i trained data with cross entropy loss function with learning rate 0.001 and 50 epoch training.</p>
<p>here is my example training data<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/2/5207f88c0b8b08df981df1cf285244cbde96787f.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/5207f88c0b8b08df981df1cf285244cbde96787f" title="a01"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/5/2/5207f88c0b8b08df981df1cf285244cbde96787f_2_386x500.jpeg" alt="a01" data-base62-sha1="bHGegAOYft2TVds7L7dk9tRMIXl" width="386" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/5/2/5207f88c0b8b08df981df1cf285244cbde96787f_2_386x500.jpeg, https://discuss.pytorch.org/uploads/default/original/3X/5/2/5207f88c0b8b08df981df1cf285244cbde96787f.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/5/2/5207f88c0b8b08df981df1cf285244cbde96787f.jpeg 2x" data-dominant-color="262626"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">a01</span><span class="informations">556×720 83 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
class: A</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/d/2dff78f82fe53f078070b8f60cd8dce2c9e8e66b.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/2dff78f82fe53f078070b8f60cd8dce2c9e8e66b" title="s06"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/2/d/2dff78f82fe53f078070b8f60cd8dce2c9e8e66b_2_350x500.jpeg" alt="s06" data-base62-sha1="6yUPGbQoDxm1HGdDdizV6cbrZJV" width="350" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/2/d/2dff78f82fe53f078070b8f60cd8dce2c9e8e66b_2_350x500.jpeg, https://discuss.pytorch.org/uploads/default/original/3X/2/d/2dff78f82fe53f078070b8f60cd8dce2c9e8e66b.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/2/d/2dff78f82fe53f078070b8f60cd8dce2c9e8e66b.jpeg 2x" data-dominant-color="3B3B3B"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">s06</span><span class="informations">505×720 80.9 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
class: B</p>
<p>when i try to test with new data like this image (it should be non of those class):<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/3/4/34cb30365eb0c22dfc7792f33803b76dcb95a4f1.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/34cb30365eb0c22dfc7792f33803b76dcb95a4f1" title="ates"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/3/4/34cb30365eb0c22dfc7792f33803b76dcb95a4f1_2_378x500.jpeg" alt="ates" data-base62-sha1="7x29LfbkH97Js9KI7dW36jB67FD" width="378" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/3/4/34cb30365eb0c22dfc7792f33803b76dcb95a4f1_2_378x500.jpeg, https://discuss.pytorch.org/uploads/default/original/3X/3/4/34cb30365eb0c22dfc7792f33803b76dcb95a4f1.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/3/4/34cb30365eb0c22dfc7792f33803b76dcb95a4f1.jpeg 2x" data-dominant-color="747474"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">ates</span><span class="informations">413×546 49 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>the result of output model is<br>
<code>tensor([[1.5626, 0.2562]], device='cuda:0', grad_fn=&lt;AddmmBackward&gt;)</code><br>
which is 1.56 for class A and 0.25 class B, of course the result is class A but it should be non of them.</p>
<p>any advice for this would be appreciate, thank you</p>

username: cskarthik7
cooked: <p>In Image classification,the model predicts high value tensor for most likely class. So there’s no scope for a model to predict nothing as it predicts the most probable class associated to the image. So the model can’t give the result as no class associated to it. Whichever tensor has higher value will be the most probable class.</p>

username: rizal_alfarizi
cooked: <p>any solution? add more class or what?</p>

username: cskarthik7
cooked: <p>You can add 1 more label<br>
For eg :<br>
Label 0 - No class<br>
Label 1 - Class A<br>
Label 2 - Class B</p>

username: rizal_alfarizi
cooked: <p>do i need to add dataset for no class too? or just train with same data</p>

username: cskarthik7
cooked: <p>Yeah you have to add data for no class too</p>