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

本站现有博文333篇,共被浏览922490

本站已经建立2628天!

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