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

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

本站已经建立2534天!

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