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

本站现有博文322篇,共被浏览789107

本站已经建立2484天!

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