Koni commited on
Commit
c865dfa
·
1 Parent(s): c79c7e9

Test for working layout

Browse files
Files changed (2) hide show
  1. app.py +30 -28
  2. requirements.txt +2 -45
app.py CHANGED
@@ -1,16 +1,16 @@
1
  import gradio as gr
2
- import spaces
3
  from huggingface_hub import hf_hub_download
4
  import os
5
 
6
  # make sure you have the following dependencies
7
- import torch
8
  import numpy as np
9
- from models.common import DetectMultiBackend
10
- from utils.general import non_max_suppression, scale_boxes
11
- from utils.torch_utils import select_device, smart_inference_mode
12
- from utils.augmentations import letterbox
13
- import PIL.Image
14
 
15
  #@smart_inference_mode()
16
  @spaces.GPU
@@ -27,33 +27,35 @@ def yolov9_inference(img_path, model_id='YOLOv9-S_X_LOCO-converted.pt', img_size
27
  :return: A tuple containing the detections (boxes, scores, categories) and the results object for further actions like displaying.
28
  """
29
 
30
- # Load the model
31
- model_path = download_models(model_id)
32
 
33
- # Initialize
34
- device = select_device('0')
35
- model = DetectMultiBackend(model_path, device="0", fp16=False, data='data/coco.yaml')
36
- stride, names, pt = model.stride, model.names, model.pt
37
 
38
- # Load image
39
- img = np.array(PIL.Image.open(img_path))
40
- img = letterbox(img0, img_size, stride=stride, auto=True)[0]
41
- img = img[:, :, ::-1].transpose(2, 0, 1)
42
- img = np.ascontiguousarray(img)
43
- img = torch.from_numpy(img).to(device).float()
44
- img /= 255.0
45
- if img.ndimension() == 3:
46
- img = img.unsqueeze(0)
47
 
48
- # Inference
49
- results = model(img, augment=False, visualize=False)
 
 
 
 
 
 
 
50
 
51
- # Apply NMS
52
- results = non_max_suppression(results[0][0], conf_thres, iou_thres, classes=None, max_det=1000)
53
 
54
- output = results.render()
 
55
 
56
- return output[0]
 
 
57
 
58
 
59
 
 
1
  import gradio as gr
2
+ # import spaces
3
  from huggingface_hub import hf_hub_download
4
  import os
5
 
6
  # make sure you have the following dependencies
7
+ # import torch
8
  import numpy as np
9
+ # from models.common import DetectMultiBackend
10
+ # from utils.general import non_max_suppression, scale_boxes
11
+ # from utils.torch_utils import select_device, smart_inference_mode
12
+ # from utils.augmentations import letterbox
13
+ # import PIL.Image
14
 
15
  #@smart_inference_mode()
16
  @spaces.GPU
 
27
  :return: A tuple containing the detections (boxes, scores, categories) and the results object for further actions like displaying.
28
  """
29
 
30
+ return np.array(PIL.Image.open(img_path))
 
31
 
32
+ # # Load the model
33
+ # model_path = download_models(model_id)
 
 
34
 
35
+ # # Initialize
36
+ # device = select_device('0')
37
+ # model = DetectMultiBackend(model_path, device="0", fp16=False, data='data/coco.yaml')
38
+ # stride, names, pt = model.stride, model.names, model.pt
 
 
 
 
 
39
 
40
+ # # Load image
41
+ # img = np.array(PIL.Image.open(img_path))
42
+ # img = letterbox(img0, img_size, stride=stride, auto=True)[0]
43
+ # img = img[:, :, ::-1].transpose(2, 0, 1)
44
+ # img = np.ascontiguousarray(img)
45
+ # img = torch.from_numpy(img).to(device).float()
46
+ # img /= 255.0
47
+ # if img.ndimension() == 3:
48
+ # img = img.unsqueeze(0)
49
 
50
+ # # Inference
51
+ # results = model(img, augment=False, visualize=False)
52
 
53
+ # # Apply NMS
54
+ # results = non_max_suppression(results[0][0], conf_thres, iou_thres, classes=None, max_det=1000)
55
 
56
+ # output = results.render()
57
+
58
+ # return output[0]
59
 
60
 
61
 
requirements.txt CHANGED
@@ -1,49 +1,6 @@
1
  # requirements
2
  # Usage: pip install -r requirements.txt
3
 
4
- # Base ------------------------------------------------------------------------
5
- gitpython
6
- ipython
7
- matplotlib>=3.2.2
8
- numpy>=1.18.5
9
- opencv-python>=4.1.1
10
- Pillow>=7.1.2, <10.0.0
11
- psutil
12
- PyYAML>=5.3.1
13
- requests>=2.23.0
14
- scipy>=1.4.1
15
- thop>=0.1.1
16
- torch>=1.7.0
17
- torchvision>=0.8.1
18
- tqdm>=4.64.0
19
- # protobuf<=3.20.1
20
-
21
- # Logging ---------------------------------------------------------------------
22
- tensorboard>=2.4.1
23
- # clearml>=1.2.0
24
- # comet
25
-
26
- # Plotting --------------------------------------------------------------------
27
- pandas>=1.1.4
28
- seaborn>=0.11.0
29
-
30
- # Export ----------------------------------------------------------------------
31
- # coremltools>=6.0
32
- # onnx>=1.9.0
33
- # onnx-simplifier>=0.4.1
34
- # nvidia-pyindex
35
- # nvidia-tensorrt
36
- # scikit-learn<=1.1.2
37
- # tensorflow>=2.4.1
38
- # tensorflowjs>=3.9.0
39
- # openvino-dev
40
-
41
- # Deploy ----------------------------------------------------------------------
42
- # tritonclient[all]~=2.24.0
43
- git+https://github.com/KoniHD/yolov9.git@main#egg=yolov9
44
  huggingface_hub
45
-
46
- # Extras ----------------------------------------------------------------------
47
- # mss
48
- albumentations>=1.0.3
49
- pycocotools>=2.0
 
1
  # requirements
2
  # Usage: pip install -r requirements.txt
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  huggingface_hub
5
+ ultralytics
6
+ numpy>=1.18.5