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

本站现有博文324篇,共被浏览809125

本站已经建立2512天!

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