Giter VIP home page Giter VIP logo

paddle_inference's Introduction

Paddle Inference

本库是对百度飞浆推理库C接口的封装,详细说明请参考官方文档

已测试paddle_inference_c版本

  • v2.3
  • v2.4.2

使用说明

  1. 编译前请先下载或编译预测库
  2. 使用时请确保paddle_inference_c的动态库及其第三方依赖库能被正常搜索到。如:
    • Windows 下动态库及第三方依赖库目录应在环境变量PATH
    • Linux 下动态库及第三方依赖库目录应在环境变量LD_LIBRARY_PATH

使用示例

use paddle_inference::config::model::Model;
use paddle_inference::config::setting::Cpu;
use paddle_inference::Predictor;

let predictor = Predictor::builder(Model::path(
        "模型文件路径",
        "模型参数文件路径",
    ))
    // 使用 CPU 识别
    .cpu(Cpu {
        threads: Some(std::thread::available_parallelism().unwrap().get() as i32),
        mkldnn: None,
    })
    // 设置缓存陌路
    .set_optimization_cache_dir("caches".to_string())
    // 创建 Predictor
    .build();


let names = predictor.input_names();
println!("输入名称列表长度: {}", names.len());

// 获取和设置输入数据
let input = predictor.input(&names.get(0).unwrap());
input.reshape(&[1, 3, 100, 100]);
input.copy_from_f32(&[0.0; 3 * 100 * 100]);

// 执行
println!("run: {}", predictor.run());

let names = predictor.output_names();
println!("output names len: {}", names.len());

let output = predictor.output(&names.get(0).unwrap());
println!("output type: {:?}", output.data_type());
println!("output shape: {:?}", output.shape());

paddle_inference's People

Contributors

zb94 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.