bacngv commited on
Commit
62f974c
·
verified ·
1 Parent(s): 98878e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -20
app.py CHANGED
@@ -59,25 +59,10 @@ def predict_image(image, model, device, transform, threshold=0.5):
59
  label_names = [map_label_to_class(label.item()) for label in labels]
60
  drawn_image = draw_boxes_with_labels(image_uint8, boxes.cpu(), label_names)
61
 
62
- return drawn_image.permute(1, 2, 0) # Đảm bảo định dạng hình ảnh là (H, W, C)
63
-
64
- # Định nghĩa hàm get_transforms
65
- def get_transforms(train=False):
66
- if train:
67
- transform = A.Compose([
68
- A.Resize(800, 800), # Kích thước đầu vào 800px
69
- A.HorizontalFlip(p=0.3),
70
- A.VerticalFlip(p=0.3),
71
- A.RandomBrightnessContrast(p=0.1),
72
- A.ColorJitter(p=0.1),
73
- ToTensorV2()
74
- ], bbox_params=A.BboxParams(format='coco'))
75
- else:
76
- transform = A.Compose([
77
- A.Resize(800, 800), # Kích thước đầu vào 800px
78
- ToTensorV2()
79
- ], bbox_params=A.BboxParams(format='coco'))
80
- return transform
81
 
82
  # Tải mô hình
83
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
@@ -110,4 +95,4 @@ iface = gr.Interface(
110
 
111
  # Chạy ứng dụng
112
  if __name__ == "__main__":
113
- iface.launch(share=True) # Set share=True to create a public link
 
59
  label_names = [map_label_to_class(label.item()) for label in labels]
60
  drawn_image = draw_boxes_with_labels(image_uint8, boxes.cpu(), label_names)
61
 
62
+ # Convert tensor to PIL image for Gradio compatibility
63
+ drawn_image_pil = F.to_pil_image(drawn_image)
64
+
65
+ return np.array(drawn_image_pil) # Convert PIL image to NumPy array
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
  # Tải mô hình
68
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
95
 
96
  # Chạy ứng dụng
97
  if __name__ == "__main__":
98
+ iface.launch()