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

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

本站已经建立2634天!

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