Skip to content

Commit

Permalink
Update README and comments in examples code
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Yusupov committed Feb 10, 2024
1 parent 98a70c0 commit 83e6c89
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 17 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@ classification example:
git clone https://github.com/robertknight/rten.git
cd rten

# Install dependencies for model conversion
pip install -e rten-convert

# Install dependencies for Python scripts
pip install -r tools/requirements.txt

# Export an ONNX model. We're using resnet-50, a classic image classification model.
python -m tools.export-timm-model timm/resnet50.a1_in1k

# Convert model to this library's format
tools/convert-onnx.py resnet50.a1_in1k.onnx resnet50.rten
rten-convert resnet50.a1_in1k.onnx resnet50.rten

# Run image classification example. Replace `image.png` with your own image.
cargo run -p rten-examples --release --bin imagenet mobilenet resnet50.rten image.png
Expand All @@ -76,8 +79,8 @@ run:

```sh
git clone https://github.com/robertknight/rten.git
pip install -r rten/tools/requirements.txt
rten/tools/convert-onnx.py your-model.onnx output.rten
pip install -e rten/rten-convert
rten-convert your-model.onnx output.rten
```

The RTen model format does not yet guarantee long-term backwards compatibility,
Expand Down Expand Up @@ -111,7 +114,7 @@ a JavaScript project are:
or [Hugging Face](https://huggingface.co/docs/transformers/serialization).
2. If the model is not already in ONNX format, convert it to ONNX. PyTorch
users can use [torch.onnx](https://pytorch.org/docs/stable/onnx.html) for this.
3. Use the `tools/convert-onnx.py` script in this repository to convert the model
3. Use the `rten-convert` package in this repository to convert the model
to the optimized format RTen uses. See the section above on converting models.
4. In your JavaScript code, fetch the WebAssembly binary and initialize RTen
using the `init` function.
Expand Down
2 changes: 1 addition & 1 deletion docs/adding-operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ In detail, the process is:
attributes from that operator.
3. Run `make` to generate updated Rust and Python code to read the updated
FlatBuffers schema
4. If the new operator has attributes, edit `tools/convert-onnx.py` to read
4. If the new operator has attributes, edit `rten-convert/rten_convert/converter.py` and reinstall rten-convert to read
the attributes from ONNX and convert to this library's model format
5. Define the implementation of the new operator in Rust. This is a struct
that implements the `Operator` trait.
Expand Down
4 changes: 3 additions & 1 deletion js-examples/image-classification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ kind of object.

```sh
curl -L https://github.com/onnx/models/raw/main/vision/classification/mobilenet/model/mobilenetv2-10.onnx -o mobilenet.onnx
../../tools/convert-onnx.py mobilenet.onnx mobilenet.rten

pip install -e ../../rten-convert
rten-convert mobilenet.onnx mobilenet.rten
```
4. Follow either of the subsections below to run the example in Node or the
browser
Expand Down
3 changes: 2 additions & 1 deletion rten-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ fn print_input_output_list(model: &Model, node_ids: &[NodeId]) {
/// generated inputs.
///
/// ```
/// tools/convert-onnx.py model.onnx output.rten
/// pip install -e rten-convert
/// rten-convert model.onnx output.rten
/// cargo run -p rten-cli --release output.rten
/// ```
///
Expand Down
7 changes: 4 additions & 3 deletions rten-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ The general steps to run an example are:
Face](https://huggingface.co/docs/optimum/exporters/onnx/overview),
the [ONNX Model Zoo](https://github.com/onnx/models) or pre-created ONNX
models by the model authors.
2. Convert the ONNX model to this library's format using the `convert-onnx.py`
script:
2. Convert the ONNX model to this library's format using the `rten-convert`
package:

```sh
$ ../tools/convert-onnx.py <onnx_model> <output_model>
$ pip install -e rten-convert
$ rten-convert <onnx_model> <output_model>
```

3. Run the example using:
Expand Down
3 changes: 2 additions & 1 deletion rten-examples/src/bert_qa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ fn extract_nbest_answers<'a>(
///
/// ```
/// optimum-cli export onnx --model distilbert-base-cased-distilled-squad distilbert
/// tools/convert-onnx.py distilbert/model.onnx distilbert/distilbert.rten
/// pip install -e rten-convert
/// rten-convert distilbert/model.onnx distilbert/distilbert.rten
/// ```
///
/// Then run the example with:
Expand Down
3 changes: 2 additions & 1 deletion rten-examples/src/deeplab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ const PASCAL_VOC_LABELS: [(&str, Rgb); 21] = [
///
/// ```
/// python examples/export-deeplab.py
/// tools/convert-onnx.py deeplab.onnx deeplab.rten
/// pip install -e rten-convert
/// rten-convert deeplab.onnx deeplab.rten
/// ```
///
/// Run this program on an image with:
Expand Down
3 changes: 2 additions & 1 deletion rten-examples/src/depth_anything.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ Args:
/// After downloading the model, it can be run on an image using:
///
/// ```
/// tools/convert-onnx.py depth_anything.onnx
/// pip install -e rten-convert
/// rten-convert depth_anything.onnx
/// cargo run --release --bin depth_anything depth_anything.rten image.jpg
/// ```
///
Expand Down
3 changes: 2 additions & 1 deletion rten-examples/src/detr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ const LABELS: &[&str] = &[
///
/// ```
/// optimum-cli export onnx --model facebook/detr-resnet-50 detr
/// tools/convert-onnx.py detr/model.onnx detr.rten
/// pip install -e rten-convert
/// rten-convert detr/model.onnx detr.rten
/// ```
///
/// This model also works with YOLOS. Use `hustvl/yolos-tiny` or
Expand Down
3 changes: 2 additions & 1 deletion rten-examples/src/jina_similarity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ fn embed_sentence_batch(
/// Convert the model using:
///
/// ```text
/// tools/convert-onnx.py jina-embed.onnx jina-embed.rten
/// pip install -e rten-convert
/// rten-convert jina-embed.onnx jina-embed.rten
/// ```
///
/// Then run the example with:
Expand Down
3 changes: 2 additions & 1 deletion rten-examples/src/wav2vec2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ fn read_wav_file(path: &str) -> Result<Vec<f32>, hound::Error> {
///
/// ```
/// optimum-cli export onnx --model facebook/wav2vec2-base-960h wav2vec2
/// tools/convert-onnx.py wav2vec2/model.onnx wav2vec2.rten
/// pip install -e rten-convert
/// rten-convert wav2vec2/model.onnx wav2vec2.rten
/// ```
///
/// To record a .wav file and test this app:
Expand Down
3 changes: 2 additions & 1 deletion rten-examples/src/yolo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ fn resource_path(path: &str) -> PathBuf {
/// ```
/// pip install ultralytics
/// yolo mode=export model=yolov8s.pt format=onnx
/// tools/convert-onnx.py yolov8s.onnx yolov8.rten
/// pip install -e rten-convert
/// rten-convert yolov8s.onnx yolov8.rten
/// ```
///
/// Run this program on an image:
Expand Down

0 comments on commit 83e6c89

Please sign in to comment.