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

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

本站已经建立2439天!

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