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

Is possible to converting a .pt PyTorch model to a .pth file ? #13478

Open
1 task done
CPrasa opened this issue Dec 31, 2024 · 2 comments
Open
1 task done

Is possible to converting a .pt PyTorch model to a .pth file ? #13478

CPrasa opened this issue Dec 31, 2024 · 2 comments
Labels
exports Model exports (ONNX, TensorRT, TFLite, etc.) question Further information is requested

Comments

@CPrasa
Copy link

CPrasa commented Dec 31, 2024

Search before asking

Question

Is possible to converting a .pt PyTorch model to a .pth file ?

Additional

No response

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

👋 Hello @CPrasa, thank you for your interest in YOLOv5 🚀! Converting a .pt PyTorch model to a .pth file is an interesting question.

If this is a ❓ Question, please provide as much detail as possible about your use case or requirements. This will help us provide better guidance. If this is a 🐛 Bug Report, we kindly request a minimum reproducible example (MRE) to help us debug and assist you more effectively.

Requirements

Ensure you are using Python>=3.8.0 and have all required dependencies installed, including PyTorch>=1.8. To set up YOLOv5:

git clone the repository from the source  # clone
cd into the yolov5 directory
pip install required dependencies listed in requirements.txt

Environments

YOLOv5 can run on various verified environments including Jupyter Notebooks with free GPU runtime, cloud platforms like Google Cloud or AWS, or in a Docker environment with pre-installed dependencies.

Status

You can check the status of YOLOv5's integrations, including training, validation, and inference workflows, to ensure functionality is operational.

This is an automated response to help guide you, but no worries—a human Ultralytics engineer will take a closer look and assist you further soon! 😊

@pderrenger
Copy link
Member

@CPrasa yes, a .pt PyTorch model can be converted to a .pth file as both formats are interchangeable and represent serialized PyTorch models. You can achieve this by loading the .pt model using PyTorch and saving it directly as a .pth file using torch.save. Here's an example:

import torch

# Load the .pt model
model = torch.load('model.pt')

# Save as .pth
torch.save(model, 'model.pth')

Let me know if you encounter any issues!

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