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

本站现有博文337篇,共被浏览951714次

本站已经建立2662天!

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