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

本站现有博文338篇,共被浏览972289次

本站已经建立2685天!

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