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

本站现有博文337篇,共被浏览961669次

本站已经建立2673天!

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