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

本站现有博文327篇,共被浏览833613

本站已经建立2538天!

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