Update README.md
Browse files
README.md
CHANGED
|
@@ -1,72 +1,73 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
tags:
|
| 4 |
-
- jax
|
| 5 |
-
- safetensors
|
| 6 |
-
---
|
| 7 |
-
|
| 8 |
-
# Baseline PerceptNet
|
| 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 Baseline as PerceptNet
|
| 32 |
-
```
|
| 33 |
-
|
| 34 |
-
### 2.Download the configuration
|
| 35 |
-
|
| 36 |
-
```
|
| 37 |
-
config_path = hf_hub_download(repo_id="Jorgvt/ppnet-baseline",
|
| 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-baseline",
|
| 51 |
-
filename="weights.safetensors")
|
| 52 |
-
variables = load_file(weights_path)
|
| 53 |
-
variables = flax.traverse_util.unflatten_dict(variables, sep=".")
|
| 54 |
-
params = variables["params"]
|
| 55 |
-
```
|
| 56 |
-
|
| 57 |
-
#### 3.2. Using `mgspack`
|
| 58 |
-
```
|
| 59 |
-
weights_path = hf_hub_download(repo_id="Jorgvt/ppnet-fully-trained",
|
| 60 |
-
filename="weights.msgpack")
|
| 61 |
-
with open(weights_path, "rb") as f:
|
| 62 |
-
variables = orbax.checkpoint.msgpack_utils.msgpack_restore(f.read())
|
| 63 |
-
variables = jax.tree_util.tree_map(lambda x: jnp.array(x), variables)
|
| 64 |
-
params = variables["params"]
|
| 65 |
-
```
|
| 66 |
-
|
| 67 |
-
### 4. Use the model
|
| 68 |
-
|
| 69 |
-
```
|
| 70 |
-
from jax import numpy as jnp
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
tags:
|
| 4 |
+
- jax
|
| 5 |
+
- safetensors
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
# Baseline PerceptNet
|
| 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 Baseline as PerceptNet
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
### 2.Download the configuration
|
| 35 |
+
|
| 36 |
+
```
|
| 37 |
+
config_path = hf_hub_download(repo_id="Jorgvt/ppnet-baseline",
|
| 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-baseline",
|
| 51 |
+
filename="weights.safetensors")
|
| 52 |
+
variables = load_file(weights_path)
|
| 53 |
+
variables = flax.traverse_util.unflatten_dict(variables, sep=".")
|
| 54 |
+
params = variables["params"]
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
#### 3.2. Using `mgspack`
|
| 58 |
+
```
|
| 59 |
+
weights_path = hf_hub_download(repo_id="Jorgvt/ppnet-fully-trained",
|
| 60 |
+
filename="weights.msgpack")
|
| 61 |
+
with open(weights_path, "rb") as f:
|
| 62 |
+
variables = orbax.checkpoint.msgpack_utils.msgpack_restore(f.read())
|
| 63 |
+
variables = jax.tree_util.tree_map(lambda x: jnp.array(x), variables)
|
| 64 |
+
params = variables["params"]
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
### 4. Use the model
|
| 68 |
+
|
| 69 |
+
```
|
| 70 |
+
from jax import numpy as jnp
|
| 71 |
+
model = PerceptNet(config)
|
| 72 |
+
pred = model.apply({"params": params}, jnp.ones((1,384,512,3)))
|
| 73 |
+
```
|