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

本站现有博文320篇,共被浏览755709

本站已经建立2418天!

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