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

本站现有博文311篇,共被浏览742322

本站已经建立2382天!

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