コード例 #1
0
ファイル: infer.py プロジェクト: Oneflow-Inc/models
def main(args):
    start_t = time.time()
    dla_module = DLA(
        num_classes=10, levels=[1, 1, 1, 2, 2, 1], channels=[16, 32, 64, 128, 256, 512]
    )
    end_t = time.time()
    print("init time : {}".format(end_t - start_t))
    start_t = time.time()
    pretrain_models = flow.load(args.model_path)
    dla_module.load_state_dict(pretrain_models)
    end_t = time.time()
    print("load params time : {}".format(end_t - start_t))
    dla_module.eval()
    dla_module.to("cuda")
    start_t = time.time()
    image = load_image(args.image_path)
    image = flow.Tensor(image, device=flow.device("cuda"))
    logits = dla_module(image)
    predictions = logits.softmax()
    predictions = predictions.numpy()
    end_t = time.time()
    print("infer time : {}".format(end_t - start_t))
    clsidx = np.argmax(predictions)
    print(
        "predict prob: %f, class name: %s"
        % (np.max(predictions), clsidx_2_labels[clsidx])
    )
コード例 #2
0
ファイル: infer.py プロジェクト: Oneflow-Inc/models
def main(args):

    start_t = time.time()
    model = build_model(args)
    end_t = time.time()
    print("init time : {}".format(end_t - start_t))

    start_t = time.time()
    pretrain_models = flow.load(args.model_path)
    model.load_state_dict(pretrain_models)
    end_t = time.time()
    print("load params time : {}".format(end_t - start_t))

    model.eval()
    model.to("cuda")

    start_t = time.time()
    image = load_image(args.image_path,
                       image_size=(args.image_size, args.image_size))
    image = flow.Tensor(image, device=flow.device("cuda"))
    predictions = model(image).softmax()
    predictions = predictions.numpy()
    end_t = time.time()
    print("infer time : {}".format(end_t - start_t))
    clsidx = np.argmax(predictions)
    print("predict prob: %f, class name: %s" %
          (np.max(predictions), clsidx_2_labels[clsidx]))
コード例 #3
0
def main(args):
    assert args.model in model_dict
    print("Predicting using", args.model, "...")

    start_t = time.time()
    net_module = model_dict[args.model]()
    end_t = time.time()
    print("init time : {}".format(end_t - start_t))

    start_t = time.time()
    pretrain_models = flow.load(args.model_path)
    net_module.load_state_dict(pretrain_models)
    end_t = time.time()
    print("load params time : {}".format(end_t - start_t))

    net_module.eval()
    net_module.to("cuda")

    start_t = time.time()
    image = load_image(args.image_path)
    image = flow.Tensor(image, device=flow.device("cuda"))
    predictions = net_module(image).softmax()
    predictions = predictions.numpy()
    end_t = time.time()
    print("infer time : {}".format(end_t - start_t))
    clsidx = np.argmax(predictions)
    print("predict prob: %f, class name: %s" %
          (np.max(predictions), clsidx_2_labels[clsidx]))
コード例 #4
0
ファイル: infer.py プロジェクト: Oneflow-Inc/models
def main(args):

    start_t = time.time()
    repVGGA0 = create_RepVGG_A0()
    end_t = time.time()
    print("init time : {}".format(end_t - start_t))

    start_t = time.time()
    pretrain_models = flow.load(args.model_path)
    repVGGA0.load_state_dict(pretrain_models)
    end_t = time.time()
    print("load params time : {}".format(end_t - start_t))

    repVGGA0.eval()
    repVGGA0.to("cuda")

    start_t = time.time()
    image = load_image(args.image_path)
    image = flow.Tensor(image, device=flow.device("cuda"))
    predictions = repVGGA0(image).softmax()
    predictions = predictions.numpy()
    end_t = time.time()
    print("infer time : {}".format(end_t - start_t))
    clsidx = np.argmax(predictions)
    print("predict prob: %f, class name: %s" %
          (np.max(predictions), clsidx_2_labels[clsidx]))
コード例 #5
0
def main(args):
    flow.env.init()
    flow.enable_eager_execution()

    start_t = time.time()
    posenet_module = PoseNet()
    end_t = time.time()
    print("init time : {}".format(end_t - start_t))

    start_t = time.time()
    pretrain_models = flow.load(args.model_path)
    posenet_module.load_state_dict(pretrain_models)
    end_t = time.time()
    print("load params time : {}".format(end_t - start_t))

    posenet_module.eval()
    posenet_module.to("cuda")

    start_t = time.time()
    image = load_image(args.image_path)
    image = flow.Tensor(image, device=flow.device("cuda"))
    logits = posenet_module(image)
    predictions = logits.softmax()
    predictions = predictions.numpy()
    end_t = time.time()
    print("infer time : {}".format(end_t - start_t))
    clsidx = np.argmax(predictions)
    print("predict prob: %f, class name: %s" %
          (np.max(predictions), clsidx_2_labels[clsidx]))
コード例 #6
0
ファイル: infer.py プロジェクト: Oneflow-Inc/models
def main(args):

    start_t = time.time()
    inceptionv3_module = inception_v3()
    end_t = time.time()
    print("init time : {}".format(end_t - start_t))

    start_t = time.time()
    pretrain_models = flow.load(args.model_path)
    inceptionv3_module.load_state_dict(pretrain_models)
    end_t = time.time()
    print("load params time : {}".format(end_t - start_t))

    inceptionv3_module.eval()
    inceptionv3_module.to("cuda")

    start_t = time.time()
    image = load_image(args.image_path)
    image = flow.Tensor(image, device=flow.device("cuda"))
    predictions, aux_predictions = inceptionv3_module(image)
    predictions = predictions.softmax()
    predictions = predictions.numpy()
    end_t = time.time()
    print("infer time : {}".format(end_t - start_t))
    clsidx = np.argmax(predictions)
    print("predict prob: %f, class name: %s" %
          (np.max(predictions), clsidx_2_labels[clsidx]))
コード例 #7
0
def main(args):
    start_t = time.time()
    quantization_module = QuantizationAlexNet()
    quantization_module.quantize(
        quantization_bit=args.quantization_bit,
        quantization_scheme=args.quantization_scheme,
        quantization_formula=args.quantization_formula,
        per_layer_quantization=args.per_layer_quantization,
    )
    end_t = time.time()
    print("init time : {}".format(end_t - start_t))

    start_t = time.time()
    pretrain_models = flow.load(args.model_path)
    quantization_module.load_state_dict(pretrain_models)
    end_t = time.time()
    print("load params time : {}".format(end_t - start_t))

    quantization_module.eval()
    quantization_module.to("cuda")

    start_t = time.time()
    image = load_image(args.image_path)
    image = flow.Tensor(image, device=flow.device("cuda"))
    predictions = quantization_module(image).softmax()
    predictions = predictions.numpy()
    end_t = time.time()
    print("infer time : {}".format(end_t - start_t))
    clsidx = np.argmax(predictions)
    print("predict prob: %f, class name: %s" %
          (np.max(predictions), clsidx_2_labels[clsidx]))
コード例 #8
0
def main(args):
    start_t = time.perf_counter()

    print("***** Model Init *****")
    model = resnet50()
    model.load_state_dict(flow.load(args.model_path))
    model = model.to("cuda")
    model.eval()
    end_t = time.perf_counter()
    print(f"***** Model Init Finish, time escapled {end_t - start_t:.6f} s *****")

    if args.graph:
        model_graph = InferGraph(model)

    start_t = end_t
    image = load_image(args.image_path)
    image = flow.Tensor(image, device=flow.device("cuda"))
    if args.graph:
        pred = model_graph(image)
    else:
        pred = model(image).softmax()

    pred = pred.numpy()
    prob = np.max(pred)
    clsidx = np.argmax(pred)
    cls = clsidx_2_labels[clsidx]

    end_t = time.perf_counter()
    print(
        "predict image ({}) prob: {:.5f}, class name: {}, time escapled: {:.6f} s".format(
            os.path.basename(args.image_path), prob, cls, end_t - start_t
        )
    )
コード例 #9
0
ファイル: infer.py プロジェクト: Oneflow-Inc/models
def main(args):
    start_t = time.time()
    model = inception_v3()
    end_t = time.time()
    print("init time : {}".format(end_t - start_t))

    start_t = time.time()
    pretrain_models = flow.load(args.model_path)
    model.load_state_dict(pretrain_models)
    end_t = time.time()
    print("load params time : {}".format(end_t - start_t))

    model.eval()
    model.to("cuda")

    class EvalGraph(flow.nn.Graph):
        def __init__(self):
            super().__init__()
            self.model = model

        def build(self, image):
            with flow.no_grad():
                predictions, aux = self.model(image)
            return predictions

    inception_eval_graph = EvalGraph()

    start_t = time.time()
    image = load_image(args.image_path)
    image = flow.Tensor(image, device=flow.device("cuda"))
    predictions = inception_eval_graph(image).softmax()
    predictions = predictions.numpy()
    end_t = time.time()
    print("infer time : {}".format(end_t - start_t))
    clsidx = np.argmax(predictions)
    print(
        "predict prob: %f, class name: %s"
        % (np.max(predictions), clsidx_2_labels[clsidx])
    )