예제 #1
0
            print('im_detect: {:d}/{:d} {:.4f}s {:.3f}s'.format(
                i + 1, num_images, detect_time, nms_time))
            _t['im_detect'].clear()
            _t['misc'].clear()

    with open(det_file, 'wb') as f:
        pickle.dump(all_boxes, f, pickle.HIGHEST_PROTOCOL)

    print('Evaluating detections')
    testset.evaluate_detections(all_boxes, save_folder)


if __name__ == '__main__':
    img_dim = (300, 512)[args.size == '512']
    num_classes = (21, 81)[args.dataset == 'COCO']
    net = build_net(img_dim, num_classes)  # initialize detector
    state_dict = torch.load(args.trained_model)
    # create new OrderedDict that does not contain `module.`

    from collections import OrderedDict
    new_state_dict = OrderedDict()
    for k, v in state_dict.items():
        head = k[:7]
        if head == 'module.':
            name = k[7:]  # remove `module.`
        else:
            name = k
        new_state_dict[name] = v
    net.load_state_dict(new_state_dict)
    net.eval()
    print('Finished loading model!')
예제 #2
0
    from models.FSSD_VGG_BN import build_net
elif args.version == 'FSSD_VGG_prune':
    from models.FSSD_VGG_prune import build_net
else:
    print('Unkown version!')

img_dim = (300, 512)[args.size == '512']
rgb_means = (104, 117, 123)
p = 0.6
num_classes = (21, 81)[args.dataset == 'COCO']
batch_size = args.batch_size
weight_decay = 0.0005
gamma = 0.1
momentum = 0.9

net = build_net(img_dim, num_classes)
print(net)
if not args.resume_net:
    base_weights = torch.load(args.basenet)
    print('Loading base network...')
    net.base.load_state_dict(base_weights)

    def xavier(param):
        init.xavier_uniform(param)

    def weights_init(m):
        for key in m.state_dict():
            if key.split('.')[-1] == 'weight':
                if 'conv' in key:
                    init.kaiming_normal(m.state_dict()[key], mode='fan_out')
                if 'bn' in key:
예제 #3
0
        cls = int(cls)
        title = "%s:%.2f" % (CLASSES[int(cls)], s)
        coords = (x1,y1), x2-x1+1, y2-y1+1
        color = colors[cls]
        currentAxis.add_patch(plt.Rectangle(*coords, fill=False, edgecolor=color, linewidth=2))
        currentAxis.text(x1, y1, title, bbox={'facecolor': color, 'alpha': 0.5})
    plt.axis('off')
    plt.savefig(name.split('.')[0]+'.eps',format='eps',bbox_inches = 'tight')
    plt.show()

if __name__ == "__main__":
    Image = os.listdir('image/')
    for img_name in Image:
        img = cv2.imread("image/"+img_name)
        model = 'fssd_voc_79_74.pth'
        net = build_net(300, 21)
        state_dict = torch.load(model)
        from collections import OrderedDict
        new_state_dict = OrderedDict()
        for k, v in state_dict.items():
            head = k[:7]
            if head == 'module.':
                name = k[7:] # remove `module.`
            else:
                name = k
            new_state_dict[name] = v
        net.load_state_dict(new_state_dict)
        net.eval()
        net = net.cuda()
        cudnn.benchmark = True
        print("Finished loading model")