Spaces:
Running
Running
narugo1992
commited on
Commit
•
08d41dd
1
Parent(s):
ac3ec97
dev(narugo): remove usage of cv2
Browse files- app.py +1 -1
- nudenet.py +11 -16
- requirements.txt +0 -1
app.py
CHANGED
@@ -139,7 +139,7 @@ if __name__ == '__main__':
|
|
139 |
label='Zooming')
|
140 |
with gr.Row():
|
141 |
sd_f_breast = gr.Checkbox(value=False, label='Female\'s Breast')
|
142 |
-
sd_f_breast_zoom = gr.Slider(value=0.
|
143 |
label='Zooming')
|
144 |
with gr.Row():
|
145 |
sd_m_penis = gr.Checkbox(value=True, label='Male\'s Penis')
|
|
|
139 |
label='Zooming')
|
140 |
with gr.Row():
|
141 |
sd_f_breast = gr.Checkbox(value=False, label='Female\'s Breast')
|
142 |
+
sd_f_breast_zoom = gr.Slider(value=0.9, minimum=0.1, maximum=3.0, step=0.05,
|
143 |
label='Zooming')
|
144 |
with gr.Row():
|
145 |
sd_m_penis = gr.Checkbox(value=True, label='Male\'s Penis')
|
nudenet.py
CHANGED
@@ -2,14 +2,13 @@ from functools import lru_cache
|
|
2 |
from pathlib import Path
|
3 |
from typing import Tuple, List
|
4 |
|
5 |
-
import cv2
|
6 |
import numpy as np
|
7 |
import onnxruntime
|
8 |
from PIL import Image
|
9 |
from huggingface_hub import hf_hub_download
|
10 |
|
11 |
|
12 |
-
def
|
13 |
""" Read an image in BGR format.
|
14 |
Args
|
15 |
path: Path to the image.
|
@@ -25,31 +24,27 @@ def _preprocess_image(x) -> np.ndarray:
|
|
25 |
return x.astype(np.float32) - CAFFE_MASK
|
26 |
|
27 |
|
28 |
-
def
|
29 |
-
|
30 |
-
smallest_side = min(
|
|
|
31 |
|
32 |
scale = min_side / smallest_side
|
33 |
-
largest_side = max(rows, cols)
|
34 |
if largest_side * scale > max_side:
|
35 |
scale = max_side / largest_side
|
36 |
|
37 |
return scale
|
38 |
|
39 |
|
40 |
-
def resize_image(img, min_side=800, max_side=1333):
|
41 |
-
scale = compute_resize_scale(img.shape, min_side=min_side, max_side=max_side)
|
42 |
-
img = cv2.resize(img, None, fx=scale, fy=scale)
|
43 |
-
return img, scale
|
44 |
-
|
45 |
-
|
46 |
def preprocess_image(
|
47 |
image: Image.Image, min_side=800, max_side=1333,
|
48 |
):
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
53 |
|
54 |
|
55 |
FILE_URLS = {
|
|
|
2 |
from pathlib import Path
|
3 |
from typing import Tuple, List
|
4 |
|
|
|
5 |
import numpy as np
|
6 |
import onnxruntime
|
7 |
from PIL import Image
|
8 |
from huggingface_hub import hf_hub_download
|
9 |
|
10 |
|
11 |
+
def _read_bgr_data(image) -> np.ndarray:
|
12 |
""" Read an image in BGR format.
|
13 |
Args
|
14 |
path: Path to the image.
|
|
|
24 |
return x.astype(np.float32) - CAFFE_MASK
|
25 |
|
26 |
|
27 |
+
def _get_resize_scale(size, min_side=800, max_side=1333):
|
28 |
+
width, height = size
|
29 |
+
smallest_side = min(width, height)
|
30 |
+
largest_side = max(width, height)
|
31 |
|
32 |
scale = min_side / smallest_side
|
|
|
33 |
if largest_side * scale > max_side:
|
34 |
scale = max_side / largest_side
|
35 |
|
36 |
return scale
|
37 |
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
def preprocess_image(
|
40 |
image: Image.Image, min_side=800, max_side=1333,
|
41 |
):
|
42 |
+
width, height = image.size
|
43 |
+
scale = _get_resize_scale((width, height), min_side=min_side, max_side=max_side)
|
44 |
+
new_width, new_height = map(lambda x: int(x * scale), (width, height))
|
45 |
+
data = _read_bgr_data(image.resize((new_width, new_height)))
|
46 |
+
data = _preprocess_image(data)
|
47 |
+
return data, scale
|
48 |
|
49 |
|
50 |
FILE_URLS = {
|
requirements.txt
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
pillow
|
2 |
-
opencv-python
|
3 |
numpy
|
4 |
gradio==3.16.2
|
5 |
huggingface_hub
|
|
|
1 |
pillow
|
|
|
2 |
numpy
|
3 |
gradio==3.16.2
|
4 |
huggingface_hub
|