EADST

Remove "module." from Pytorch pth dict

Sometimes, the model is trained with multiply graphic cards. The saved model has the prefix "module." in each key from the model dict. Here is the method to remove "module." from pth dict.

weight_path = "best_model.pth"
class_number = 5
model = mobilenetv2(width_mult=0.25)
model.classifier = nn.Linear(model.last_channel, class_number)
update_weights = {}
temp = torch.load(weight_path)
for key in temp.keys():
    update_weights[key[7:]] = temp[key]
model.load_state_dict(update_weights)
相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
版权 顶会 Password Miniforge Vmess GPT4 图标 搞笑 Proxy 继承 Card Datetime Anaconda Github TensorRT GIT CUDA Translation XML 报税 LeetCode UNIX 多线程 Freesound uWSGI PIP Transformers Distillation FlashAttention IndexTTS2 LaTeX Gemma ms-swift Hilton Safetensors Claude Heatmap Animate Windows 飞书 Paper ModelScope Disk Website SAM Nginx VPN HuggingFace 净利润 NLP DeepStream 财报 JSON Qwen2.5 Pickle Dataset SQL Base64 强化学习 BTC CEIR Pandas TSV tqdm diffusers GGML Knowledge 阿里云 OCR Pillow hf Markdown Input transformers ResNet-50 OpenAI Ubuntu Bitcoin API CSV RAR Conda Django PDF 云服务器 Qwen2 Quantize Michelin Math COCO XGBoost Image2Text 腾讯云 Bipartite BF16 v0.dev UI FastAPI Pytorch Clash mmap Search Linux Bert EXCEL DeepSeek Jupyter Data 图形思考法 ONNX Augmentation Agent 公式 SPIE TTS VSCode Domain Numpy Food BeautifulSoup SQLite Jetson PDB Cloudreve Quantization CC FP64 Zip Git Color News Attention Rebuttal WAN Tracking git Video CTC 多进程 CLAP LLAMA Land Llama VGG-16 Google Hotel YOLO git-lfs LoRA Qwen 论文 QWEN Permission NameSilo Bin CV WebCrawler Ptyhon HaggingFace llama.cpp FP16 PyTorch AI Hungarian tar Python LLM SVR Review 第一性原理 FP8 Tensor Statistics Tiktoken Plotly RGB 域名 GoogLeNet PyCharm C++ Paddle CAM Vim uwsgi GPTQ 递归学习法 论文速读 Magnet 证件照 Template Diagram Sklearn Web FP32 icon printf 音频 关于博主 Docker Mixtral Streamlit Use Crawler scipy Plate Firewall Excel Shortcut Logo InvalidArgumentError NLTK logger Interview Random 算法题 OpenCV Baidu MD5 v2ray Breakpoint ChatGPT torchinfo 签证 Algorithm TensorFlow
站点统计

本站现有博文329篇,共被浏览858560

本站已经建立2567天!

热门文章
文章归档
回到顶部