Mauricio Guerta commited on
Commit
34f0f30
1 Parent(s): ca4567f

Simplifica script

Browse files
app.py CHANGED
@@ -1,48 +1,27 @@
1
  import gradio as gr
2
  import os
3
- #os.system("pip -qq install yoloxdetect==0.0.7")
4
- #os.system("pip -qq install yoloxdetect")
5
  import torch
6
  import json
7
  import yoloxdetect2.helpers as yoloxdetect
8
- #from yoloxdetect import YoloxDetector
9
-
10
-
11
- # Images
12
- torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg', 'zidane.jpg')
13
- torch.hub.download_url_to_file('https://raw.githubusercontent.com/obss/sahi/main/tests/data/small-vehicles1.jpeg', 'small-vehicles1.jpeg')
14
- torch.hub.download_url_to_file('https://raw.githubusercontent.com/Megvii-BaseDetection/YOLOX/main/assets/dog.jpg', 'dog.jpg')
15
 
16
  model = yoloxdetect.YoloxDetector2('kadirnar/yolox_s-v0.1.1', 'configs.yolox_s', device="cpu", hf_model=True)
 
17
 
18
  def yolox_inference(
19
  image_path: gr.inputs.Image = None,
20
- model_path: gr.inputs.Dropdown = 'kadirnar/yolox_s-v0.1.1',
21
- config_path: gr.inputs.Textbox = 'configs.yolox_s',
22
- image_size: gr.inputs.Slider = 640
23
  ):
24
  """
25
  YOLOX inference function
26
  Args:
27
  image: Input image
28
- model_path: Path to the model
29
- config_path: Path to the config file
30
- image_size: Image size
31
  Returns:
32
  Rendered image
33
  """
34
 
35
- #model = YoloxDetector(model_path, config_path=config_path, device="cpu", hf_model=True)
36
- #pred = model.predict(image_path=image_path, image_size=image_size)
37
  pred2 = []
38
  if model :
39
  model.torchyolo = True
40
  pred2 = model.predict(image_path=image_path, image_size=image_size)
41
- #text = "Ola"
42
- #print (vars(model))
43
- #print (pred2[0])
44
- #print (pred2[1])
45
- #print (pred2[2])
46
 
47
 
48
  tensor = {
@@ -51,7 +30,6 @@ def yolox_inference(
51
  }
52
 
53
  if pred2 is not None:
54
- #print (pred2[3])
55
  for i, element in enumerate(pred2[0]):
56
  object = {}
57
  itemclass = round(pred2[2][i].item())
@@ -64,7 +42,6 @@ def yolox_inference(
64
  object["h"] = element[3].item()
65
  tensor["tensorflow"].append(object)
66
 
67
- #print(tensor)
68
 
69
  text = json.dumps(tensor)
70
  return text
@@ -72,18 +49,15 @@ def yolox_inference(
72
 
73
  inputs = [
74
  gr.inputs.Image(type="filepath", label="Input Image"),
75
- gr.inputs.Textbox(lines=1, label="Model Path", default="kadirnar/yolox_s-v0.1.1"),
76
- gr.inputs.Textbox(lines=1, label="Config Path", default="configs.yolox_s"),
77
- gr.inputs.Slider(minimum=320, maximum=1280, default=640, step=32, label="Image Size"),
78
  ]
79
 
80
  outputs = gr.outputs.Image(type="filepath", label="Output Image")
81
  title = "SIMULADOR PARA RECONHECIMENTO DE IMAGEM"
82
 
83
  examples = [
84
- ["small-vehicles1.jpeg", "kadirnar/yolox_m-v0.1.1", "configs.yolox_m", 640],
85
- ["zidane.jpg", "kadirnar/yolox_s-v0.1.1", "configs.yolox_s", 640],
86
- ["dog.jpg", "kadirnar/yolox_tiny-v0.1.1", "configs.yolox_tiny", 640],
87
  ]
88
 
89
  demo_app = gr.Interface(
@@ -94,7 +68,6 @@ demo_app = gr.Interface(
94
  examples=examples,
95
  cache_examples=True,
96
  live=True,
97
- theme='huggingface',
98
  )
99
  demo_app.launch(debug=True, server_name="192.168.0.153", server_port=8080, enable_queue=True)
100
  #demo_app.launch(debug=True, server_port=8083, enable_queue=True)
 
1
  import gradio as gr
2
  import os
 
 
3
  import torch
4
  import json
5
  import yoloxdetect2.helpers as yoloxdetect
 
 
 
 
 
 
 
6
 
7
  model = yoloxdetect.YoloxDetector2('kadirnar/yolox_s-v0.1.1', 'configs.yolox_s', device="cpu", hf_model=True)
8
+ image_size = 640
9
 
10
  def yolox_inference(
11
  image_path: gr.inputs.Image = None,
 
 
 
12
  ):
13
  """
14
  YOLOX inference function
15
  Args:
16
  image: Input image
 
 
 
17
  Returns:
18
  Rendered image
19
  """
20
 
 
 
21
  pred2 = []
22
  if model :
23
  model.torchyolo = True
24
  pred2 = model.predict(image_path=image_path, image_size=image_size)
 
 
 
 
 
25
 
26
 
27
  tensor = {
 
30
  }
31
 
32
  if pred2 is not None:
 
33
  for i, element in enumerate(pred2[0]):
34
  object = {}
35
  itemclass = round(pred2[2][i].item())
 
42
  object["h"] = element[3].item()
43
  tensor["tensorflow"].append(object)
44
 
 
45
 
46
  text = json.dumps(tensor)
47
  return text
 
49
 
50
  inputs = [
51
  gr.inputs.Image(type="filepath", label="Input Image"),
 
 
 
52
  ]
53
 
54
  outputs = gr.outputs.Image(type="filepath", label="Output Image")
55
  title = "SIMULADOR PARA RECONHECIMENTO DE IMAGEM"
56
 
57
  examples = [
58
+ ["small-vehicles1.jpeg"],
59
+ ["zidane.jpg"],
60
+ ["dog.jpg"],
61
  ]
62
 
63
  demo_app = gr.Interface(
 
68
  examples=examples,
69
  cache_examples=True,
70
  live=True,
 
71
  )
72
  demo_app.launch(debug=True, server_name="192.168.0.153", server_port=8080, enable_queue=True)
73
  #demo_app.launch(debug=True, server_port=8083, enable_queue=True)
configs/__pycache__/__init__.cpython-38.pyc CHANGED
Binary files a/configs/__pycache__/__init__.cpython-38.pyc and b/configs/__pycache__/__init__.cpython-38.pyc differ
 
configs/__pycache__/yolox_s.cpython-38.pyc CHANGED
Binary files a/configs/__pycache__/yolox_s.cpython-38.pyc and b/configs/__pycache__/yolox_s.cpython-38.pyc differ
 
yoloxdetect2/__pycache__/helpers.cpython-38.pyc CHANGED
Binary files a/yoloxdetect2/__pycache__/helpers.cpython-38.pyc and b/yoloxdetect2/__pycache__/helpers.cpython-38.pyc differ
 
yoloxdetect2/utils/__pycache__/downloads.cpython-38.pyc CHANGED
Binary files a/yoloxdetect2/utils/__pycache__/downloads.cpython-38.pyc and b/yoloxdetect2/utils/__pycache__/downloads.cpython-38.pyc differ