Replace Objective-C bridge with Swift ONNX runtime backend
CodeQL Advanced / Analyze (swift) (push) Has been cancelled
CodeQL Advanced / Analyze (swift) (push) Has been cancelled
This commit is contained in:
@@ -1,32 +1,48 @@
|
||||
# Swift Package Manager for ONNX Runtime
|
||||
|
||||
A light-weight repository for providing [Swift Package Manager (SPM)](https://www.swift.org/package-manager/) support for [ONNXRuntime](https://github.com/microsoft/onnxruntime). The ONNX Runtime native package is included as a binary dependency of the SPM package.
|
||||
Swift-native ONNX Runtime bindings derived from the public Objective-C wrapper surface, but implemented without the Objective-C bridge so the package can build on Linux.
|
||||
|
||||
## Status
|
||||
|
||||
SPM is the alternative to CocoaPods when desired platform to consume is mobile iOS.
|
||||
- Public API covers inference, session/run options, tensor values, checkpoint state, and training session entry points.
|
||||
- Backend is wired to the ONNX Runtime C API and training C API through a Swift system library target.
|
||||
- The package expects `libonnxruntime` and headers to be available on the host, typically via `pkg-config`.
|
||||
|
||||
## Note
|
||||
## Requirements
|
||||
|
||||
The `objectivec/` directory is copied from the [ORT repo](https://github.com/microsoft/onnxruntime/tree/main/objectivec) and it's expected to match. It will be updated periodically/before release to merge new changes.
|
||||
- Swift 6.1+
|
||||
- ONNX Runtime installed on the system with:
|
||||
- `libonnxruntime`
|
||||
- `onnxruntime_c_api.h`
|
||||
- `onnxruntime_training_c_api.h`
|
||||
- `pkg-config` metadata for `libonnxruntime`
|
||||
|
||||
## Contributing
|
||||
## Usage
|
||||
|
||||
This project welcomes contributions and suggestions. Most contributions require you to agree to a
|
||||
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
|
||||
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
|
||||
```swift
|
||||
import OnnxRuntimeBindings
|
||||
|
||||
When you submit a pull request, a CLA bot will automatically determine whether you need to provide
|
||||
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
|
||||
provided by the bot. You will only need to do this once across all repos using our CLA.
|
||||
let environment = try ORTEnv(loggingLevel: .warning)
|
||||
let sessionOptions = try ORTSessionOptions()
|
||||
let session = try ORTSession(
|
||||
env: environment,
|
||||
modelPath: "/path/to/model.onnx",
|
||||
sessionOptions: sessionOptions
|
||||
)
|
||||
|
||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
||||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
|
||||
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
||||
let inputTensor = try ORTValue(
|
||||
tensorData: NSMutableData(data: inputData),
|
||||
elementType: .float,
|
||||
shape: [1, 224, 224, 3]
|
||||
)
|
||||
|
||||
## Trademarks
|
||||
let outputs = try session.run(
|
||||
inputs: ["input": inputTensor],
|
||||
outputNames: ["output"]
|
||||
)
|
||||
```
|
||||
|
||||
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
|
||||
trademarks or logos is subject to and must follow
|
||||
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
|
||||
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
|
||||
Any use of third-party trademarks or logos are subject to those third-party's policies.
|
||||
## Notes
|
||||
|
||||
- The `objectivec/` directory remains in the repo as the reference contract surface from upstream ONNX Runtime.
|
||||
- The shipped Swift package target is the pure Swift `OnnxRuntimeBindings` implementation under `swift/OnnxRuntimeBindings`.
|
||||
|
||||
Reference in New Issue
Block a user