DeepLabV3Plus-Pytorch icon indicating copy to clipboard operation
DeepLabV3Plus-Pytorch copied to clipboard

关于训练结果

Open KOOKOKOK opened this issue 5 years ago • 7 comments

我使用cityscapes数据集训练,PR值都还好,但是看了一下results文件夹下产生的pre_img发现语义分割都画乱了,之后我自己又下载了一下你的模型,看一下图片检测结果,发现也不行。我不知道是我根据网络输出结果把语义分割画到原图的过程错误还是有忽略其他什么问题,希望您可以给一个将神经网络结果画回原图的示例代码。谢谢!

"

import cv2 import numpy as np

from network import * from PIL import Image from torchvision.transforms.transforms import * import torch

val_transform = Compose([ #et.ExtResize( 512 ), ToTensor(), Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), ]) device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') model_path = 'models_res/best_deeplabv3plus_mobilenet_cityscapes_os16.pth' model = deeplabv3plus_mobilenet(num_classes = 19,output_stride=16)

model.load_state_dict(torch.load(model_path)['model_state']) model.to(device) model.eval()

img_path = 'results/4_image.png' image = Image.open(img_path).convert('RGB') input = cv2.cvtColor(np.asarray(image),cv2.COLOR_RGB2BGR) if name == 'main': import torch

cv2.namedWindow('img_draw',0)

model_dict = torch.load(model_path)
test_input = val_transform(image).unsqueeze(dim=0)
test_input = test_input.to(device)
print('输入图像:',test_input.size())
output =model(test_input).cpu().detach().clone()
print('输出:',output.size())

preds = output.max(dim=1)[1].cpu().numpy()#中括号里对应输出 19 个维度中其中一个
print(preds)
mask = (output.detach().max(dim=1)[1].cpu()==5).nonzero()
mask = mask[...,1:].numpy()
print(mask)
cv2.drawContours(input, [mask], -1, (0, 0, 255), -1)
cv2.imshow('img_draw',input)
cv2.waitKey(0)

"

KOOKOKOK avatar Sep 18 '20 12:09 KOOKOKOK

I meet the same bug. If there has any update, please tell me ASAP. Thanks a lot!

littlePrince126 avatar Sep 18 '20 13:09 littlePrince126

I meet the same bug. If there has any update, please tell me ASAP. Thanks a lot!

from network import * from torchvision.transforms.transforms import * from datasets.cityscapes import *

val_transform = Compose([ ToTensor(), Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), ]) device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') model_path = 'checkpoints/latest_deeplabv3_resnet50_cityscapes_os16.pth' model = deeplabv3_resnet50(num_classes=19,output_stride=16)

model.load_state_dict(torch.load(model_path)['model_state']) model.to(device) model.eval()

img_path = 'results/4_image.png' image = Image.open(img_path).convert('RGB') input = cv2.cvtColor(np.asarray(image),cv2.COLOR_RGB2BGR) if name == 'main': import torch

cv2.namedWindow('',0)

model_dict = torch.load(model_path)
test_input = val_transform(image).unsqueeze(dim=0)
test_input = test_input.to(device)
print('输入图像:',test_input.size())
output =model(test_input).cpu().detach().clone()
print('输出:',output.size())

preds = output.max(dim=1)[1].numpy()
print(preds)
pred = preds[0]
pred = Cityscapes.decode_target(pred).astype(np.uint8)
cv2.imshow('',pred)

cv2.waitKey(0)

KOOKOKOK avatar Sep 19 '20 00:09 KOOKOKOK

问题已解决 haha!

KOOKOKOK avatar Sep 19 '20 00:09 KOOKOKOK

去hub上看看吧,我弄好了

---原始邮件--- 发件人: "littlePrince126"<[email protected]> 发送时间: 2020年9月18日(周五) 晚上9:08 收件人: "VainF/DeepLabV3Plus-Pytorch"<[email protected]>; 抄送: "KOOKOKOK"<[email protected]>;"Author"<[email protected]>; 主题: Re: [VainF/DeepLabV3Plus-Pytorch] 关于训练结果 (#22)

I meet the same bug. If there has any update, please tell me ASAP. Thanks a lot!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

KOOKOKOK avatar Sep 19 '20 00:09 KOOKOKOK

楼上是怎么解决的?

XGBoost avatar Dec 01 '20 08:12 XGBoost

@KOOKOKOK

XGBoost avatar Dec 01 '20 08:12 XGBoost

问题已解决 haha!

大哥 请问作者的代码 更新解决了这个问题没?若解决 请告知 万分感谢 万分感谢!!!

cm0561 avatar Nov 15 '21 15:11 cm0561