14 Star 78 Fork 29

PaddlePaddle / FastDeploy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
python.md 1.72 KB
一键复制 编辑 原始数据 按行查看 历史

English | 中文

Python Inference

Please check out the FastDeploy is already installed in your environment. You can refer to FastDeploy Installation to install the pre-compiled FastDeploy, or customize your installation.

This document shows an inference sample on the CPU using the PaddleClas classification model MobileNetV2 as an example.

1. Obtaining the model

import fastdeploy as fd

model_url = "https://bj.bcebos.com/fastdeploy/models/mobilenetv2.tgz"
fd.download_and_decompress(model_url, path=".")

2. Backend Configuration

option = fd.RuntimeOption()

option.set_model_path("mobilenetv2/inference.pdmodel",
                      "mobilenetv2/inference.pdiparams")

# **** CPU Configuration ****
option.use_cpu()
option.use_ort_backend()
option.set_cpu_thread_num(12)

# Initialise runtime
runtime = fd.Runtime(option)

# Get model input name
input_name = runtime.get_input_info(0).name

# Constructing random data for inference
results = runtime.infer({
    input_name: np.random.rand(1, 3, 224, 224).astype("float32")
})

print(results[0].shape)

When loading is complete, you will get the following output information indicating the initialized backend and the hardware devices.

[INFO] fastdeploy/fastdeploy_runtime.cc(283)::Init	Runtime initialized with Backend::OrtBackend in device Device::CPU.

Other Documents

Python
1
https://gitee.com/paddlepaddle/FastDeploy.git
git@gitee.com:paddlepaddle/FastDeploy.git
paddlepaddle
FastDeploy
FastDeploy
develop

搜索帮助

53164aa7 5694891 3bd8fe86 5694891