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

本站现有博文332篇,共被浏览875934

本站已经建立2583天!

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