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

本站现有博文332篇,共被浏览882990

本站已经建立2588天!

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