You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DroneDetector/train_scripts/PTH_to_PT.ipynb

56 lines
1.2 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "a89c0273",
"metadata": {},
"outputs": [],
"source": [
"import torch\n",
"import torchvision\n",
"\n",
"def convert_pth_to_pt(pth_path, pt_path, model_class):\n",
" state_dict = torch.load(pth_path)\n",
" model = model_class()\n",
" model.load_state_dict(state_dict)\n",
" torch.save(model, pt_path)\n",
" print(f'Model saved to {pt_path}')\n",
"\n",
"class ModelClass(torch.nn.Module):\n",
" def __init__(self):\n",
" super(ModelClass, self).__init__()\n",
"\n",
" def forward(self, x):\n",
" pass\n",
"\n",
"pth_path = 'model.pth'\n",
"pt_path = 'model.pt'\n",
"\n",
"convert_pth_to_pt(pth_path, pt_path, ModelClass)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}