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

本站现有博文339篇,共被浏览996009次

本站已经建立2706天!

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