TEST
import torch
import torchvision.transforms as transforms
import  exps.voc.config2 as cfg
from torch.autograd import Variable
import pandas as pd
from retinanet import RetinaNet
from encoder import DataEncoder
from PIL import Image, ImageDraw
try:
import ipdb
except:
import pdb as ipdb
print(‘Loading model…’)
net = RetinaNet(backbone=cfg.backbone, num_classes=len(cfg.classes),pretrained=False)
map_location = lambda storage, loc: storage
net.load_state_dict(torch.load(’.store/ckpt6.pth’,map_location=‘cpu’)[‘net’],strict=False)
print(torch.load(’.store/ckpt6.pth’,map_location=map_location)[‘lr’])
print(torch.load(’.store/ckpt6.pth’,map_location=map_location)[‘epoch’])
net.eval()
transform = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize((0.485,0.456,0.406), (0.229,0.224,0.225))
])
print(‘Loading image…’)
img = Image.open(’./image/0.jpg’)
w =img.size[0]
h=img.size[1]
img = img.resize((w,h))
x = transform(img)
x = x.unsqueeze(0)
x = Variable(x, volatile=True)
loc_preds, cls_preds = net(x)
encoder = DataEncoder()
cls_preds1=cls_preds.data.squeeze()
score, labels = cls_preds1.max(1)
xxx = pd.DataFrame(score.tolist())
print(xxx.describe())
yyy=pd.DataFrame(labels.tolist())
print(yyy.describe())
yy=labels>0
print(yy.numel())
print(yy.data.long().sum())
FIRST
              0

count  56088.000000
mean       0.014430
std        0.033506
min       -0.333214
25%       -0.000789
50%        0.010297
75%        0.027038
max        0.603817
0
count  56088.000000
mean       0.770807
std        0.420318
min        0.000000
25%        1.000000
50%        1.000000
75%        1.000000
max        1.000000
56088
tensor(43233)
SECOND
0
count  56088.000000
mean       0.022885
std        0.063939
min       -0.526022
25%       -0.011785
50%        0.007780
75%        0.041688
max        0.933956
0
count  56088.000000
mean       0.550260
std        0.497472
min        0.000000
25%        0.000000
50%        1.000000
75%        1.000000
max        1.000000
56088
tensor(30863)