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

本站现有博文321篇,共被浏览771638

本站已经建立2460天!

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