Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video inference with YOLOv5 model in python #13269

Open
1 task done
mayurkatre18 opened this issue Aug 20, 2024 · 3 comments
Open
1 task done

Video inference with YOLOv5 model in python #13269

mayurkatre18 opened this issue Aug 20, 2024 · 3 comments
Labels
python Pull requests that update Python code question Further information is requested

Comments

@mayurkatre18
Copy link

mayurkatre18 commented Aug 20, 2024

Search before asking

Question

I have trained yolov5 model for instance segmentation and saved model in .pt format. Now I have to make video inference from this .pt model. Please provide me solution for this.
Thank you.

Additional

No response

@mayurkatre18 mayurkatre18 added the question Further information is requested label Aug 20, 2024
@UltralyticsAssistant UltralyticsAssistant added the python Pull requests that update Python code label Aug 20, 2024
@glenn-jocher
Copy link
Member

@mayurkatre18 to perform video inference with your YOLOv5 model, you can use the detect.py script. Here's a basic example:

python detect.py --weights your_model.pt --source your_video.mp4

Replace your_model.pt with your model's path and your_video.mp4 with your video file. For more details, refer to the YOLOv5 documentation.

@mayurkatre18
Copy link
Author

mayurkatre18 commented Aug 20, 2024

@glenn-jocher Thank you for above solution. But I have to perform it without detect.py file is their any solution for it in python.

And Important is I have to intergrate YOLOv5 model i.e. best.pt in mobile application which supports flutter language.

@glenn-jocher
Copy link
Member

@mayurkatre18 you can perform video inference directly in Python without using detect.py by leveraging the YOLOv5 model and OpenCV. Here's a minimal example:

import cv2
import torch

# Load model
model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt')

# Open video
cap = cv2.VideoCapture('your_video.mp4')

while cap.isOpened():
    ret, frame = cap.read()
    if not ret:
        break

    # Inference
    results = model(frame)

    # Display results
    results.show()

cap.release()
cv2.destroyAllWindows()

For integrating with a Flutter mobile application, you might consider exporting your model to a format supported by TensorFlow Lite. More details on model export can be found in the YOLOv5 documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Pull requests that update Python code question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants