Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 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(
|
|
|
|
| 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()
|