You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Paddle/go/README_cn.md

1.2 KiB

Paddle 预测golang API

安装

首先cmake编译时打开-DON_INFER=ON,在编译目录下得到paddle_inference_c_install_dir,将该目录移动到当前目录中并重命名为paddle_c

在Go中使用Paddle预测

首先创建预测配置

config := paddle.NewAnalysisConfig()
config.SetModel(model_file, params_file)
config.SwitchUseFeedFetchOps(false)
config.SwitchSpecifyInputNames(true)

创建predictor

predictor := paddle.NewPredictor(config)

获取输入Tensor和输出Tensor

inputs = predictor.GetInputTensors()

设置输入数据(假设只有一个输入)

input := inputs[0]
input.SetValue(data)
input.Reshape([]int32{1, 3, 300, 300})

运行预测

predictor.ZeroCopyRun()

获取输入Tensor的真实值

output := outputs[0]
predictor.GetZeroCopyOutput(output)
value := reflect.ValueOf(output.Value())
shape, dtype := paddle.ShapeAndTypeOf(value)
output_data := value.Interface().([][]float32)

示例

源码见mobilenet

下载数据并解压到当前目录

运行

export LD_LIBRARY_PATH=`pwd`/paddle_c/paddle/lib:$LD_LIBRARY_PATH
go run ./demo/mobilenet.go