【pth如何转pt】

求解,怎么把yolov5训练好的pth模型文件转化成pt呀,我用的是B站Bubblii_iing的代码


import torch
from models.yolo import Model

def convert_to_torchscript(model_path, output_path):
    model = Model(model_path)
    model.eval()
    example_input = torch.rand(1, 3, 640, 640)
    traced_script_module = torch.jit.trace(model, example_input)
    traced_script_module.save(output_path)

if __name__ == "__main__":
    model_path = "path/to/your/weights.pth"  # 更改为你的模型文件路径
    output_path = "path/to/output/weights.pt"  # 更改为你想要保存 .pt 文件的路径
    convert_to_torchscript(model_path, output_path)