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

本站现有博文332篇,共被浏览875881

本站已经建立2583天!

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