def eval_list(cfgfile, namefile, weightfile, testfile): m = Darknet(cfgfile) m.load_weights(weightfile) use_cuda = 1 if use_cuda: m.cuda() class_names = load_class_names(namefile) file_list = [] with open(testfile, "r") as fin: for f in fin: file_list.append(f.strip()) for imgfile in file_list: img = Image.open(imgfile).convert('RGB') sized = img.resize((m.width, m.height)) filename = os.path.basename(imgfile) filename = os.path.splitext(filename)[0] #print(filename, img.width, img.height, sized_width, sized_height) if m.width * m.height > 1024 * 2560: print('omit %s' % filename) continue if False: boxes = do_detect(m, sized, conf_thresh, nms_thresh, use_cuda) else: m.eval() sized = image2torch(sized).cuda(); #output = m(Variable(sized, volatile=True)).data output = m(sized) #boxes = get_region_boxes(output, conf_thresh, m.num_classes, m.anchors, m.num_anchors, 0, 1)[0] boxes = get_all_boxes(output, conf_thresh, m.num_classes)[0] boxes = np.array(nms(boxes, nms_thresh)) if False: savename = get_det_image_name(imgfile) print('img: save to %s' % savename) plot_boxes(img, boxes, savename, class_names) if False: savename = get_det_result_name(imgfile) print('det: save to %s' % savename) save_boxes(imgfile, img, boxes, savename)
print(model.models[0][1].bias) print("--- bn running_mean ---") print(model.models[0][1].running_mean) print("--- bn running_var ---") print(model.models[0][1].running_var) model.train() m = model.cuda() optimizer = optim.SGD(model.parameters(), lr=1e-2, momentum=0.9, weight_decay=0.1) img = Image.open(imgpath) img = image2torch(img) img = Variable(img.cuda()) target = Variable(label) print("----- img ---------------------") print(img.data.storage()[0:100]) print("----- target -----------------") print(target.data.storage()[0:100]) optimizer.zero_grad() output = m(img) print("----- output ------------------") print(output.data.storage()[0:100]) exit()
print('--- bn weight ---') print(m.models[0][1].weight) print('--- bn bias ---') print(m.models[0][1].bias) print('--- bn running_mean ---') print(m.models[0][1].running_mean) print('--- bn running_var ---') print(m.models[0][1].running_var) m.train() m = m.cuda() optimizer = optim.SGD(m.parameters(), lr=1e-2, momentum=0.9, weight_decay=0.1) img = Image.open(imgpath) img = image2torch(img).cuda() target = label print('----- img ---------------------') print(img.data.storage()[0:100]) print('----- target -----------------') print(target.data.storage()[0:100]) optimizer.zero_grad() output = m(img) print('----- output ------------------') print(output.data.storage()[0:100]) exit() loss = region_loss(output, target)
def detect(model, img, conf_thresh, nms_thresh, use_cuda): img = image2torch(img) img = img.to(torch.device('cuda' if use_cuda else 'cpu')) out_boxes = model(img) boxes = get_all_boxes(out_boxes, conf_thresh, model.num_classes, use_cuda=use_cuda)[0] return nms(boxes, nms_thresh)