caffe.set_device(1) net = caffe.Net(net_file, caffe_model, caffe.TEST) coco_names = np.loadtxt('../lib/coco_names.txt', str, delimiter='\n') data_dir = '../demo/images/' out_dir = '../demo/output/' if not os.path.exists(out_dir): os.makedirs(out_dir) imgpath = os.listdir(data_dir) for imgfile in imgpath: result = open(out_dir + '/' + imgfile.split('.')[0] + '.txt', 'w+') starttime = time.time() cls_det = multi_scale_test_net_512(net, data_dir + '/' + imgfile, soft_nms=False) endtime = time.time() print 'speed: {:.3f}s / iter'.format(endtime - starttime) result.write(imgfile.split('.')[0] + '\n') for j in range(1, 81): if len(cls_det[j][0]) != 0: for i in range(len(cls_det[j][0])): result.write( str(coco_names[j - 1]) + ' ' + str(int(cls_det[j][0][i][0])) + ' ' + str(int(cls_det[j][0][i][1])) + ' ' + str(int(cls_det[j][0][i][2])) + ' ' + str(int(cls_det[j][0][i][3])) + ' ' + str(cls_det[j][0][i][4]) + '\n') result.close()
caffemodel = path + model print('Start evaluating: ' + caffemodel) net = caffe.Net(prototxt, caffemodel, caffe.TEST) net.name = os.path.splitext(os.path.basename(model))[0] cfg.net_name = net.name try: iter = int(net.name.split('_')[-1]) except: iter = 000000 if single_scale is True: single_scale_test_net(net, imdb, targe_size=input_size) else: if input_size == 320: multi_scale_test_net_320(net, imdb) else: multi_scale_test_net_512(net, imdb) mAP[iter] = cfg.mAP keys = mAP.keys() keys.sort() templine = [] print( "#########################################################################################################" ) print( "#########################################################################################################" ) if 'voc' in test_set: for key in keys: value = mAP.get(key) print("%d\t%.4f" % (key, value))
iter = 000000 if single_scale is True: single_scale_test_net(net, imdb, targe_size=input_size, vis=visualizeDets, redoInference=redoInference) else: if input_size == 320: multi_scale_test_net_320(net, imdb, vis=visualizeDets, redoInference=redoInference) else: multi_scale_test_net_512(net, imdb, vis=visualizeDets, redoInference=redoInference) mAP[iter] = cfg.mAP mPrec[iter] = cfg.prec mRec[iter] = cfg.rec # Also available for further evaluation (From MATLAB, not used yet): miss[iter] = cfg.miss #roc[iter] = cfg.roc #gt[iter] = cfg.gt #dt[iter] = cfg.dt # Just to check data structure: #print("Miss : " + str( miss.get(miss.keys()[0]) )) #print("ROCs : " + str( roc.get(roc.keys()[0]) )) #print("GTs : " + str( gt.get(gt.keys()[0]) )) #print("DTs : " + str( dt.get(dt.keys()[0]) ))