From 144813b3caaf13a84e4f6c185bc9d48b2e9ce9c4 Mon Sep 17 00:00:00 2001 From: Anton Osokin Date: Fri, 9 Feb 2018 09:55:11 +0000 Subject: [PATCH 1/4] fixes to run SSD demo --- torchcv/models/fpnssd/net.py | 2 +- torchcv/models/retinanet/retinanet.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/torchcv/models/fpnssd/net.py b/torchcv/models/fpnssd/net.py index 8192eb2..253f480 100644 --- a/torchcv/models/fpnssd/net.py +++ b/torchcv/models/fpnssd/net.py @@ -2,7 +2,7 @@ import torch.nn as nn import torch.nn.functional as F -from fpn import FPN50 +from .fpn import FPN50 from torch.autograd import Variable diff --git a/torchcv/models/retinanet/retinanet.py b/torchcv/models/retinanet/retinanet.py index 7e8c3db..ed5d528 100644 --- a/torchcv/models/retinanet/retinanet.py +++ b/torchcv/models/retinanet/retinanet.py @@ -1,7 +1,7 @@ import torch import torch.nn as nn -from fpn import FPN50 +from .fpn import FPN50 from torch.autograd import Variable From 8154e6f0fa5a633fcfe5cb2a407c1aaf537a2922 Mon Sep 17 00:00:00 2001 From: Anton Osokin Date: Fri, 9 Feb 2018 19:04:16 +0300 Subject: [PATCH 2/4] make examples/ssd/eval.py work --- examples/ssd/demo.py | 2 +- examples/ssd/eval.py | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/examples/ssd/demo.py b/examples/ssd/demo.py index 6f06719..054e7a9 100644 --- a/examples/ssd/demo.py +++ b/examples/ssd/demo.py @@ -5,7 +5,7 @@ from PIL import Image, ImageDraw from torch.autograd import Variable from torchcv.models.fpnssd import FPNSSD512 -from torchcv.models.ssd import SSD512, SSDBoxCoder +from torchcv.models.ssd import SSDBoxCoder print('Loading model..') diff --git a/examples/ssd/eval.py b/examples/ssd/eval.py index a73f069..3c5e9eb 100755 --- a/examples/ssd/eval.py +++ b/examples/ssd/eval.py @@ -7,13 +7,15 @@ from torchcv.transforms import resize from torchcv.datasets import ListDataset from torchcv.evaluations.voc_eval import voc_eval -from torchcv.models.ssd import SSD300, SSDBoxCoder +from torchcv.models.fpnssd import FPNSSD512 +from torchcv.models.ssd import SSDBoxCoder from PIL import Image +import numpy as np print('Loading model..') -net = SSD300(num_classes=21) +net = FPNSSD512(num_classes=21) net.load_state_dict(torch.load('./examples/ssd/checkpoint/params.pth')) net.cuda() net.eval() @@ -32,7 +34,7 @@ def transform(img, boxes, labels): list_file='torchcv/datasets/voc/voc07_test.txt', transform=transform) dataloader = torch.utils.data.DataLoader(dataset, batch_size=1, shuffle=False, num_workers=2) -box_coder = SSDBoxCoder() +box_coder = SSDBoxCoder(net) pred_boxes = [] pred_labels = [] @@ -44,7 +46,7 @@ def transform(img, boxes, labels): gt_difficults = [] for line in f.readlines(): line = line.strip().split() - d = [int(x) for x in line[1:]] + d = np.array([int(x) for x in line[1:]]) gt_difficults.append(d) def eval(net, dataset): @@ -62,10 +64,9 @@ def eval(net, dataset): pred_boxes.append(box_preds) pred_labels.append(label_preds) pred_scores.append(score_preds) - - print voc_eval( - pred_boxes, pred_labels, pred_scores, - gt_boxes, gt_labels, gt_difficults, - iou_thresh=0.5, use_07_metric=True) + + print(voc_eval(pred_boxes, pred_labels, pred_scores, + gt_boxes, gt_labels, gt_difficults, + iou_thresh=0.5, use_07_metric=True)) eval(net, dataset) From 94e3fb4a030b2eb6cbdbf70c6e41f45bff59ec4a Mon Sep 17 00:00:00 2001 From: Anton Osokin Date: Fri, 9 Feb 2018 19:06:20 +0300 Subject: [PATCH 3/4] minor fix in test --- torchcv/models/fpnssd/net.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchcv/models/fpnssd/net.py b/torchcv/models/fpnssd/net.py index 253f480..37800aa 100644 --- a/torchcv/models/fpnssd/net.py +++ b/torchcv/models/fpnssd/net.py @@ -44,7 +44,7 @@ def forward(self, x): def test(): - net = SSD512(21) + net = FPNSSD512(21) loc_preds, cls_preds = net(Variable(torch.randn(1,3,512,512))) print(loc_preds.size(), cls_preds.size()) From dd7d922f7e8177ab205df91b4f08e5343e4fd040 Mon Sep 17 00:00:00 2001 From: Anton Osokin Date: Fri, 9 Feb 2018 19:55:36 +0300 Subject: [PATCH 4/4] image resolution --- examples/ssd/eval.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ssd/eval.py b/examples/ssd/eval.py index 3c5e9eb..1d4d50c 100755 --- a/examples/ssd/eval.py +++ b/examples/ssd/eval.py @@ -21,7 +21,7 @@ net.eval() print('Preparing dataset..') -img_size = 300 +img_size = 512 def transform(img, boxes, labels): img, boxes = resize(img, boxes, size=(img_size,img_size)) img = transforms.Compose([