Update index.html
Browse files- index.html +12 -8
index.html
CHANGED
@@ -24,15 +24,19 @@ from transformers_js import import_transformers_js, as_url
|
|
24 |
import gradio as gr
|
25 |
|
26 |
|
|
|
|
|
27 |
transformers = await import_transformers_js()
|
28 |
AutoProcessor = transformers.AutoProcessor
|
29 |
AutoModel = transformers.AutoModel
|
30 |
RawImage = transformers.RawImage
|
31 |
|
32 |
-
processor = await AutoProcessor.from_pretrained('Xenova/yolov9-c')
|
33 |
-
|
|
|
|
|
34 |
|
35 |
-
model = await AutoModel.from_pretrained('Xenova/yolov9-c')
|
36 |
|
37 |
|
38 |
async def detect(image_path):
|
@@ -41,7 +45,7 @@ async def detect(image_path):
|
|
41 |
processed_input = await processor(image)
|
42 |
|
43 |
# Predict bounding boxes
|
44 |
-
result = await model(images=processed_input["pixel_values"])
|
45 |
|
46 |
outputs = result["outputs"] # Tensor
|
47 |
np_outputs = outputs.numpy() # [xmin, ymin, xmax, ymax, score, id][]
|
@@ -49,10 +53,10 @@ async def detect(image_path):
|
|
49 |
# List[Tuple[numpy.ndarray | Tuple[int, int, int, int], str]]
|
50 |
(
|
51 |
(
|
52 |
-
int(xmin),
|
53 |
-
int(ymin),
|
54 |
-
int(xmax),
|
55 |
-
int(ymax),
|
56 |
),
|
57 |
model.config.id2label[str(int(id))],
|
58 |
)
|
|
|
24 |
import gradio as gr
|
25 |
|
26 |
|
27 |
+
IMAGE_SIZE = 256;
|
28 |
+
|
29 |
transformers = await import_transformers_js()
|
30 |
AutoProcessor = transformers.AutoProcessor
|
31 |
AutoModel = transformers.AutoModel
|
32 |
RawImage = transformers.RawImage
|
33 |
|
34 |
+
processor = await AutoProcessor.from_pretrained('Xenova/yolov9-c')
|
35 |
+
|
36 |
+
# For this demo, we resize the image to IMAGE_SIZE x IMAGE_SIZE
|
37 |
+
processor.feature_extractor.size = { "width": IMAGE_SIZE, "height": IMAGE_SIZE }
|
38 |
|
39 |
+
model = await AutoModel.from_pretrained('Xenova/yolov9-c')
|
40 |
|
41 |
|
42 |
async def detect(image_path):
|
|
|
45 |
processed_input = await processor(image)
|
46 |
|
47 |
# Predict bounding boxes
|
48 |
+
result = await model(images=processed_input["pixel_values"])
|
49 |
|
50 |
outputs = result["outputs"] # Tensor
|
51 |
np_outputs = outputs.numpy() # [xmin, ymin, xmax, ymax, score, id][]
|
|
|
53 |
# List[Tuple[numpy.ndarray | Tuple[int, int, int, int], str]]
|
54 |
(
|
55 |
(
|
56 |
+
int(xmin * image.width / IMAGE_SIZE),
|
57 |
+
int(ymin * image.height / IMAGE_SIZE),
|
58 |
+
int(xmax * image.width / IMAGE_SIZE),
|
59 |
+
int(ymax * image.height / IMAGE_SIZE),
|
60 |
),
|
61 |
model.config.id2label[str(int(id))],
|
62 |
)
|