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

How to save model (export) upon program exit #13439

Open
1 task done
Mitutoyum opened this issue Nov 29, 2024 · 2 comments
Open
1 task done

How to save model (export) upon program exit #13439

Mitutoyum opened this issue Nov 29, 2024 · 2 comments
Labels
exports Model exports (ONNX, TensorRT, TFLite, etc.) question Further information is requested

Comments

@Mitutoyum
Copy link

Mitutoyum commented Nov 29, 2024

Search before asking

Question

How can i make yolo to automically export when the program exits? or atleast save it after each epoch

Additional

No response

@Mitutoyum Mitutoyum added the question Further information is requested label Nov 29, 2024
@UltralyticsAssistant UltralyticsAssistant added the exports Model exports (ONNX, TensorRT, TFLite, etc.) label Nov 29, 2024
@UltralyticsAssistant
Copy link
Member

👋 Hello @Mitutoyum, thank you for your interest in YOLOv5 🚀! Please review the YOLOv5 documentation and tutorials to explore solutions for tasks like exporting or saving models.

If this is a custom training ❓ Question, to assist you better, please provide as much information as possible, including details about your training process or any relevant logs. If your query relates to a specific feature like saving models, you may explore the available export options or saving checkpoints during training to ensure your progress is correctly handled.

If this is a potential 🐛 Bug Report, please share a minimum reproducible example that demonstrates the issue. This will help us better understand and debug your situation.

Requirements

Ensure you have Python 3.8.0 or newer installed along with all YOLOv5 dependencies, and verify compatibility with PyTorch 1.8 or greater.

Environments

YOLOv5 is designed to run on various platforms, including cloud notebooks, local machines, or containerized environments like Docker. Ensure all dependencies, including CUDA, Python, and PyTorch, are installed and up to date on your platform.

Status

To verify proper operation, run YOLOv5's training, validation, or inference pipelines in your selected environment. Ensure all tests pass successfully.

This is an automated response to help guide you in the right direction 😊. An Ultralytics team member will review and assist you further as soon as possible!

@pderrenger
Copy link
Member

@Mitutoyum to automatically export a YOLO model upon program exit, you can utilize Python's signal handling to trigger the export on exit. For example:

import signal
from ultralytics import YOLO

# Load your YOLO model
model = YOLO("path/to/best.pt")

# Define export function
def export_model(signal_received, frame):
    print("Exporting model on exit...")
    model.export(format="onnx")  # Change format as needed
    exit(0)

# Set up signal handler for graceful exit
signal.signal(signal.SIGINT, export_model)
signal.signal(signal.SIGTERM, export_model)

# Training process
model.train(data="data.yaml", epochs=10)

Alternatively, to save the model after each epoch, you can do so within the training loop by customizing the existing train() method. For further details on model export, refer to the Export Documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exports Model exports (ONNX, TensorRT, TFLite, etc.) question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants