Update README.md
Browse files
README.md
CHANGED
@@ -1,74 +1,75 @@
|
|
1 |
-
---
|
2 |
-
license: apache-2.0
|
3 |
-
tags:
|
4 |
-
- jax
|
5 |
-
- safetensors
|
6 |
-
---
|
7 |
-
|
8 |
-
# Parametric PerceptNet Bio-Fitted
|
9 |
-
|
10 |
-
## Model Description
|
11 |
-
|
12 |
-
## How to use it
|
13 |
-
|
14 |
-
### Install the model's package from source:
|
15 |
-
```
|
16 |
-
git clone https://github.com/Jorgvt/paramperceptnet.git
|
17 |
-
cd paramperceptnet
|
18 |
-
pip install -e .
|
19 |
-
```
|
20 |
-
|
21 |
-
### 1.Import necessary libraries:
|
22 |
-
|
23 |
-
```
|
24 |
-
import json
|
25 |
-
|
26 |
-
from huggingface_hub import hf_hub_download
|
27 |
-
import flax
|
28 |
-
import orbax.checkpoint
|
29 |
-
from ml_collections import ConfigDict
|
30 |
-
|
31 |
-
from paramperceptnet.models import PerceptNet
|
32 |
-
```
|
33 |
-
|
34 |
-
### 2.Download the configuration
|
35 |
-
|
36 |
-
```
|
37 |
-
config_path = hf_hub_download(repo_id="Jorgvt/ppnet-bio-fitted",
|
38 |
-
filename="config.json")
|
39 |
-
with open(config_path, "r") as f:
|
40 |
-
config = ConfigDict(json.load(f))
|
41 |
-
```
|
42 |
-
|
43 |
-
### 3. Download the weights
|
44 |
-
|
45 |
-
#### 3.1. Using `safetensors`
|
46 |
-
|
47 |
-
```
|
48 |
-
from safetensors.flax import load_file
|
49 |
-
|
50 |
-
weights_path = hf_hub_download(repo_id="Jorgvt/ppnet-bio-fitted",
|
51 |
-
filename="weights.safetensors")
|
52 |
-
variables = load_file(weights_path)
|
53 |
-
variables = flax.traverse_util.unflatten_dict(variables, sep=".")
|
54 |
-
state = variables["state"]
|
55 |
-
params = variables["params"]
|
56 |
-
```
|
57 |
-
|
58 |
-
#### 3.2. Using `mgspack`
|
59 |
-
```
|
60 |
-
weights_path = hf_hub_download(repo_id="Jorgvt/ppnet-bio-fitted",
|
61 |
-
filename="weights.msgpack")
|
62 |
-
with open(weights_path, "rb") as f:
|
63 |
-
variables = orbax.checkpoint.msgpack_utils.msgpack_restore(f.read())
|
64 |
-
variables = jax.tree_util.tree_map(lambda x: jnp.array(x), variables)
|
65 |
-
state = variables["state"]
|
66 |
-
params = variables["params"]
|
67 |
-
```
|
68 |
-
|
69 |
-
### 4. Use the model
|
70 |
-
|
71 |
-
```
|
72 |
-
from jax import numpy as jnp
|
73 |
-
|
74 |
-
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
tags:
|
4 |
+
- jax
|
5 |
+
- safetensors
|
6 |
+
---
|
7 |
+
|
8 |
+
# Parametric PerceptNet Bio-Fitted
|
9 |
+
|
10 |
+
## Model Description
|
11 |
+
|
12 |
+
## How to use it
|
13 |
+
|
14 |
+
### Install the model's package from source:
|
15 |
+
```
|
16 |
+
git clone https://github.com/Jorgvt/paramperceptnet.git
|
17 |
+
cd paramperceptnet
|
18 |
+
pip install -e .
|
19 |
+
```
|
20 |
+
|
21 |
+
### 1.Import necessary libraries:
|
22 |
+
|
23 |
+
```
|
24 |
+
import json
|
25 |
+
|
26 |
+
from huggingface_hub import hf_hub_download
|
27 |
+
import flax
|
28 |
+
import orbax.checkpoint
|
29 |
+
from ml_collections import ConfigDict
|
30 |
+
|
31 |
+
from paramperceptnet.models import PerceptNet
|
32 |
+
```
|
33 |
+
|
34 |
+
### 2.Download the configuration
|
35 |
+
|
36 |
+
```
|
37 |
+
config_path = hf_hub_download(repo_id="Jorgvt/ppnet-bio-fitted",
|
38 |
+
filename="config.json")
|
39 |
+
with open(config_path, "r") as f:
|
40 |
+
config = ConfigDict(json.load(f))
|
41 |
+
```
|
42 |
+
|
43 |
+
### 3. Download the weights
|
44 |
+
|
45 |
+
#### 3.1. Using `safetensors`
|
46 |
+
|
47 |
+
```
|
48 |
+
from safetensors.flax import load_file
|
49 |
+
|
50 |
+
weights_path = hf_hub_download(repo_id="Jorgvt/ppnet-bio-fitted",
|
51 |
+
filename="weights.safetensors")
|
52 |
+
variables = load_file(weights_path)
|
53 |
+
variables = flax.traverse_util.unflatten_dict(variables, sep=".")
|
54 |
+
state = variables["state"]
|
55 |
+
params = variables["params"]
|
56 |
+
```
|
57 |
+
|
58 |
+
#### 3.2. Using `mgspack`
|
59 |
+
```
|
60 |
+
weights_path = hf_hub_download(repo_id="Jorgvt/ppnet-bio-fitted",
|
61 |
+
filename="weights.msgpack")
|
62 |
+
with open(weights_path, "rb") as f:
|
63 |
+
variables = orbax.checkpoint.msgpack_utils.msgpack_restore(f.read())
|
64 |
+
variables = jax.tree_util.tree_map(lambda x: jnp.array(x), variables)
|
65 |
+
state = variables["state"]
|
66 |
+
params = variables["params"]
|
67 |
+
```
|
68 |
+
|
69 |
+
### 4. Use the model
|
70 |
+
|
71 |
+
```
|
72 |
+
from jax import numpy as jnp
|
73 |
+
model = PerceptNet(config)
|
74 |
+
pred = model.apply({"params": params, **state}, jnp.ones((1,384,512,3)))
|
75 |
+
```
|