Spaces:
Configuration error
Configuration error
Update app.py
Browse filessupport multitask
app.py
CHANGED
|
@@ -11,7 +11,7 @@ import torch
|
|
| 11 |
import numpy as np
|
| 12 |
import sys
|
| 13 |
import os
|
| 14 |
-
version = "YxZhang/evf-sam"
|
| 15 |
model_type = "ori"
|
| 16 |
|
| 17 |
tokenizer = AutoTokenizer.from_pretrained(
|
|
@@ -29,7 +29,7 @@ model.to('cuda')
|
|
| 29 |
|
| 30 |
@spaces.GPU
|
| 31 |
@torch.no_grad()
|
| 32 |
-
def pred(image_np, prompt):
|
| 33 |
original_size_list = [image_np.shape[:2]]
|
| 34 |
|
| 35 |
image_beit = beit3_preprocess(image_np, 224).to(dtype=model.dtype,
|
|
@@ -38,6 +38,8 @@ def pred(image_np, prompt):
|
|
| 38 |
image_sam, resize_shape = sam_preprocess(image_np, model_type=model_type)
|
| 39 |
image_sam = image_sam.to(dtype=model.dtype, device=model.device)
|
| 40 |
|
|
|
|
|
|
|
| 41 |
input_ids = tokenizer(
|
| 42 |
prompt, return_tensors="pt")["input_ids"].to(device=model.device)
|
| 43 |
|
|
@@ -79,7 +81,12 @@ demo = gr.Interface(
|
|
| 79 |
label="Prompt",
|
| 80 |
info=
|
| 81 |
"Use a phrase or sentence to describe the object you want to segment. Currently we only support English"
|
| 82 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
],
|
| 84 |
outputs=[
|
| 85 |
gr.components.Image(type="numpy", label="visulization"),
|
|
|
|
| 11 |
import numpy as np
|
| 12 |
import sys
|
| 13 |
import os
|
| 14 |
+
version = "YxZhang/evf-sam-multitask"
|
| 15 |
model_type = "ori"
|
| 16 |
|
| 17 |
tokenizer = AutoTokenizer.from_pretrained(
|
|
|
|
| 29 |
|
| 30 |
@spaces.GPU
|
| 31 |
@torch.no_grad()
|
| 32 |
+
def pred(image_np, prompt, semantic_type):
|
| 33 |
original_size_list = [image_np.shape[:2]]
|
| 34 |
|
| 35 |
image_beit = beit3_preprocess(image_np, 224).to(dtype=model.dtype,
|
|
|
|
| 38 |
image_sam, resize_shape = sam_preprocess(image_np, model_type=model_type)
|
| 39 |
image_sam = image_sam.to(dtype=model.dtype, device=model.device)
|
| 40 |
|
| 41 |
+
if semantic_type:
|
| 42 |
+
prompt = "[semantic] " + prompt
|
| 43 |
input_ids = tokenizer(
|
| 44 |
prompt, return_tensors="pt")["input_ids"].to(device=model.device)
|
| 45 |
|
|
|
|
| 81 |
label="Prompt",
|
| 82 |
info=
|
| 83 |
"Use a phrase or sentence to describe the object you want to segment. Currently we only support English"
|
| 84 |
+
),
|
| 85 |
+
gr.components.Checkbox(
|
| 86 |
+
False,
|
| 87 |
+
label="semantic level",
|
| 88 |
+
info="check this if you want to segment body parts or background or multi objects (only available with latest evf-sam checkpoint)"
|
| 89 |
+
),
|
| 90 |
],
|
| 91 |
outputs=[
|
| 92 |
gr.components.Image(type="numpy", label="visulization"),
|