Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,31 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import DetrForObjectDetection, DetrFeatureExtractor
|
| 3 |
-
|
| 4 |
|
| 5 |
-
# ๋ชจ๋ธ
|
| 6 |
model_id = "facebook/detr-resnet-50"
|
|
|
|
|
|
|
| 7 |
model = DetrForObjectDetection.from_pretrained(model_id)
|
| 8 |
feature_extractor = DetrFeatureExtractor.from_pretrained(model_id)
|
| 9 |
|
| 10 |
def object_detection(image):
|
| 11 |
-
# ์ด๋ฏธ์ง๋ฅผ ๋ชจ๋ธ
|
| 12 |
inputs = feature_extractor(images=image, return_tensors="pt")
|
| 13 |
outputs = model(**inputs)
|
| 14 |
|
| 15 |
-
# ๊ฒฐ๊ณผ ์ฒ๋ฆฌ
|
| 16 |
-
#
|
| 17 |
-
#
|
| 18 |
return outputs.logits.tolist()
|
| 19 |
|
| 20 |
-
# Gradio ์ธํฐํ์ด์ค
|
| 21 |
iface = gr.Interface(
|
| 22 |
fn=object_detection,
|
| 23 |
-
inputs=gr.Image(
|
| 24 |
outputs="json",
|
| 25 |
title="Object Detection with DETR",
|
| 26 |
-
description="Upload an image
|
| 27 |
)
|
| 28 |
|
| 29 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import DetrForObjectDetection, DetrFeatureExtractor
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
# ๋ชจ๋ธ ID ์ง์
|
| 6 |
model_id = "facebook/detr-resnet-50"
|
| 7 |
+
|
| 8 |
+
# ๋ชจ๋ธ๊ณผ ํผ์ฒ ์ถ์ถ๊ธฐ ๋ก๋
|
| 9 |
model = DetrForObjectDetection.from_pretrained(model_id)
|
| 10 |
feature_extractor = DetrFeatureExtractor.from_pretrained(model_id)
|
| 11 |
|
| 12 |
def object_detection(image):
|
| 13 |
+
# ์ด๋ฏธ์ง๋ฅผ ๋ชจ๋ธ ์
๋ ฅ์ผ๋ก ๋ณํ
|
| 14 |
inputs = feature_extractor(images=image, return_tensors="pt")
|
| 15 |
outputs = model(**inputs)
|
| 16 |
|
| 17 |
+
# ๊ฒฐ๊ณผ ์ฒ๋ฆฌ
|
| 18 |
+
# ์ฌ๊ธฐ์๋ ๊ฐ๋จํ ๋ชจ๋ธ์ ์ถ๋ ฅ logits๋ฅผ ๋ฆฌ์คํธ๋ก ๋ฐํํฉ๋๋ค.
|
| 19 |
+
# ์ค์ ์ ํ๋ฆฌ์ผ์ด์
์์๋ ์ถ๋ ฅ์ ์ฌ์ฉ์๊ฐ ์ดํดํ ์ ์๋ ํํ๋ก ๊ฐ๊ณตํด์ผ ํฉ๋๋ค.
|
| 20 |
return outputs.logits.tolist()
|
| 21 |
|
| 22 |
+
# Gradio ์ธํฐํ์ด์ค ์ ์ ๋ฐ ์คํ
|
| 23 |
iface = gr.Interface(
|
| 24 |
fn=object_detection,
|
| 25 |
+
inputs=gr.Image(),
|
| 26 |
outputs="json",
|
| 27 |
title="Object Detection with DETR",
|
| 28 |
+
description="Upload an image and the model will detect objects in the image."
|
| 29 |
)
|
| 30 |
|
| 31 |
iface.launch()
|