What Rust compatible package I can use with ultralytics

I have this python code:

from ultralytics import YOLO

model = YOLO("custom_ncnn_model/")

model.predict(source = "video.mp4",
show = True, conf = 0.6, line_thickness = 2, save = False)

And I was wondering how would I do the same thing in Rust without making it complex?

Something like:

model.predict(Predict{source : "video.mp4",
show : true, conf : 0.6, line_thickness : 2, save : false});

You can use also a tuple: ("video.mp4",true,0.6,2,false). It's actually aligned more to my style of programming.

I mean like what libraries etc can I use with Rust to make it compatible with ultralytics and with my model?

Did you check the crate? It looks like a good documented, although I do not have much experience with it.

1 Like

Ok I am tried it but I got this error:

   |
16 | use ort::tensor::TensorElementType;
   |          ^^^^^^ could not find `tensor` in `ort`

For more information about this error, try `rustc --explain E0432`.
error: could not compile `ultralytics-inference` (lib) due to 1 previous error

Here is my code:

use ultralytics_inference::{YOLOModel, InferenceConfig};

fn main()
{
    // Load your custom NCNN model (auto-detects format)
    let mut model = YOLOModel::load("custom_ncnn_model/").unwrap();

    // Configure exactly like Python predict params
    let mut config = InferenceConfig::default();
    config.conf = 0.6;           // Confidence threshold
    config.show = true;          // Real-time display window
    config.line_thickness = 2;   // Box line thickness
    config.save = false;         // No output saving
    config.stream = true;        // Process video frame-by-frame

    // Run prediction (handles video streaming + visualization automatically)
    model.predict_config("video.mp4", config);
}

Not too sure what to fix yet?

The problem is that ultralytics-inference is using ort via a git dependency, without any version information. You'll need to manually lock the ort crate to a version that ultralytics-inference works with. Try running this command:

cargo update ort --precise 2de34065983a5c034f5afcc072b23b99479f465b

That git hash is copied from the ultralytics/inference Cargo.lock file.

1 Like

Hi mate I don't get that error anymore, thank you, but now I get this error:

thread 'main' (100562) panicked at src/main.rs:6:59:
called `Result::unwrap()` on an `Err` value: ModelLoadError("Failed to load model: Load model from custom_ncnn_model/ failed:Protobuf parsing failed.")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Doesn't this support ncnn?