I cant get the deimensions of the input right

baris: <p>I’ m trying to implement a simple classification network where images are of size 33x33</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/6/66b0ee9afa2acac9db8d7af43bca472d8ab7d551.png" data-download-href="https://discuss.pytorch.org/uploads/default/66b0ee9afa2acac9db8d7af43bca472d8ab7d551" title="Screenshot%20from%202019-04-21%2018-06-37"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/6/66b0ee9afa2acac9db8d7af43bca472d8ab7d551_2_690x311.png" alt="Screenshot%20from%202019-04-21%2018-06-37" data-base62-sha1="eErMboRXIM9faDNfDMlnzmcR3YB" width="690" height="311" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/6/66b0ee9afa2acac9db8d7af43bca472d8ab7d551_2_690x311.png, https://discuss.pytorch.org/uploads/default/optimized/2X/6/66b0ee9afa2acac9db8d7af43bca472d8ab7d551_2_1035x466.png 1.5x, https://discuss.pytorch.org/uploads/default/original/2X/6/66b0ee9afa2acac9db8d7af43bca472d8ab7d551.png 2x" data-dominant-color="F0F0E7"><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%20from%202019-04-21%2018-06-37</span><span class="informations">1116×504 32.3 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>However, I’m getting the following error:<br>
RuntimeError: Expected 4-dimensional input for 4-dimensional weight [3, 1, 5, 5], but got 3-dimensional input of size [4, 33, 33] instead</p>
<p>Can someone tell me how to make the inputs match my image? Also why is the input [4,33,33] and not [33,33] ? Is it because I used a batch size of 4?</p>

LeviViana: <aside class="quote no-group" data-username="baris" data-post="1" data-topic="43179">
<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/b/ea666f/48.png" class="avatar"> baris:</div>
<blockquote>
<p>Also why is the input [4,33,33] and not [33,33] ? Is it because I used a batch size of 4?</p>
</blockquote>
</aside>
<p>Yes !</p>
<aside class="quote no-group" data-username="baris" data-post="1" data-topic="43179">
<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/b/ea666f/48.png" class="avatar"> baris:</div>
<blockquote>
<p>RuntimeError: Expected 4-dimensional input for 4-dimensional weight [3, 1, 5, 5], but got 3-dimensional input of size [4, 33, 33] instead</p>
</blockquote>
</aside>
<p>If you are using convnets, then you must explicitly tell how many channels your image has. In your case, I guess you should do something like <code>tensor_training_x = tensor_training_x.unsqueeze(1)</code> to get a tensor of size N x 1 x 33 x 33.</p>
<p>I hope it helps !</p>

baris: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/1/141472ae124b361a8bf73b41d361af9da1f624bf.png" data-download-href="https://discuss.pytorch.org/uploads/default/141472ae124b361a8bf73b41d361af9da1f624bf" title="Screenshot%20from%202019-04-21%2018-08-03"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/1/141472ae124b361a8bf73b41d361af9da1f624bf_2_690x363.png" alt="Screenshot%20from%202019-04-21%2018-08-03" data-base62-sha1="2RDmfUUGgDE89nFGCZvGBF5dvht" width="690" height="363" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/1/141472ae124b361a8bf73b41d361af9da1f624bf_2_690x363.png, https://discuss.pytorch.org/uploads/default/optimized/2X/1/141472ae124b361a8bf73b41d361af9da1f624bf_2_1035x544.png 1.5x, https://discuss.pytorch.org/uploads/default/original/2X/1/141472ae124b361a8bf73b41d361af9da1f624bf.png 2x" data-dominant-color="F3F3F3"><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%20from%202019-04-21%2018-08-03</span><span class="informations">1075×566 46.5 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>

LeviViana: <p>You may get errors from the fact that you flatten your feature maps to pass it to a dense layer. This means that your architecture doesn’t allow arbitrary image sizes as inputs. You should do some debugging to get the dimensions right. For instance, try putting a <code>print(x.size())</code> after your second convolution in your forward method. For it to work you should get a feature map of shape <code>[5, 5, 10]</code>.</p>

baris: <p>Hey thanks for your reply! I had some problems with this website and didn’t see any of your replies when I first asked my question. Also I wasn’t allowed edit my post or post more than one image at a time so I just gave up. This time hopefully it works better.</p>
<p>So I’ll just summarize what I’m trying to do. I have a dataframe that is 23000x1090 . Each row corresponds to a different image. The first line of the row is the label and the rest (1089=33x33) is the pixel values:</p>
<p>                    <a href="https://i.imgur.com/i53PPdL.png?1" target="_blank" class="onebox" rel="nofollow noopener">
            <img src="https://i.imgur.com/i53PPdL.png?1" width="690" height="423">
          </a>

</p>
<p>There are 23 differend classes and each class is made up of 1000 images. The first 1000 images are all class A, second thousand class B etc. My trainset will be created from the first 900 and testset from the last 100:</p>
<p>                    <a href="https://i.imgur.com/fy7X6ld.png?1" target="_blank" class="onebox" rel="nofollow noopener">
            <img src="https://i.imgur.com/fy7X6ld.png?1" width="668" height="500">
          </a>

</p>
<p>I then construct the testset, trainset and the loaders:</p>
<p>                    <a href="https://i.imgur.com/i1zgogO.png?1" target="_blank" class="onebox" rel="nofollow noopener">
            <img src="https://i.imgur.com/i1zgogO.png?1" width="690" height="244">
          </a>

</p>
<p>This is the network:</p>
<p>                    <a href="https://i.imgur.com/bgVN751.png?1" target="_blank" class="onebox" rel="nofollow noopener">
            <img src="https://i.imgur.com/bgVN751.png?1" width="575" height="500">
          </a>

</p>
<p>But when i do this:</p>
<p>                    <a href="https://i.imgur.com/TxKpo9l.png?1" target="_blank" class="onebox" rel="nofollow noopener">
            <img src="https://i.imgur.com/TxKpo9l.png?1" width="690" height="339">
          </a>

</p>
<p>This is the error:</p>
<p>                    <a href="https://i.imgur.com/7fv7FbB.png?1" target="_blank" class="onebox" rel="nofollow noopener">
            <img src="https://i.imgur.com/7fv7FbB.png?1" width="690" height="490">
          </a>

</p>
<p>If I convert the values inside the tensors to Long I get a different error (can post that too if this post works).</p>
<p>Can you tell me what I should do please?</p>