Add multiple export formats inference support in Live Inference solution (#21553)

Signed-off-by: Muhammad Rizwan Munawar <muhammadrizwanmunawar123@gmail.com>
Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
Co-authored-by: Ultralytics Assistant <135830346+UltralyticsAssistant@users.noreply.github.com>
Co-authored-by: Jing Qiu <61612323+Laughing-q@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
Muhammad Rizwan Munawar 2025-08-18 19:36:09 +05:00 committed by GitHub
parent 2d9e8a0b44
commit 35dd4bc725
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 21 deletions

View File

@ -64,24 +64,6 @@ Streamlit makes it simple to build and deploy interactive web applications. Comb
This will launch the Streamlit application in your default web browser. You will see the main title, subtitle, and the sidebar with configuration options. Select your desired YOLO11 model, set the confidence and [NMS thresholds](https://www.ultralytics.com/glossary/non-maximum-suppression-nms), and click the "Start" button to begin the real-time object detection.
You can optionally supply a specific model in Python:
!!! example "Streamlit Application with a custom model"
=== "Python"
```python
from ultralytics import solutions
inf = solutions.Inference(
model="yolo11n.pt", # you can use any model that Ultralytics support, i.e. YOLO11, YOLOv10
)
inf.inference()
# Make sure to run the file using command `streamlit run path/to/file.py`
```
## How It Works
Under the hood, the Streamlit application uses the [Ultralytics solutions module](https://docs.ultralytics.com/reference/solutions/streamlit_inference/) to create an interactive interface. When you start the inference, the application:

View File

@ -160,12 +160,19 @@ class Inference:
],
key=lambda x: (M_ORD.index(x[:7].lower()), T_ORD.index(x[7:].lower() or "")),
)
if self.model_path: # If user provided the custom model, insert model without suffix as *.pt is added later
available_models.insert(0, self.model_path.split(".pt", 1)[0])
if self.model_path: # Insert user provided custom model in available_models
available_models.insert(0, self.model_path)
selected_model = self.st.sidebar.selectbox("Model", available_models)
with self.st.spinner("Model is downloading..."):
self.model = YOLO(f"{selected_model.lower()}.pt") # Load the YOLO model
if (
selected_model.endswith((".pt", ".onnx", ".torchscript", ".mlpackage", ".engine"))
or "openvino_model" in selected_model
):
model_path = selected_model
else:
model_path = f"{selected_model.lower()}.pt" # Default to .pt if no model provided during function call.
self.model = YOLO(model_path) # Load the YOLO model
class_names = list(self.model.names.values()) # Convert dictionary to list of class names
self.st.success("Model loaded successfully!")