Giter Club home page Giter Club logo

onnxruntime-php's Introduction

ONNX Runtime PHP

๐Ÿ”ฅ ONNX Runtime - the high performance scoring engine for ML models - for PHP

Check out an example

Build Status

Installation

Run:

composer require ankane/onnxruntime

And download the shared library:

composer exec -- php -r "require 'vendor/autoload.php'; OnnxRuntime\Vendor::check();"

Getting Started

Load a model and make predictions

$model = new OnnxRuntime\Model('model.onnx');
$model->predict(['x' => [1, 2, 3]]);

Download pre-trained models from the ONNX Model Zoo

Get inputs

$model->inputs();

Get outputs

$model->outputs();

Get metadata

$model->metadata();

Load a model from a stream

$stream = fopen('model.onnx', 'rb');
$model = new OnnxRuntime\Model($stream);

Get specific outputs

$model->predict(['x' => [1, 2, 3]], outputNames: ['label']);

Session Options

use OnnxRuntime\ExecutionMode;
use OnnxRuntime\GraphOptimizationLevel;

new OnnxRuntime\Model(
    $path,
    enableCpuMemArena: true,
    enableMemPattern: true,
    enableProfiling: false,
    executionMode: ExecutionMode::Sequential, // or Parallel
    freeDimensionOverridesByDenotation: null,
    freeDimensionOverridesByName: null,
    graphOptimizationLevel: GraphOptimizationLevel::None, // or Basic, Extended, All
    interOpNumThreads: null,
    intraOpNumThreads: null,
    logSeverityLevel: 2,
    logVerbosityLevel: 0,
    logid: 'tag',
    optimizedModelFilepath: null,
    profileFilePrefix: 'onnxruntime_profile_',
    sessionConfigEntries: null
);

Run Options

$model->predict(
    $inputFeed,
    outputNames: null,
    logSeverityLevel: 2,
    logVerbosityLevel: 0,
    logid: 'tag',
    terminate: false
);

Inference Session API

You can also use the Inference Session API, which follows the Python API.

$session = new OnnxRuntime\InferenceSession('model.onnx');
$session->run(null, ['x' => [1, 2, 3]]);

The Python example models are included as well.

OnnxRuntime\Datasets::example('sigmoid.onnx');

GPU Support

To enable GPU support on Linux and Windows, download the appropriate GPU release and set:

OnnxRuntime\FFI::$lib = 'path/to/lib/libonnxruntime.so'; // onnxruntime.dll for Windows

and use:

$model = new OnnxRuntime\Model('model.onnx', providers: ['CUDAExecutionProvider']);

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development:

git clone https://github.com/ankane/onnxruntime-php.git
cd onnxruntime-php
composer install
composer test

onnxruntime-php's People

Contributors

ankane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

hadryan ghostjat

onnxruntime-php's Issues

Memory leak in createFromOnnxValue

Hi,

I'm using onnxruntime-php in textualization/php-semantic-search. When indexing thousands of documents the memory consumption balloons up several gigs.

Looking at your code, there is this comment in SessionInference run()

        // output values released in create_from_onnx_value

However, the memory release code in SessionInference createFromOnnxValue() seems to be missing.

If that's a known bug, we can look into fixing it or waiting for a fix. Otherwise we'll look into something else as the reason behind the memory usage.

Thanks for making onnxruntime-php available!

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.