JosephTK commited on
Commit
9d9db66
1 Parent(s): 3602b81

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -7
app.py CHANGED
@@ -1,25 +1,33 @@
1
  import gradio as gr
2
- from transformers import YolosFeatureExtractor, YolosForObjectDetection
3
  import torch
4
 
5
- feature_extractor = YolosFeatureExtractor.from_pretrained('hustvl/yolos-small')
6
- model = YolosForObjectDetection.from_pretrained('hustvl/yolos-small')
7
 
8
  def detect(image):
9
  inputs = feature_extractor(images=image, return_tensors="pt")
10
  outputs = model(**inputs)
 
 
 
 
 
 
11
 
12
  # model predicts bounding boxes and corresponding COCO classes
13
- logits = outputs.logits
14
- bboxes = outputs.pred_boxes
15
 
16
- return outputs
 
17
 
 
18
 
19
  demo = gr.Interface(
20
  fn=detect,
21
  inputs=[gr.inputs.Image(label="Input image")],
22
- outputs=["text"],
23
  title="Object Counts in Image"
24
  )
25
 
 
1
  import gradio as gr
2
+ from transformers import AutoImageProcessor, AutoModelForObjectDetection
3
  import torch
4
 
5
+ image_processor = AutoImageProcessor.from_pretrained('hustvl/yolos-small')
6
+ model = AutoModelForObjectDetection.from_pretrained('hustvl/yolos-small')
7
 
8
  def detect(image):
9
  inputs = feature_extractor(images=image, return_tensors="pt")
10
  outputs = model(**inputs)
11
+
12
+ # convert outputs to COCO API
13
+ target_sizes = torch.tensor([image.size[::-1]])
14
+ results = image_processor.post_process_object_detection(outputs,
15
+ threshold=0.9,
16
+ target_sizes=target_sizes)[0]
17
 
18
  # model predicts bounding boxes and corresponding COCO classes
19
+ #logits = outputs.logits
20
+ #bboxes = outputs.pred_boxes
21
 
22
+ # label and the count
23
+ counts = {}
24
 
25
+ return results
26
 
27
  demo = gr.Interface(
28
  fn=detect,
29
  inputs=[gr.inputs.Image(label="Input image")],
30
+ outputs=["text"]#, gr.Label(num_top_classes=10)],
31
  title="Object Counts in Image"
32
  )
33