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

本站现有博文323篇,共被浏览796188

本站已经建立2493天!

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