Exemple #1
0
def detect(cfgfile, weightfile, imgfile):
    if cfgfile.find('.prototxt') >= 0:
        from caffenet import CaffeNet
        m = CaffeNet(cfgfile)
    else:
        m = Darknet(cfgfile)

    m.print_network()
    m.load_weights(weightfile)
    print('Loading weights from %s... Done!' % (weightfile))

    if m.num_classes == 20:
        namesfile = 'data/voc.names'
    elif m.num_classes == 80:
        namesfile = 'data/coco.names'
    else:
        namesfile = 'data/names'
    
    use_cuda = 1
    if use_cuda:
        m.cuda()

    img = Image.open(imgfile).convert('RGB')
    sized = img.resize((m.width, m.height))
    
    for i in range(2):
        start = time.time()
        boxes = do_detect(m, sized, 0.5, 0.4, use_cuda)
        finish = time.time()
        if i == 1:
            print('%s: Predicted in %f seconds.' % (imgfile, (finish-start)))

    class_names = load_class_names(namesfile)
    plot_boxes(img, boxes, 'predictions.jpg', class_names)
Exemple #2
0
def detect(cfgfile, weightfile, imgfile):
    if cfgfile.find('.prototxt') >= 0:
        from caffenet import CaffeNet
        m = CaffeNet(cfgfile)
    else:
        m = Darknet(cfgfile)

    m.print_network()
    m.load_weights(weightfile)
    print('Loading weights from %s... Done!' % (weightfile))

    if m.num_classes == 20:
        namesfile = 'data/voc.names'
    elif m.num_classes == 80:
        namesfile = 'data/coco.names'
    else:
        namesfile = 'data/names'

    use_cuda = 1
    if use_cuda:
        m.cuda()

    img = Image.open(imgfile).convert('RGB')
    sized = img.resize((m.width, m.height))

    for i in range(2):
        start = time.time()
        boxes = do_detect(m, sized, 0.5, 0.4, use_cuda)
        finish = time.time()
        if i == 1:
            print('%s: Predicted in %f seconds.' % (imgfile, (finish - start)))

    class_names = load_class_names(namesfile)
    plot_boxes(img, boxes, 'predictions.jpg', class_names)
Exemple #3
0
test_interval = 99999999
snapshot = int(solver['snapshot'])
snapshot_prefix = solver['snapshot_prefix']
stepvalues = solver['stepvalue']
stepvalues = [int(item) for item in stepvalues]

if args.lr != None:
    base_lr = args.lr

#torch.manual_seed(int(time.time()))
#if args.gpu:
#    torch.cuda.manual_seed(int(time.time()))
#print(protofile)
net = CaffeNet(protofile)
if args.weights:
    net.load_weights(args.weights)
#net.set_verbose(False)
net.set_train_outputs('mbox_loss')

if args.gpu:
    device_ids = args.gpu.split(',')
    device_ids = [int(i) for i in device_ids]
    print('device_ids', device_ids)
    if len(device_ids) > 1:
        print('---- Multi GPUs ----')
        net = ParallelCaffeNet(net.cuda(), device_ids=device_ids)
    else:
        print('---- Single GPU ----')
        net.cuda()

print(net)
weightfile1 = 'reid.weights'
cfgfile2 = 'reid_nbn.cfg'
weightfile2 = 'reid_nbn.weights'
cfgfile3 = 'reid_nbn.prototxt'
weightfile3 = 'reid_nbn.caffemodel'

m1 = Darknet(cfgfile1)
m1.load_weights(weightfile1)
m1.eval()

m2 = Darknet(cfgfile2)
m2.load_weights(weightfile2)
m2.eval()

m3 = CaffeNet(cfgfile3)
m3.load_weights(weightfile3)
m3.eval()

img = torch.rand(8, 3, 128, 64)
img = Variable(img)

output1 = m1(img).clone()
output2 = m2(img).clone()
output3 = m3(img).clone()
print('----- output1 ------------------')
print(output1.data.storage()[0:100])
print('----- output2 ------------------')
print(output2.data.storage()[0:100])
print('----- output3 ------------------')
print(output3.data.storage()[0:100])