Spaces:
Runtime error
Runtime error
v1
Browse files
app.py
CHANGED
|
@@ -15,7 +15,9 @@ inpaint_model = inpaint.IVModel(device=device)
|
|
| 15 |
sod_model = sod.IVModel(device=torch.device("cpu"))
|
| 16 |
max_size=512
|
| 17 |
scale_factor = 8
|
|
|
|
| 18 |
def sod_inpaint(img):
|
|
|
|
| 19 |
h,w = img.shape[:2]
|
| 20 |
if max(h, w) > max_size:
|
| 21 |
if h < w:
|
|
@@ -27,16 +29,16 @@ def sod_inpaint(img):
|
|
| 27 |
img = cv2.resize(img, (w,h))
|
| 28 |
img = img[:,:,::-1]
|
| 29 |
res = sod_model.forward(img,None)
|
| 30 |
-
print('sod complete!')
|
| 31 |
res = np.uint8(res)
|
| 32 |
res = inpaint_model.forward(res,None)
|
| 33 |
res = np.uint8(res)
|
| 34 |
-
|
|
|
|
| 35 |
return res[:,:,::-1]
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
examples = glob.glob('examples/*.*')
|
| 40 |
inputs = gr.inputs.Image(shape=None, image_mode="RGB", invert_colors=False, source="upload", tool="editor", type="numpy", label=None, optional=False)
|
| 41 |
-
iface = gr.Interface(fn=sod_inpaint, inputs=inputs, outputs="image", examples=examples, title='Salient Object Detection + Inpaint', description='Upload
|
| 42 |
iface.launch()
|
|
|
|
| 15 |
sod_model = sod.IVModel(device=torch.device("cpu"))
|
| 16 |
max_size=512
|
| 17 |
scale_factor = 8
|
| 18 |
+
count = 0
|
| 19 |
def sod_inpaint(img):
|
| 20 |
+
global count
|
| 21 |
h,w = img.shape[:2]
|
| 22 |
if max(h, w) > max_size:
|
| 23 |
if h < w:
|
|
|
|
| 29 |
img = cv2.resize(img, (w,h))
|
| 30 |
img = img[:,:,::-1]
|
| 31 |
res = sod_model.forward(img,None)
|
|
|
|
| 32 |
res = np.uint8(res)
|
| 33 |
res = inpaint_model.forward(res,None)
|
| 34 |
res = np.uint8(res)
|
| 35 |
+
count +=1
|
| 36 |
+
print(count, ' images have been processed')
|
| 37 |
return res[:,:,::-1]
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
examples = glob.glob('examples/*.*')
|
| 42 |
inputs = gr.inputs.Image(shape=None, image_mode="RGB", invert_colors=False, source="upload", tool="editor", type="numpy", label=None, optional=False)
|
| 43 |
+
iface = gr.Interface(fn=sod_inpaint, inputs=inputs, outputs="image", examples=examples, title='Salient Object Detection + Inpaint', description='Upload an image and you will find something disappears', theme='huggingface')
|
| 44 |
iface.launch()
|