Input Single Image to Pytorch CNN Model

username: numan741
cooked: <p>I have implemented the model for CIFAR for dateset having 32x32 images size. While testing this model in batch gives correct prediction.</p>
<p>But while giving single image, it is given the following error:<br>
<strong>ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 512, 1, 1])</strong><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/3/a/3ad00fb64da137dee7a146c25529030542b303b3.png" data-download-href="https://discuss.pytorch.org/uploads/default/3ad00fb64da137dee7a146c25529030542b303b3" title="Screenshot (109)"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/3/a/3ad00fb64da137dee7a146c25529030542b303b3_2_690x387.png" alt="Screenshot (109)" data-base62-sha1="8ohsGIPEJYNXglHWdPZxqONxQtl" width="690" height="387" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/3/a/3ad00fb64da137dee7a146c25529030542b303b3_2_690x387.png, https://discuss.pytorch.org/uploads/default/optimized/3X/3/a/3ad00fb64da137dee7a146c25529030542b303b3_2_1035x580.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/3/a/3ad00fb64da137dee7a146c25529030542b303b3.png 2x" data-dominant-color="F3F3F5"><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">Screenshot (109)</span><span class="informations">1366×768 133 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> ![Screenshot (110)|690x387]</p>

username: ptrblck
cooked: <p>This error is raised by batchnorm layers, if the batch statistic cannot be calculated from a single input value.<br>
If you are testing the model, you should call <code>model.eval()</code>, which will put all modules in evaluation mode, such that e.g. the batchnorm layers will apply their running estimates instead of calculating the stats from the current input batch.<br>
Thus you could use the model even for single input images.</p>

username: numan741
cooked: <p>Thanks I solved the previous error with your help. However,I am facing a new error now =&gt;<strong>Dimension out of range (expected to be in range of [-1, 0], but got 1)</strong><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/9/4/94d568a1e65d4fe18f66ab75497ec9cb1a96f402.png" data-download-href="https://discuss.pytorch.org/uploads/default/94d568a1e65d4fe18f66ab75497ec9cb1a96f402" title="Screenshot (111)"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/9/4/94d568a1e65d4fe18f66ab75497ec9cb1a96f402_2_690x387.png" alt="Screenshot (111)" data-base62-sha1="leDThHmBcjZlSV5hDzxOom8aghQ" width="690" height="387" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/9/4/94d568a1e65d4fe18f66ab75497ec9cb1a96f402_2_690x387.png, https://discuss.pytorch.org/uploads/default/optimized/3X/9/4/94d568a1e65d4fe18f66ab75497ec9cb1a96f402_2_1035x580.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/9/4/94d568a1e65d4fe18f66ab75497ec9cb1a96f402.png 2x" data-dominant-color="F1F1F2"><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">Screenshot (111)</span><span class="informations">1366×768 87.6 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>

username: ptrblck
cooked: <p><code>output</code> seems to have a single dimension, which seems to be wrong.<br>
Did you delete the batch dimension?<br>
If not, could you <code>print(output.shape)</code> in your code before trying to compute the predictions?<br>
For a multi-class classification, the output should have the shape <code>[batch_size, nb_classes]</code>.</p>
<p>Check if you code for all <code>squeeze()</code> calls, which might have removed the batch dimension of 1.</p>