Update README.md with new model card content
Browse files
README.md
CHANGED
|
@@ -1,17 +1,62 @@
|
|
| 1 |
---
|
| 2 |
library_name: keras-hub
|
| 3 |
---
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
library_name: keras-hub
|
| 3 |
---
|
| 4 |
+
### Model Overview
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
## Example Usage
|
| 8 |
+
```python
|
| 9 |
+
import keras
|
| 10 |
+
import numpy as np
|
| 11 |
+
import requests
|
| 12 |
+
from PIL import Image
|
| 13 |
+
|
| 14 |
+
from keras_hub.src.models.depth_anything.depth_anything_depth_estimator import (
|
| 15 |
+
DepthAnythingDepthEstimator,
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
|
| 19 |
+
image = image.resize((518, 518))
|
| 20 |
+
depth_estimator = DepthAnythingDepthEstimator.from_preset(
|
| 21 |
+
"depth_anything_v2_base,
|
| 22 |
+
depth_estimation_type="relative",
|
| 23 |
+
max_depth=None,
|
| 24 |
+
)
|
| 25 |
+
images = np.expand_dims(np.array(image).astype("float32"), axis=0)
|
| 26 |
+
outputs = depth_estimator.predict({"images": images})["depths"]
|
| 27 |
+
depth = keras.ops.nn.relu(outputs[0, ..., 0])
|
| 28 |
+
depth = (depth - keras.ops.min(depth)) / (
|
| 29 |
+
keras.ops.max(depth) - keras.ops.min(depth)
|
| 30 |
+
)
|
| 31 |
+
depth = keras.ops.convert_to_numpy(depth) * 255
|
| 32 |
+
Image.fromarray(depth.astype("uint8")).save("depth_map.png")
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
## Example Usage with Hugging Face URI
|
| 36 |
+
|
| 37 |
+
```python
|
| 38 |
+
import keras
|
| 39 |
+
import numpy as np
|
| 40 |
+
import requests
|
| 41 |
+
from PIL import Image
|
| 42 |
+
|
| 43 |
+
from keras_hub.src.models.depth_anything.depth_anything_depth_estimator import (
|
| 44 |
+
DepthAnythingDepthEstimator,
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
|
| 48 |
+
image = image.resize((518, 518))
|
| 49 |
+
depth_estimator = DepthAnythingDepthEstimator.from_preset(
|
| 50 |
+
"depth_anything_v2_base,
|
| 51 |
+
depth_estimation_type="relative",
|
| 52 |
+
max_depth=None,
|
| 53 |
+
)
|
| 54 |
+
images = np.expand_dims(np.array(image).astype("float32"), axis=0)
|
| 55 |
+
outputs = depth_estimator.predict({"images": images})["depths"]
|
| 56 |
+
depth = keras.ops.nn.relu(outputs[0, ..., 0])
|
| 57 |
+
depth = (depth - keras.ops.min(depth)) / (
|
| 58 |
+
keras.ops.max(depth) - keras.ops.min(depth)
|
| 59 |
+
)
|
| 60 |
+
depth = keras.ops.convert_to_numpy(depth) * 255
|
| 61 |
+
Image.fromarray(depth.astype("uint8")).save("depth_map.png")
|
| 62 |
+
```
|