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

本站现有博文333篇,共被浏览909389

本站已经建立2612天!

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