Download code/tt_paddleocr/tt/weights.py from changh95/PaddleOCR-VL: direct link, hf CLI and curl.
- Browser
- Download file 750 Bytes
-
https://huggingface.co/changh95/PaddleOCR-VL/resolve/main/code/tt_paddleocr/tt/weights.py
- Command line
-
hf download hf://changh95/PaddleOCR-VL/code/tt_paddleocr/tt/weights.py
-
curl -L -o weights.py https://huggingface.co/changh95/PaddleOCR-VL/resolve/main/code/tt_paddleocr/tt/weights.py
750 Bytes
| # SPDX-License-Identifier: Apache-2.0 | |
| """Checkpoint loading (CPU): model.safetensors -> {name: tensor} (bf16 as stored; the pooling head and the unused | |
| packing position table are skipped).""" | |
| from __future__ import annotations | |
| import os | |
| from typing import Dict | |
| import torch | |
| SKIP = ("visual.vision_model.head.", "visual.vision_model.embeddings.packing_position_embedding") | |
| def load_weights(path: str) -> Dict[str, torch.Tensor]: | |
| from safetensors import safe_open | |
| p = os.path.join(path, "model.safetensors") if os.path.isdir(path) else path | |
| out = {} | |
| with safe_open(p, framework="pt") as f: | |
| for k in f.keys(): | |
| if k.startswith(SKIP): | |
| continue | |
| out[k] = f.get_tensor(k) | |
| return out | |