本文整理匯總了Python中model.config.get_output_dir方法的典型用法代碼示例。如果您正苦於以下問題:Python config.get_output_dir方法的具體用法?Python config.get_output_dir怎麽用?Python config.get_output_dir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類model.config
的用法示例。
在下文中一共展示了config.get_output_dir方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_net
# 需要導入模塊: from model import config [as 別名]
# 或者: from model.config import get_output_dir [as 別名]
def test_net(sess, net, imdb, weights_filename, thresh=0.05):
np.random.seed(cfg.RNG_SEED)
"""Test a SSH network on an image database."""
num_images = len(imdb.image_index)
# all detections are collected into:
# all_boxes[cls][image] = N x 5 array of detections in
# (x1, y1, x2, y2, score)
all_boxes = [[] for _ in range(num_images)]
output_dir = get_output_dir(imdb, weights_filename)
# timers
_t = {'im_detect': Timer(), 'misc': Timer()}
for i in range(num_images):
im = cv2.imread(imdb.image_path_at(i))
_t['im_detect'].tic()
scores, boxes = im_detect(sess, net, im)
_t['im_detect'].toc()
_t['misc'].tic()
inds = np.where(scores[:, 0] > thresh)[0]
scores = scores[inds, 0]
boxes = boxes[inds, :]
dets = np.hstack((boxes, scores[:, np.newaxis])).astype(np.float32, copy=False)
keep = nms(dets, cfg.TEST.NMS)
dets = dets[keep, :]
all_boxes[i] = det
_t['misc'].toc()
print('im_detect: {:d}/{:d} {:.3f}s {:.3f}s' \
.format(i + 1, num_images, _t['im_detect'].average_time,
_t['misc'].average_time))
det_file = os.path.join(output_dir, 'detections.pkl')
with open(det_file, 'wb') as f:
pickle.dump(all_boxes, f, pickle.HIGHEST_PROTOCOL)
print('Evaluating detections')
imdb.evaluate_detections(all_boxes, output_dir)
示例2: test_net_base
# 需要導入模塊: from model import config [as 別名]
# 或者: from model.config import get_output_dir [as 別名]
def test_net_base(sess, net, imdb, roidb, weights_filename, visualize=False):
np.random.seed(cfg.RNG_SEED)
"""Test a Fast R-CNN network on an image database."""
num_images = len(roidb)
output_dir = get_output_dir(imdb, weights_filename)
output_dir_image = os.path.join(output_dir, 'images')
if visualize and not os.path.exists(output_dir_image):
os.makedirs(output_dir_image)
all_scores = [[] for _ in range(num_images)]
# timers
_t = {'score' : Timer()}
for i in range(num_images):
_t['score'].tic()
all_scores[i], blobs = im_detect(sess, imdb, net, [roidb[i]])
_t['score'].toc()
print('score: {:d}/{:d} {:.3f}s' \
.format(i + 1, num_images, _t['score'].average_time))
if visualize and i % 10 == 0:
basename = os.path.basename(imdb.image_path_at(i)).split('.')[0]
im_vis, wrong = draw_predicted_boxes_test(blobs['data'], all_scores[i], blobs['gt_boxes'])
if wrong:
out_image = os.path.join(output_dir_image, basename + '.jpg')
print(out_image)
cv2.imwrite(out_image, im_vis)
res_file = os.path.join(output_dir, 'results.pkl')
with open(res_file, 'wb') as f:
pickle.dump(all_scores, f, pickle.HIGHEST_PROTOCOL)
print('Evaluating detections')
mcls_sc, mcls_ac, mcls_ap, mins_sc, mins_ac, mins_ap = imdb.evaluate(all_scores, output_dir)
eval_file = os.path.join(output_dir, 'results.txt')
with open(eval_file, 'w') as f:
f.write('{:.3f} {:.3f} {:.3f} {:.3f}'.format(mins_ap, mins_ac, mcls_ap, mcls_ac))
示例3: test_net_memory
# 需要導入模塊: from model import config [as 別名]
# 或者: from model.config import get_output_dir [as 別名]
def test_net_memory(sess, net, imdb, roidb, weights_filename, visualize=False, iter=0):
np.random.seed(cfg.RNG_SEED)
"""Test a Fast R-CNN network on an image database."""
num_images = len(roidb)
output_dir = get_output_dir(imdb, weights_filename + "_iter%02d" % iter)
output_dir_image = os.path.join(output_dir, 'images')
if visualize and not os.path.exists(output_dir_image):
os.makedirs(output_dir_image)
all_scores = [[] for _ in range(num_images)]
# timers
_t = {'score' : Timer()}
for i in range(num_images):
_t['score'].tic()
all_scores[i], blobs = im_detect_iter(sess, imdb, net, [roidb[i]], iter)
_t['score'].toc()
print('score: {:d}/{:d} {:.3f}s' \
.format(i + 1, num_images, _t['score'].average_time))
if visualize and i % 10 == 0:
basename = os.path.basename(imdb.image_path_at(i)).split('.')[0]
im_vis, wrong = draw_predicted_boxes_test(blobs['data'], all_scores[i], blobs['gt_boxes'])
if wrong:
out_image = os.path.join(output_dir_image, basename + '.jpg')
print(out_image)
cv2.imwrite(out_image, im_vis)
res_file = os.path.join(output_dir, 'results.pkl')
with open(res_file, 'wb') as f:
pickle.dump(all_scores, f, pickle.HIGHEST_PROTOCOL)
print('Evaluating detections')
mcls_sc, mcls_ac, mcls_ap, mins_sc, mins_ac, mins_ap = imdb.evaluate(all_scores, output_dir)
eval_file = os.path.join(output_dir, 'results.txt')
with open(eval_file, 'w') as f:
f.write('{:.3f} {:.3f} {:.3f} {:.3f}'.format(mins_ap, mins_ac, mcls_ap, mcls_ac))
示例4: test_net
# 需要導入模塊: from model import config [as 別名]
# 或者: from model.config import get_output_dir [as 別名]
def test_net(net, imdb, weights_filename, max_per_image=100, thresh=0.):
np.random.seed(cfg.RNG_SEED)
"""Test a Fast R-CNN network on an image database."""
num_images = len(imdb.image_index)
# all detections are collected into:
# all_boxes[cls][image] = N x 5 array of detections in
# (x1, y1, x2, y2, score)
all_boxes = [[[] for _ in range(num_images)]
for _ in range(imdb.num_classes)]
output_dir = get_output_dir(imdb, weights_filename)
# timers
_t = {'im_detect' : Timer(), 'misc' : Timer()}
for i in range(num_images):
im = cv2.imread(imdb.image_path_at(i))
_t['im_detect'].tic()
scores, boxes = im_detect(net, im)
_t['im_detect'].toc()
_t['misc'].tic()
# skip j = 0, because it's the background class
for j in range(1, imdb.num_classes):
inds = np.where(scores[:, j] > thresh)[0]
cls_scores = scores[inds, j]
cls_boxes = boxes[inds, j*4:(j+1)*4]
cls_dets = np.hstack((cls_boxes, cls_scores[:, np.newaxis])) \
.astype(np.float32, copy=False)
keep = nms(torch.from_numpy(cls_dets), cfg.TEST.NMS).numpy() if cls_dets.size > 0 else []
cls_dets = cls_dets[keep, :]
all_boxes[j][i] = cls_dets
# Limit to max_per_image detections *over all classes*
if max_per_image > 0:
image_scores = np.hstack([all_boxes[j][i][:, -1]
for j in range(1, imdb.num_classes)])
if len(image_scores) > max_per_image:
image_thresh = np.sort(image_scores)[-max_per_image]
for j in range(1, imdb.num_classes):
keep = np.where(all_boxes[j][i][:, -1] >= image_thresh)[0]
all_boxes[j][i] = all_boxes[j][i][keep, :]
_t['misc'].toc()
print('im_detect: {:d}/{:d} {:.3f}s {:.3f}s' \
.format(i + 1, num_images, _t['im_detect'].average_time(),
_t['misc'].average_time()))
det_file = os.path.join(output_dir, 'detections.pkl')
with open(det_file, 'wb') as f:
pickle.dump(all_boxes, f, pickle.HIGHEST_PROTOCOL)
print('Evaluating detections')
imdb.evaluate_detections(all_boxes, output_dir)
示例5: test_net
# 需要導入模塊: from model import config [as 別名]
# 或者: from model.config import get_output_dir [as 別名]
def test_net(sess, net, imdb, weights_filename, max_per_image=100, thresh=0.0):
np.random.seed(cfg.RNG_SEED)
"""Test a Fast R-CNN network on an image database."""
num_images = len(imdb.image_index)
# all detections are collected into:
# all_boxes[cls][image] = N x 5 array of detections in
# (x1, y1, x2, y2, score)
all_boxes = [[[] for _ in range(num_images)]
for _ in range(imdb.num_classes)]
output_dir = get_output_dir(imdb, weights_filename)
if os.path.isfile(os.path.join(output_dir, 'detections.pkl')):
all_boxes=pickle.load(open(os.path.join(output_dir, 'detections.pkl'),'r'))
else:
# timers
_t = {'im_detect' : Timer(), 'misc' : Timer()}
for i in range(num_images):
im = cv2.imread(imdb.image_path_at(i))
_t['im_detect'].tic()
scores, boxes,_ ,_ = im_detect(sess, net, im)
_t['im_detect'].toc()
_t['misc'].tic()
# skip j = 0, because it's the background class
for j in range(1, imdb.num_classes):
inds = np.where(scores[:, j] > thresh)[0]
cls_scores = scores[inds, j]
cls_boxes = boxes[inds, j*4:(j+1)*4]
cls_dets = np.hstack((cls_boxes, cls_scores[:, np.newaxis])) \
.astype(np.float32, copy=False)
keep = nms(cls_dets, cfg.TEST.NMS)
cls_dets = cls_dets[keep, :]
all_boxes[j][i] = cls_dets
# Limit to max_per_image detections *over all classes*
if max_per_image > 0:
image_scores = np.hstack([all_boxes[j][i][:, -1]
for j in range(1, imdb.num_classes)])
if len(image_scores) > max_per_image:
image_thresh = np.sort(image_scores)[-max_per_image]
for j in range(1, imdb.num_classes):
keep = np.where(all_boxes[j][i][:, -1] >= image_thresh)[0]
all_boxes[j][i] = all_boxes[j][i][keep, :]
_t['misc'].toc()
print('im_detect: {:d}/{:d} {:.3f}s {:.3f}s' \
.format(i + 1, num_images, _t['im_detect'].average_time,
_t['misc'].average_time))
det_file = os.path.join(output_dir, 'detections_{:f}.pkl'.format(10))
with open(det_file, 'wb') as f:
pickle.dump(all_boxes, f, pickle.HIGHEST_PROTOCOL)
print('Evaluating detections')
imdb.evaluate_detections(all_boxes, output_dir)
示例6: test_net
# 需要導入模塊: from model import config [as 別名]
# 或者: from model.config import get_output_dir [as 別名]
def test_net(sess, net, imdb, weights_filename, max_per_image=100, thresh=0.):
np.random.seed(cfg.RNG_SEED)
"""Test a Fast R-CNN network on an image database."""
num_images = len(imdb.image_index)
# all detections are collected into:
# all_boxes[cls][image] = N x 5 array of detections in
# (x1, y1, x2, y2, score)
all_boxes = [[[] for _ in range(num_images)]
for _ in range(imdb.num_classes)]
output_dir = get_output_dir(imdb, weights_filename)
# timers
_t = {'im_detect' : Timer(), 'misc' : Timer()}
for i in range(num_images):
im = cv2.imread(imdb.image_path_at(i))
_t['im_detect'].tic()
scores, boxes = im_detect(sess, net, im)
_t['im_detect'].toc()
_t['misc'].tic()
# skip j = 0, because it's the background class
for j in range(1, imdb.num_classes):
inds = np.where(scores[:, j] > thresh)[0]
cls_scores = scores[inds, j]
cls_boxes = boxes[inds, j*4:(j+1)*4]
cls_dets = np.hstack((cls_boxes, cls_scores[:, np.newaxis])) \
.astype(np.float32, copy=False)
keep = nms(cls_dets, cfg.TEST.NMS)
cls_dets = cls_dets[keep, :]
all_boxes[j][i] = cls_dets
# Limit to max_per_image detections *over all classes*
if max_per_image > 0:
image_scores = np.hstack([all_boxes[j][i][:, -1]
for j in range(1, imdb.num_classes)])
if len(image_scores) > max_per_image:
image_thresh = np.sort(image_scores)[-max_per_image]
for j in range(1, imdb.num_classes):
keep = np.where(all_boxes[j][i][:, -1] >= image_thresh)[0]
all_boxes[j][i] = all_boxes[j][i][keep, :]
_t['misc'].toc()
print('im_detect: {:d}/{:d} {:.3f}s {:.3f}s' \
.format(i + 1, num_images, _t['im_detect'].average_time,
_t['misc'].average_time))
det_file = os.path.join(output_dir, 'detections.pkl')
with open(det_file, 'wb') as f:
pickle.dump(all_boxes, f, pickle.HIGHEST_PROTOCOL)
print('Evaluating detections')
imdb.evaluate_detections(all_boxes, output_dir)