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])
示例#2
0
        net.cuda()

optimizer = optim.SGD(net.parameters(), lr=base_lr, momentum=momentum, weight_decay=weight_decay)

if args.weights:
    state = torch.load(args.weights)
    start_epoch = state['batch']+1
    model.load_state_dict(state['state_dict'])
    optimizer.load_state_dict(state['optimizer'])
    print('loaded state %s' % (args.weights))

net.train()
buf = Variable(torch.zeros(len(device_ids)).cuda())
for batch in range(max_iter):
    if (batch+1) % test_interval == 0:
        net.eval()
        average_accuracy = 0.0
        average_loss = 0.0
        for i in range(test_iter):
            loss, accuracy = net(buf)
            average_accuracy += accuracy.data.mean()
            average_loss += loss.data.mean()
        average_accuracy /= test_iter
        average_loss /= test_iter
        print('[%d]  test loss: %f\ttest accuracy: %f' % (batch+1, average_loss, average_accuracy))
        net.train()
    else:
        optimizer.zero_grad()
        loss = net(buf).mean()
        loss.backward()
        optimizer.step()
示例#3
0
parser.add_argument('--gpu', help='gpu ids e.g "0,1,2,3"')
parser.add_argument('--solver', help='the solver prototxt')
parser.add_argument('--model', help='the network definition prototxt')
parser.add_argument('--snapshot', help='the snapshot solver state to resume training')
parser.add_argument('--weights', help='the pretrained weight')

args = parser.parse_args()
if args.mode == 'time':

    protofile  = args.model
    net_info   = parse_prototxt(protofile)
    model      = CaffeNet(protofile)
    batch_size = 64

    model.print_network()
    model.eval()

    niters = 50
    total = 0
    for i in range(niters):
        x = torch.rand(batch_size, 1, 28, 28)
        x = Variable(x)
        t0 = time.time()
        output = model(x)
        t1 = time.time()
        print('iteration %d: %fs' %(i, t1-t0))
        total = total + (t1-t0)
    print('total time %fs, %fs per batch, %fs per sample' % (total, total/niters, total/(niters*batch_size)))
    
elif args.mode == 'train':
    solver        = parse_prototxt(args.solver)