Spaces:
Running
on
Zero
Running
on
Zero
changes for zeroGPU
Browse files
app.py
CHANGED
@@ -1,11 +1,15 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
|
|
3 |
|
4 |
from chrislib.general import uninvert, invert, view, view_scale
|
5 |
|
6 |
from intrinsic.pipeline import load_models, run_pipeline
|
7 |
|
8 |
-
|
|
|
|
|
9 |
|
10 |
def generate_pipeline(models):
|
11 |
|
@@ -17,11 +21,12 @@ def generate_pipeline(models):
|
|
17 |
|
18 |
pipeline_func = generate_pipeline(intrinsic_models)
|
19 |
|
|
|
20 |
def process_image(image):
|
21 |
print(image.shape)
|
22 |
image = image.astype(np.single) / 255.
|
23 |
|
24 |
-
result = pipeline_func(image, device=
|
25 |
|
26 |
return [view(result['hr_alb']), 1 - invert(result['dif_shd']), view_scale(result['pos_res'])]
|
27 |
|
|
|
1 |
+
import spaces
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
+
impot torch
|
5 |
|
6 |
from chrislib.general import uninvert, invert, view, view_scale
|
7 |
|
8 |
from intrinsic.pipeline import load_models, run_pipeline
|
9 |
|
10 |
+
DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
11 |
+
|
12 |
+
intrinsic_models = load_models('v2', device=DEVICE)
|
13 |
|
14 |
def generate_pipeline(models):
|
15 |
|
|
|
21 |
|
22 |
pipeline_func = generate_pipeline(intrinsic_models)
|
23 |
|
24 |
+
@spaces.GPU
|
25 |
def process_image(image):
|
26 |
print(image.shape)
|
27 |
image = image.astype(np.single) / 255.
|
28 |
|
29 |
+
result = pipeline_func(image, device=DEVICE)
|
30 |
|
31 |
return [view(result['hr_alb']), 1 - invert(result['dif_shd']), view_scale(result['pos_res'])]
|
32 |
|