Spaces:
Runtime error
Runtime error
Commit ·
baa0e1d
1
Parent(s): 85ccb18
Working version 1
Browse files- app.py +24 -4
- examples/image00998.jpg_RESAMPLED_57958afc1dddb17a_scaled.png +0 -0
- examples/image06458.jpg_RESAMPLED_5305f3a8b83a73fd_scaled_scaled.png +0 -0
- examples/image1.jpg +0 -0
- examples/image2.jpg +0 -0
- examples/image29477.jpg_RESAMPLED_70ada8cd855e57e0_scaled_scaled.png +0 -0
- examples/image29675.jpg_RESAMPLED_7b41aeb60f83fffa_scaled.png +0 -0
- examples/image32475.jpg_RESAMPLED_e8e7afef30663d1e_scaled.png +0 -0
- requirements.txt +3 -2
- resnet18_5epochs.pkl +3 -0
app.py
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastai.vision.all import *
|
| 2 |
import gradio as gr
|
| 3 |
+
import numpy as np
|
| 4 |
+
from skimage import color
|
| 5 |
|
| 6 |
+
# import pathlib
|
| 7 |
+
# temp = pathlib.PosixPath
|
| 8 |
+
# pathlib.PosixPath = pathlib.WindowsPath
|
| 9 |
|
| 10 |
+
def get_label(filepath):
|
| 11 |
+
return None
|
| 12 |
+
|
| 13 |
+
learn = load_learner("resnet18_5epochs.pkl")
|
| 14 |
+
|
| 15 |
+
def segment(img):
|
| 16 |
+
mask, _, _ = learn.predict(img)
|
| 17 |
+
result = color.label2rgb(np.array(mask),img, colors=['red', 'green', 'blue', 'chocolate', 'cyan', 'purple', 'yellow', 'darkorange', 'turquoise', 'lime'] , bg_label=0)
|
| 18 |
+
return result
|
| 19 |
+
|
| 20 |
+
TITLE = "Pixel-level Face Segmentation"
|
| 21 |
+
DESCRIPTION = "Resnet18 fine-tuned for face features segmentation via fastai and Mut1ny's Face Segmentation Dataset"
|
| 22 |
+
INPUT = gr.Image(shape=(224, 224))
|
| 23 |
+
OUTPUT = gr.ImageMask(shape=(224, 224), label='Resnet18')
|
| 24 |
+
EXAMPLES = [f for f in pathlib.Path('examples').iterdir()]
|
| 25 |
+
|
| 26 |
+
intf = gr.Interface(fn=segment, inputs=INPUT, outputs=OUTPUT, examples=EXAMPLES, title=TITLE, description=DESCRIPTION)
|
| 27 |
+
intf.launch(inline=False)
|
examples/image00998.jpg_RESAMPLED_57958afc1dddb17a_scaled.png
ADDED
|
examples/image06458.jpg_RESAMPLED_5305f3a8b83a73fd_scaled_scaled.png
ADDED
|
examples/image1.jpg
ADDED
|
examples/image2.jpg
ADDED
|
examples/image29477.jpg_RESAMPLED_70ada8cd855e57e0_scaled_scaled.png
ADDED
|
examples/image29675.jpg_RESAMPLED_7b41aeb60f83fffa_scaled.png
ADDED
|
examples/image32475.jpg_RESAMPLED_e8e7afef30663d1e_scaled.png
ADDED
|
requirements.txt
CHANGED
|
@@ -1,9 +1,10 @@
|
|
| 1 |
pip
|
|
|
|
| 2 |
torch
|
| 3 |
gradio
|
| 4 |
Pillow
|
| 5 |
imageio
|
| 6 |
torchvision
|
| 7 |
opencv_python
|
| 8 |
-
|
| 9 |
-
|
|
|
|
| 1 |
pip
|
| 2 |
+
numpy = 1.21.6
|
| 3 |
torch
|
| 4 |
gradio
|
| 5 |
Pillow
|
| 6 |
imageio
|
| 7 |
torchvision
|
| 8 |
opencv_python
|
| 9 |
+
tqdm
|
| 10 |
+
fastai
|
resnet18_5epochs.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:15524ef73b50041924c98e233ba4f61e0965c194da3f10fa666cbd8bf7e52808
|
| 3 |
+
size 129432459
|