def inference(base_model_name, path_to_npz, data_format, input_files, plot): model_func = get_model(base_model_name) height, width = (368, 432) e = measure( lambda: TfPoseEstimator(path_to_npz, model_func, target_size=(width, height), data_format=data_format), 'create TfPoseEstimator') t0 = time.time() for idx, img_name in enumerate(input_files): image = measure( lambda: read_imgfile( img_name, width, height, data_format=data_format), 'read_imgfile') humans, heatMap, pafMap = measure(lambda: e.inference(image), 'e.inference') tl.logging.info('got %d humans from %s' % (len(humans), img_name)) if humans: for h in humans: tl.logging.debug(h) if plot: if data_format == 'channels_first': image = image.transpose([1, 2, 0]) plot_humans(image, heatMap, pafMap, humans, '%02d' % (idx + 1), 'inferece') tot = time.time() - t0 mean = tot / len(input_files) tl.logging.info('inference all took: %f, mean: %f, FPS: %f' % (tot, mean, 1.0 / mean))
def model_func(): target_size = (args.width, args.height) return get_model(args.base_model)(target_size, args.data_format)
def model_func(): target_size = (config.MODEL.win, config.MODEL.hin) return get_model(config.MODEL.name)(target_size, config.MODEL.data_format)
config.DATA.data_path, 'mscoco%s' % config.DATA.coco_version, 'annotations/person_keypoints_val%s.json' % config.DATA.coco_version) cocoGt = COCO(coco_json_file) catIds = cocoGt.getCatIds(catNms=['person']) keys = cocoGt.getImgIds(catIds=catIds) if config.EVAL.data_idx < 0: if config.EVAL.eval_size > 0: keys = keys[:config.EVAL. eval_size] # only use the first #eval_size elements. pass else: keys = [keys[config.EVAL.data_idx]] logger.info('validation %s set size=%d' % (coco_json_file, len(keys))) height, width = (config.MODEL.hin, config.MODEL.win) model_func = get_model(config.MODEL.name) estimator = TfPoseEstimator(os.path.join(config.MODEL.model_path, config.EVAL.model), model_func, target_size=(width, height)) result = [] for i, k in enumerate(tqdm(keys)): img_meta = cocoGt.loadImgs(k)[0] img_idx = img_meta['id'] img_name = os.path.join(image_dir, img_meta['file_name']) image = read_imgfile(img_name, width, height) if image is None: logger.error('image not found, path=%s' % img_name) sys.exit(-1)