RuntimeError: output with shape doesn’t match the broadcast shape

username: jim_gitonga
cooked: <p>how should i go on this type of error<br>
NB AM USING A CPU</p>
<pre><code class="lang-auto">transform = transforms.Compose([
 transforms.Resize(256),
 transforms.CenterCrop(224),
 transforms.ToTensor()
])

transform_normalize = transforms.Normalize(
     mean=[0.485, 0.456, 0.406],
     std=[0.229, 0.224, 0.225]
 )
img = Image.open('image.jpeg')

transformed_img = transform(img)

input = transform_normalize(transformed_img)
input = input.unsqueeze(0)
</code></pre>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/c/dc5ed65268aa94d457414374a2071771d1885c8e.png" data-download-href="https://discuss.pytorch.org/uploads/default/dc5ed65268aa94d457414374a2071771d1885c8e" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/d/c/dc5ed65268aa94d457414374a2071771d1885c8e.png" alt="image" data-base62-sha1="vruekVNM7ulNGcH9jkghXLc5VQq" width="690" height="401" data-dominant-color="EFF2EE"><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">image</span><span class="informations">731×425 19.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>

username: vainaijr
cooked: <p>I think if you use only one value in mean, one value in std, then it will start working, i.e.,</p>
<pre><code class="lang-auto">transform_normalize = transforms.Normalize(
     mean=[0.485],
     std=[0.229]
 )
</code></pre>

username: jim_gitonga
cooked: <p>after i use this an error is raised</p>
<pre><code class="lang-auto">transform_normalize = transforms.Normalize(
     mean=[0.485],
     std=[0.229]
 )
</code></pre>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/0/d/0d96fe9aeafdf59f0d8eb5bd5768a61df2e1f607.png" data-download-href="https://discuss.pytorch.org/uploads/default/0d96fe9aeafdf59f0d8eb5bd5768a61df2e1f607" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/0/d/0d96fe9aeafdf59f0d8eb5bd5768a61df2e1f607.png" alt="image" data-base62-sha1="1WdI6OukjfDNDjYq4HBXgyIOt8P" width="690" height="383" data-dominant-color="EFF1EE"><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">image</span><span class="informations">708×393 19 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: vainaijr
cooked: <p>maybe change number of in_channels to 1 in nn.Conv2d, i.e.,</p>
<pre><code class="lang-auto">nn.Conv2d(1, out_channels, kernel_size)
</code></pre>

username: jim_gitonga
cooked: <p>how do i do that.please show</p>

username: jim_gitonga
cooked: <p>this has solved my problem i just grayed the image</p>
<pre><code class="lang-auto">import cv2
import numpy as np
img = cv2.imread('jim.jpeg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img2 = np.zeros_like(img)
img2[:,:,0] = gray
img2[:,:,1] = gray
img2[:,:,2] = gray
cv2.imwrite('jim.jpeg', img2)
</code></pre>