Possible local minima problem with my model

cooler_mann: <p>Hi, I am currently training a CNN to binarily classify images of polar bears. After only a few epochs it classifies about 80% of my positive examples correctly, even in my validation set. However, if I show the model a blank white image after training, it outputs with high certainty that the image belongs in the polar bear class, which leads me to the conclusion, that it possibly predicts the output based on the amount of white pixels in the input image. I thought about adding a lot of white images as negative examples to my data, but im not sure if this would be the right approach.<br>
My model looks like this:<br>
class Net(torch.nn.Module):<br>
def <strong>init</strong>(self):<br>
super(Net,self).<strong>init</strong>()<br>
self.conv1=nn.Conv2d(3,6,3,1)<br>
self.conv2=nn.Conv2d(6,16,3,1)<br>
self.dropout1=nn.Dropout2d(0.4)<br>
self.dropout2=nn.Dropout2d(0.4)<br>
self.fc1=nn.Linear(46656,64)<br>
self.fc2=nn.Linear(64,1)<br>
<span class="hashtag">#self</span>.fc3=nn.Linear(2000,128)<br>
<span class="hashtag">#self</span>.fc4=nn.Linear(128,1)<br>
def forward(self,x):<br>
CELU=torch.nn.CELU()<br>
Tanh=torch.nn.Tanh()<br>
x = self.conv1(x)<br>
x = self.dropout1(x)<br>
x = CELU(x)<br>
x=F.max_pool2d(x,2)<br>
x = self.conv2(x)<br>
x = CELU(x)<br>
x = F.max_pool2d(x, 2)<br>
x = torch.flatten(x, 1)<br>
x = CELU(x)<br>
x = self.fc1(x)<br>
x = CELU(x)<br>
x = self.dropout2(x)<br>
x = self.fc2(x)<br>
output = torch.sigmoid(x)<br>
return output</p>
<pre><code>            return(x)</code></pre>

ptrblck: <p>Your idea sounds valid. If you suspect the model is focusing on the “wrong” feature, you could add negative samples as e.g. just pictures of snow without any bears.<br>
Also, you could use e.g. <code>Captum</code> to apply some visualization techniques, which might be helpful to figure out what the strongest features in the inputs are.</p>

cooler_mann: <p>I’ve experimented around with captum a bit and generally speaking, my verdict was confirmed, as this heatmap of a completely blank image shows.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/1/1/11615558c53d41e26f390369200e5d30b38bf516.png" data-download-href="https://discuss.pytorch.org/uploads/default/11615558c53d41e26f390369200e5d30b38bf516" title="Figure_1"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/1/1/11615558c53d41e26f390369200e5d30b38bf516_2_500x500.png" alt="Figure_1" data-base62-sha1="2tKEtq4swUx10cFMzXWZNyX7aRw" width="500" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/1/1/11615558c53d41e26f390369200e5d30b38bf516_2_500x500.png, https://discuss.pytorch.org/uploads/default/original/3X/1/1/11615558c53d41e26f390369200e5d30b38bf516.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/1/1/11615558c53d41e26f390369200e5d30b38bf516.png 2x" data-dominant-color="B3D0E5"><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">Figure_1</span><span class="informations">600×600 216 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>
However, I am quite confused, because in some input Images, it seems to recognise the polar bear in the image, but just seemingly neglects it, as this heatmap shows:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/c/4/c4696c2ba92334bc8bd1f49ed4007f99d787e914.png" data-download-href="https://discuss.pytorch.org/uploads/default/c4696c2ba92334bc8bd1f49ed4007f99d787e914" title="Figure_10692(2)"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/c/4/c4696c2ba92334bc8bd1f49ed4007f99d787e914_2_500x500.png" alt="Figure_10692(2)" data-base62-sha1="s1xrXuBk3PG7o7fCDQ3iK00rvVy" width="500" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/c/4/c4696c2ba92334bc8bd1f49ed4007f99d787e914_2_500x500.png, https://discuss.pytorch.org/uploads/default/original/3X/c/4/c4696c2ba92334bc8bd1f49ed4007f99d787e914.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/c/4/c4696c2ba92334bc8bd1f49ed4007f99d787e914.png 2x" data-dominant-color="D4DED2"><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">Figure_10692(2)</span><span class="informations">600×600 176 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> <div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/4/c/4c0da703905d0769da67893b89849794d590fc0c.png" data-download-href="https://discuss.pytorch.org/uploads/default/4c0da703905d0769da67893b89849794d590fc0c" title="Figure_10692"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/4/c/4c0da703905d0769da67893b89849794d590fc0c_2_500x500.png" alt="Figure_10692" data-base62-sha1="aQNxlCosViZBgOfLaBLWs6M5L9a" width="500" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/4/c/4c0da703905d0769da67893b89849794d590fc0c_2_500x500.png, https://discuss.pytorch.org/uploads/default/original/3X/4/c/4c0da703905d0769da67893b89849794d590fc0c.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/4/c/4c0da703905d0769da67893b89849794d590fc0c.png 2x" data-dominant-color="C6DCEC"><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">Figure_10692</span><span class="informations">600×600 205 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>
This seems quite contraintuitive to me, or am I misinterpreting something here?</p>

ptrblck: <p>Could you explain what you’ve visualized in these images?<br>
Are more positive values corresponding to “more important” areas of the input image?<br>
Is the first (snow only) image also classified as a bear? If so, could you post another figure showing a negative sample (no bear and classified correctly)?</p>