ZhengPeng7
commited on
Update README.md
Browse files
README.md
CHANGED
@@ -52,6 +52,15 @@ Visit our GitHub repo: [https://github.com/ZhengPeng7/BiRefNet](https://github.c
|
|
52 |
|
53 |
### 1. Load BiRefNet:
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
#### Use codes from GitHub + weights from HuggingFace
|
56 |
> Only use the weights on HuggingFace -- Pro: codes are always latest; Con: Need to clone the BiRefNet repo from my GitHub.
|
57 |
|
@@ -64,16 +73,19 @@ cd BiRefNet
|
|
64 |
```python
|
65 |
# Load weights
|
66 |
from models.birefnet import BiRefNet
|
|
|
|
|
67 |
birefnet = BiRefNet.from_pretrained('zhengpeng7/birefnet')
|
68 |
-
```
|
69 |
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
-
```python
|
74 |
-
# Load BiRefNet with weights
|
75 |
-
from transformers import AutoModelForImageSegmentation
|
76 |
-
birefnet = AutoModelForImageSegmentation.from_pretrained('zhengpeng7/birefnet', trust_remote_code=True)
|
77 |
```
|
78 |
|
79 |
#### Use the loaded BiRefNet for inference
|
|
|
52 |
|
53 |
### 1. Load BiRefNet:
|
54 |
|
55 |
+
#### Use codes + weights from HuggingFace
|
56 |
+
> Only use the weights on HuggingFace -- Pro: No need to download BiRefNet codes manually; Con: Codes on HuggingFace might not be latest version (I'll try to keep them always latest).
|
57 |
+
|
58 |
+
```python
|
59 |
+
# Load BiRefNet with weights
|
60 |
+
from transformers import AutoModelForImageSegmentation
|
61 |
+
birefnet = AutoModelForImageSegmentation.from_pretrained('zhengpeng7/birefnet', trust_remote_code=True)
|
62 |
+
```
|
63 |
+
|
64 |
#### Use codes from GitHub + weights from HuggingFace
|
65 |
> Only use the weights on HuggingFace -- Pro: codes are always latest; Con: Need to clone the BiRefNet repo from my GitHub.
|
66 |
|
|
|
73 |
```python
|
74 |
# Load weights
|
75 |
from models.birefnet import BiRefNet
|
76 |
+
|
77 |
+
# Option-1: From Hugging Face Models
|
78 |
birefnet = BiRefNet.from_pretrained('zhengpeng7/birefnet')
|
|
|
79 |
|
80 |
+
# Option-2: From local disk
|
81 |
+
import torch
|
82 |
+
from utils import check_state_dict
|
83 |
+
|
84 |
+
birefnet = BiRefNet(bb_pretrained=False)
|
85 |
+
state_dict = torch.load(PATH_TO_WEIGHT, map_location='cpu')
|
86 |
+
state_dict = check_state_dict(state_dict)
|
87 |
+
birefnet.load_state_dict(state_dict)
|
88 |
|
|
|
|
|
|
|
|
|
89 |
```
|
90 |
|
91 |
#### Use the loaded BiRefNet for inference
|