oldgarden21 commited on
Commit
8a80b35
ยท
verified ยท
1 Parent(s): eeae096

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -1,29 +1,31 @@
1
  import gradio as gr
2
  from transformers import DetrForObjectDetection, DetrFeatureExtractor
3
- from PIL import Image
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
- # ์—ฌ๊ธฐ์„œ๋Š” outputs์˜ ์š”์•ฝ๋œ ์ •๋ณด๋งŒ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
18
  return outputs.logits.tolist()
19
 
20
- # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ • ๋ฐ ์•ฑ ์‹คํ–‰
21
  iface = gr.Interface(
22
  fn=object_detection,
23
- inputs=gr.Image(shape=(512, 512)),
24
  outputs="json",
25
  title="Object Detection with DETR",
26
- description="Upload an image, and the model will detect objects in the 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()