Instructions to use hazhu/mlx-deepdanbooru with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use hazhu/mlx-deepdanbooru with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] hf download hazhu/mlx-deepdanbooru --local-dir mlx-deepdanbooru
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
hazhu commited on
Commit ·
7b69884
1
Parent(s): 1b61398
README.md
CHANGED
|
@@ -57,31 +57,27 @@ Image Interrogate:
|
|
| 57 |
|
| 58 |
```python
|
| 59 |
import numpy as np
|
| 60 |
-
from PIL import Image
|
| 61 |
|
| 62 |
# using apple silicon's MLX
|
| 63 |
# not Pytorch
|
| 64 |
import mlx.core as mx
|
| 65 |
from mlxDeepDanBooru.mlx_deep_danbooru_model import mlxDeepDanBooruModel
|
| 66 |
|
| 67 |
-
|
| 68 |
model_path = "models/model-resnet_custom_v3_fp32_mlx.safetensors"
|
| 69 |
-
|
| 70 |
|
| 71 |
mlx_dan = mlxDeepDanBooruModel()
|
| 72 |
mlx_dan.load_weights(model_path)
|
| 73 |
mx.eval(mlx_dan.parameters())
|
| 74 |
|
| 75 |
-
|
| 76 |
-
model_tags = np.load(tags_path)
|
| 77 |
-
print(f'total tags: {len(model_tags)}')
|
| 78 |
-
|
| 79 |
def danbooru_tags(fpath):
|
| 80 |
tags = []
|
| 81 |
-
pic = Image.open(fpath).convert("RGB").resize((512, 512))
|
| 82 |
-
a = np.expand_dims(np.array(pic, dtype=np.float32), 0) / 255
|
| 83 |
|
| 84 |
try:
|
|
|
|
|
|
|
|
|
|
| 85 |
x = mx.array(a)
|
| 86 |
y = mlx_dan(x)[0]
|
| 87 |
for i, p in enumerate(y):
|
|
@@ -91,31 +87,23 @@ def danbooru_tags(fpath):
|
|
| 91 |
tags.append(model_tags[i].item())
|
| 92 |
except Exception as err:
|
| 93 |
print(err)
|
|
|
|
| 94 |
|
| 95 |
return tags
|
| 96 |
|
| 97 |
-
image_count = 0
|
| 98 |
def image_infer(fpath):
|
| 99 |
-
global image_count
|
| 100 |
tags = danbooru_tags(fpath)
|
| 101 |
-
image_count += 1
|
| 102 |
return tags
|
| 103 |
|
| 104 |
-
|
| 105 |
-
t1 = time.time()
|
| 106 |
tags_1 = image_infer("example/1.png")
|
| 107 |
tags_2 = image_infer("example/2.png")
|
| 108 |
|
| 109 |
-
t2 = time.time()
|
| 110 |
-
|
| 111 |
print(tags_1)
|
| 112 |
# will show tags: ['1girl', 'beach', 'black_hair', 'blurry', 'blurry_background', 'blurry_foreground', 'building', 'bush', 'christmas_tree', 'day', 'depth_of_field', 'field', 'grass', 'lake', 'looking_at_viewer', 'mountain', 'nature', 'outdoors', 'palm_leaf', 'palm_tree', 'park', 'park_bench', 'path', 'photo_background', 'plant', 'river', 'road', 'skirt', 'sky', 'smile', 'striped', 'striped_dress', 'striped_shirt', 'tree', 'vertical-striped_shirt', 'vertical_stripes', 'rating:safe']
|
| 113 |
|
| 114 |
print(tags_2)
|
| 115 |
# will show tags: ['1girl', '3d', 'blurry', 'blurry_background', 'blurry_foreground', 'brown_eyes', 'brown_hair', 'bush', 'christmas_tree', 'cosplay_photo', 'day', 'depth_of_field', 'field', 'floral_print', 'foliage', 'forest', 'garden', 'grass', 'jungle', 'lips', 'long_hair', 'long_sleeves', 'looking_at_viewer', 'nature', 'on_grass', 'outdoors', 'palm_tree', 'park', 'path', 'plant', 'potted_plant', 'realistic', 'smile', 'solo', 'tree', 'upper_body', 'white_dress', 'rating:safe']
|
| 116 |
|
| 117 |
-
print("-----------")
|
| 118 |
-
print(f'infer speed(with mlx): {(t2 - t1)/image_count} seconds per image')
|
| 119 |
```
|
| 120 |
|
| 121 |
|
|
|
|
| 57 |
|
| 58 |
```python
|
| 59 |
import numpy as np
|
| 60 |
+
from PIL import Image
|
| 61 |
|
| 62 |
# using apple silicon's MLX
|
| 63 |
# not Pytorch
|
| 64 |
import mlx.core as mx
|
| 65 |
from mlxDeepDanBooru.mlx_deep_danbooru_model import mlxDeepDanBooruModel
|
| 66 |
|
|
|
|
| 67 |
model_path = "models/model-resnet_custom_v3_fp32_mlx.safetensors"
|
| 68 |
+
model_tags = np.load('models/tags-resnet_custom_v3_mlx.npy')
|
| 69 |
|
| 70 |
mlx_dan = mlxDeepDanBooruModel()
|
| 71 |
mlx_dan.load_weights(model_path)
|
| 72 |
mx.eval(mlx_dan.parameters())
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
def danbooru_tags(fpath):
|
| 75 |
tags = []
|
|
|
|
|
|
|
| 76 |
|
| 77 |
try:
|
| 78 |
+
pic = Image.open(fpath).convert("RGB").resize((512, 512))
|
| 79 |
+
a = np.expand_dims(np.array(pic, dtype=np.float32), 0) / 255
|
| 80 |
+
#
|
| 81 |
x = mx.array(a)
|
| 82 |
y = mlx_dan(x)[0]
|
| 83 |
for i, p in enumerate(y):
|
|
|
|
| 87 |
tags.append(model_tags[i].item())
|
| 88 |
except Exception as err:
|
| 89 |
print(err)
|
| 90 |
+
tags = []
|
| 91 |
|
| 92 |
return tags
|
| 93 |
|
|
|
|
| 94 |
def image_infer(fpath):
|
|
|
|
| 95 |
tags = danbooru_tags(fpath)
|
|
|
|
| 96 |
return tags
|
| 97 |
|
|
|
|
|
|
|
| 98 |
tags_1 = image_infer("example/1.png")
|
| 99 |
tags_2 = image_infer("example/2.png")
|
| 100 |
|
|
|
|
|
|
|
| 101 |
print(tags_1)
|
| 102 |
# will show tags: ['1girl', 'beach', 'black_hair', 'blurry', 'blurry_background', 'blurry_foreground', 'building', 'bush', 'christmas_tree', 'day', 'depth_of_field', 'field', 'grass', 'lake', 'looking_at_viewer', 'mountain', 'nature', 'outdoors', 'palm_leaf', 'palm_tree', 'park', 'park_bench', 'path', 'photo_background', 'plant', 'river', 'road', 'skirt', 'sky', 'smile', 'striped', 'striped_dress', 'striped_shirt', 'tree', 'vertical-striped_shirt', 'vertical_stripes', 'rating:safe']
|
| 103 |
|
| 104 |
print(tags_2)
|
| 105 |
# will show tags: ['1girl', '3d', 'blurry', 'blurry_background', 'blurry_foreground', 'brown_eyes', 'brown_hair', 'bush', 'christmas_tree', 'cosplay_photo', 'day', 'depth_of_field', 'field', 'floral_print', 'foliage', 'forest', 'garden', 'grass', 'jungle', 'lips', 'long_hair', 'long_sleeves', 'looking_at_viewer', 'nature', 'on_grass', 'outdoors', 'palm_tree', 'park', 'path', 'plant', 'potted_plant', 'realistic', 'smile', 'solo', 'tree', 'upper_body', 'white_dress', 'rating:safe']
|
| 106 |
|
|
|
|
|
|
|
| 107 |
```
|
| 108 |
|
| 109 |
|