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

本站现有博文340篇,共被浏览1021391次

本站已经建立2719天!

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