how_to_download_models_zh_cn.md 2.6 KB
Newer Older
1
2
3
4
# 如何下载模型文件

模型文件可以从Hugging Face 或 Model Scope 下载,由于网络原因,国内用户访问HF 可能会失败,请使用 ModelScope。

5

6
方法一:[从 Hugging Face 下载模型](#方法一从-hugging-face-下载模型)
7

8
方法二:[从 ModelScope 下载模型](#方法二从-modelscope-下载模型)
9

10
## 方法一:从 Hugging Face 下载模型
11

12
使用Git LFS 从Hugging Face下载模型文件
13
14

```bash
15
16
git lfs install # 安装 Git 大文件存储插件 (Git LFS) 
git lfs clone https://huggingface.co/wanderkid/PDF-Extract-Kit # 从 Hugging Face 下载 PDF-Extract-Kit 模型
17
18
19
```


20
21
## 方法二:从 ModelScope 下载模型
ModelScope 支持SDK或模型下载,任选一个即可。
22

23
24
25
[Git lsf下载](#1利用git-lsf下载)

[SDK下载](#2利用sdk下载)
26

27
28
29
30
31
32
### 1)利用Git lsf下载

```bash
git lfs install
git lfs clone https://www.modelscope.cn/wanderkid/PDF-Extract-Kit.git
```
33

34
### 2)利用SDK下载
35
36
37
38
39
40
41
42
43
44

```bash
# 首先安装modelscope
pip install modelscope
```

```python
# 使用modelscope sdk下载模型
from modelscope import snapshot_download
model_dir = snapshot_download('wanderkid/PDF-Extract-Kit')
45
print(f"模型文件下载路径为:{model_dir}")
46
47
```

48
## 额外步骤
49

50
### 1.检查模型目录是否下载完整
51
模型文件夹的结构如下,包含了不同组件的配置文件和权重文件:
52
53
```
./
54
├── Layout  # 布局检测模型
55
56
│   ├── config.json
│   └── model_final.pth
57
├── MFD  # 公式检测
58
│   └── weights.pt
59
├── MFR  # 公式识别模型
60
61
62
63
64
65
66
│   └── UniMERNet
│       ├── config.json
│       ├── preprocessor_config.json
│       ├── pytorch_model.bin
│       ├── README.md
│       ├── tokenizer_config.json
│       └── tokenizer.json
67
│── TabRec # 表格识别模型
68
69
70
71
72
73
74
75
76
│   └─StructEqTable
│       ├── config.json
│       ├── generation_config.json
│       ├── model.safetensors
│       ├── preprocessor_config.json
│       ├── special_tokens_map.json
│       ├── spiece.model
│       ├── tokenizer.json
│       └── tokenizer_config.json 
77
└── README.md
78
```
79
80
81
82
83
84

### 2.检查模型文件是否下载完整
请检查目录下的模型文件大小与网页上描述是否一致,如果可以的话,最好通过sha256校验模型是否下载完整

### 3.移动模型到固态硬盘
将 'models' 目录移动到具有较大磁盘空间的目录中,最好是在固态硬盘(SSD)上。
85
此外在 `~/magic-pdf.json`里修改模型的目录指向最终的模型存放位置,否则会报模型无法加载的错误。