Same code behave diffrently

username: Makyavelci_7
cooked: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/d/dd5f7b6b3ca3ae5b53b96810b07865428d280624.png" data-download-href="https://discuss.pytorch.org/uploads/default/dd5f7b6b3ca3ae5b53b96810b07865428d280624" title="1111111"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/d/d/dd5f7b6b3ca3ae5b53b96810b07865428d280624_2_690x203.png" alt="1111111" data-base62-sha1="vAm5BDoBdmwhJGmOYxPRZLTg4du" width="690" height="203" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/d/d/dd5f7b6b3ca3ae5b53b96810b07865428d280624_2_690x203.png, https://discuss.pytorch.org/uploads/default/original/3X/d/d/dd5f7b6b3ca3ae5b53b96810b07865428d280624.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/d/d/dd5f7b6b3ca3ae5b53b96810b07865428d280624.png 2x" data-dominant-color="517087"><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">1111111</span><span class="informations">994×293 113 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>Hey guys, i am using this repo <a href="https://github.com/hamdaan19/UNet-Multiclass" class="inline-onebox" rel="noopener nofollow ugc">GitHub - hamdaan19/UNet-Multiclass: This repository contains code used to train U-Net on a multi-class segmentation dataset.</a>.</p>
<p>Evaluate function in this repo producing the second image, which is what i want.</p>
<p>But i need a real time function so i wrote this:</p>
<pre><code class="lang-auto">model = UNET(in_channels=3, classes=19)
model.state_dict(destination=torch.load("D:/ide/Saves/RedHorse/env/HorseNet/NN/Static/NNmodels/2_Segmentation_Model_Segmentation_model.pth", map_location="cpu"))
model.eval()

IMAGE_HEIGHT, IMAGE_WIDTH = 300, 600

x = cv2.imread("D:/ide/Saves/RedHorse/env/HorseNet/NN/extracted_data/Cityspaces.zip/images/val/frankfurt/frankfurt_000000_015389_leftImg8bit.png")

x = cv2.resize(x, (IMAGE_WIDTH,IMAGE_HEIGHT))
x = cv2.cvtColor(x, cv2.COLOR_BGR2RGB)

x = torch.from_numpy(x).float()
x = x.permute(2,0,1)
x = x.unsqueeze(0)

with torch.no_grad():
    y = model(x)

y = torch.nn.functional.softmax(y, dim=1)
y = torch.argmax(y, dim=1).float()

y.apply_(lambda x: t2l[x].id)

y = y.numpy()

y = y.transpose(1,2,0)

plt.imshow(y)
plt.show()

cv2.imwrite("D:/Downloads/UNet-Multiclass/saved_images/.png",y)

</code></pre>
<p>and output of this code is first image. I really don’t understand is this a problem or not. If its not what should i do to get the outputs like second one?</p>

username: ptrblck
cooked: <p>I guess you might be missing some preprocessing steps such as normalizing the image and I would generally try to compare the intermediate outputs between the original repository output and your “real time” code.</p>

username: Makyavelci_7
cooked: <p>Thank you for yours answer but i already try that. Before this implementation i basically copy all the code that evaluate function in the repo. The only differences, in the evaluate function its using data loader, but i am using cv2.imread. Before you ask, yes i did check data loaders transforms to. I just don’t understand whats the issue.</p>