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

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

本站已经建立2588天!

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