当前位置: 首页>>代码示例>>Python>>正文


Python workspace.Predictor方法代码示例

本文整理汇总了Python中caffe2.python.workspace.Predictor方法的典型用法代码示例。如果您正苦于以下问题:Python workspace.Predictor方法的具体用法?Python workspace.Predictor怎么用?Python workspace.Predictor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在caffe2.python.workspace的用法示例。


在下文中一共展示了workspace.Predictor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import Predictor [as 别名]
def main():
    args = make_args()
    config = configparser.ConfigParser()
    utils.load_config(config, args.config)
    for cmd in args.modify:
        utils.modify_config(config, cmd)
    with open(os.path.expanduser(os.path.expandvars(args.logging)), 'r') as f:
        logging.config.dictConfig(yaml.load(f))
    torch.manual_seed(args.seed)
    model_dir = utils.get_model_dir(config)
    init_net = caffe2_pb2.NetDef()
    with open(os.path.join(model_dir, 'init_net.pb'), 'rb') as f:
        init_net.ParseFromString(f.read())
    predict_net = caffe2_pb2.NetDef()
    with open(os.path.join(model_dir, 'predict_net.pb'), 'rb') as f:
        predict_net.ParseFromString(f.read())
    p = workspace.Predictor(init_net, predict_net)
    height, width = tuple(map(int, config.get('image', 'size').split()))
    tensor = torch.randn(1, 3, height, width)
    # Checksum
    output = p.run([tensor.numpy()])
    for key, a in [
        ('tensor', tensor.cpu().numpy()),
        ('output', output[0]),
    ]:
        print('\t'.join(map(str, [key, a.shape, utils.abs_mean(a), hashlib.md5(a.tostring()).hexdigest()]))) 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:28,代码来源:checksum_caffe2.py

示例2: load_model

# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import Predictor [as 别名]
def load_model(init_net_path, predict_net_path):
    with open(init_net_path, "rb") as f:
        init_net = f.read()
    with open(predict_net_path, "rb") as f:
        predict_net = f.read()
    p = workspace.Predictor(init_net, predict_net)
    return p 
开发者ID:qfgaohao,项目名称:pytorch-ssd,代码行数:9,代码来源:run_ssd_live_caffe2.py

示例3: classify

# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import Predictor [as 别名]
def classify(self, path):
        input_image_size = self.model[4]

        img = skimage.img_as_float(skimage.io.imread(path)).astype(np.float32)
        img = self.rescale(img, input_image_size, input_image_size)
        img = self.crop_center(img, input_image_size, input_image_size)

        img = img.swapaxes(1, 2).swapaxes(0, 1)
        img = img[(2, 1, 0), :, :]
        img = img * 255 - self.mean

        img = img[np.newaxis, :, :, :].astype(np.float32)

        p = workspace.Predictor(self.init_net, self.predict_net)

        results = p.run([img])
        results = np.asarray(results)

        results = np.delete(results, 1)
        filtered_results = []

        for i, r in enumerate(results):
            if (float(r) > 0.01):
                filtered_results.append((self.get_category_from_code(i + 1), float(r)))

        return sorted(filtered_results, key=lambda result: result[1], reverse=True) 
开发者ID:damianmoore,项目名称:photo-manager-classifier,代码行数:28,代码来源:classify.py

示例4: generate_test_output_data

# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import Predictor [as 别名]
def generate_test_output_data(caffe2_init_net, caffe2_predict_net, inputs):
    p = c2_workspace.Predictor(caffe2_init_net, caffe2_predict_net)
    inputs_map = {input[0]:input[1] for input in inputs}

    output = p.run(inputs_map)
    c2_workspace.ResetWorkspace()
    return output 
开发者ID:onnxbot,项目名称:onnx-fb-universe,代码行数:9,代码来源:update-models-from-caffe2.py

示例5: run_caffe2_model

# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import Predictor [as 别名]
def run_caffe2_model(predict_net_path, init_net_path, feed_dict):
    from caffe2.python import workspace
    with open(init_net_path, "rb") as f:
        init_net = f.read()
    with open(predict_net_path, "rb") as f:
        predict_net = f.read()

    predictor = workspace.Predictor(init_net, predict_net)
    return [np.array(arr) for arr in predictor.run(feed_dict)] 
开发者ID:KhronosGroup,项目名称:NNEF-Tools,代码行数:11,代码来源:caffe2_test_runner.py

示例6: __init__

# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import Predictor [as 别名]
def __init__(self, args, config):
        self.args = args
        self.config = config
        self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
        self.cache_dir = utils.get_cache_dir(config)
        self.model_dir = utils.get_model_dir(config)
        _, self.num_parts = utils.get_dataset_mappers(config)
        self.limbs_index = utils.get_limbs_index(config)
        if args.debug is None:
            self.draw_cluster = utils.visualize.DrawCluster(colors=args.colors, thickness=args.thickness)
        else:
            self.draw_feature = utils.visualize.DrawFeature()
            s = re.search('(-?[0-9]+)([a-z]+)(-?[0-9]+)', args.debug)
            stage = int(s.group(1))
            name = s.group(2)
            channel = int(s.group(3))
            self.get_feature = lambda outputs: outputs[stage][name][0][channel]
        self.height, self.width = tuple(map(int, config.get('image', 'size').split()))
        if args.caffe:
            init_net = caffe2_pb2.NetDef()
            with open(os.path.join(self.model_dir, 'init_net.pb'), 'rb') as f:
                init_net.ParseFromString(f.read())
            predict_net = caffe2_pb2.NetDef()
            with open(os.path.join(self.model_dir, 'predict_net.pb'), 'rb') as f:
                predict_net.ParseFromString(f.read())
            p = workspace.Predictor(init_net, predict_net)
            self.inference = lambda tensor: [{'parts': torch.from_numpy(parts), 'limbs': torch.from_numpy(limbs)} for parts, limbs in zip(*[iter(p.run([tensor.detach().cpu().numpy()]))] * 2)]
        else:
            self.step, self.epoch, self.dnn, self.stages = self.load()
            self.inference = model.Inference(config, self.dnn, self.stages)
            self.inference.eval()
            if torch.cuda.is_available():
                self.inference.cuda()
            logging.info(humanize.naturalsize(sum(var.cpu().numpy().nbytes for var in self.inference.state_dict().values())))
        self.cap = self.create_cap()
        self.keys = set(args.keys)
        self.resize = transform.parse_transform(config, config.get('transform', 'resize_test'))
        self.transform_image = transform.get_transform(config, config.get('transform', 'image_test').split())
        self.transform_tensor = transform.get_transform(config, config.get('transform', 'tensor').split()) 
开发者ID:ruiminshen,项目名称:openpose-pytorch,代码行数:41,代码来源:estimate.py


注:本文中的caffe2.python.workspace.Predictor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。