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

本站现有博文329篇,共被浏览858622

本站已经建立2567天!

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