Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image data distribution #5

Open
SeungyounShin opened this issue May 24, 2020 · 1 comment
Open

image data distribution #5

SeungyounShin opened this issue May 24, 2020 · 1 comment

Comments

@SeungyounShin
Copy link

SeungyounShin commented May 24, 2020

Thanks for your sharing codes

I am trying to predict a low resolution image with pretrained ERFNet. Sadly, It doesn't work.
I think my preprocessing of image data is different from yours.
I would like to know mean/std normalization is correct.

Code I used is below.

import torch
import cv2
import utils.transforms as tf
import numpy as np
import models
import numpy as np
import matplotlib.pyplot as plt

PATH = '#/erfnet.pth'
test_image = "./test_images/test1.png"


#model load
model = models.ERFNet(37, partial_bn=False)
ckpt = torch.load(PATH)
torch.nn.Module.load_state_dict(model, ckpt['state_dict'], strict=False)
model = model.cuda()
model.eval()

#load image
img = plt.imread(test_image)[:,:,:3]
orgh,orgw = img.shape[0], img.shape[1]
zeros = np.zeros((448, 720,3))
xoffset = 2
yoffset = 10
zeros[xoffset:orgh+xoffset,yoffset:orgw+yoffset,:] = img
img = zeros
img = cv2.resize(img, None, fx=2, fy=2, interpolation=cv2.INTER_CUBIC)
plt.imshow(img)
print("image shape : ", img.shape)
#h,w = img.shape[0], img.shape[1]

#image preprocess
img *= 255.
img -= np.array([103.939, 116.779, 123.68])
img /= np.array([1.,1.,1.])
img /= 255.

h,w = img.shape[0], img.shape[1]

image = torch.from_numpy(img).permute(2, 0, 1).contiguous().float().view(1,3,h,w)
image = image.cuda()

#infer
out = model(image)
index = torch.max(out, 1)[1].squeeze().cpu().numpy()
plt.imshow(index, alpha= 0.5)

plt.show()
@cardwing
Copy link
Owner

Is the low-resolution image from ApolloScape? If yes, you may need to finetune the model. If no, you have to retrain the model from scratch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants