stphtan94117 commited on
Commit
563db0d
·
1 Parent(s): 447656b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -69
app.py CHANGED
@@ -28,45 +28,19 @@ for i, url in enumerate(file_urls):
28
  f"image_{i}.jpg"
29
  )
30
 
31
- model = YOLO('crack.pt')
32
  path = [['image_0.jpg'], ['image_1.jpg']]
33
  video_path = [['video.mp4']]
34
 
35
- # def show_preds_image(image_path):
36
- # image = cv2.imread(image_path)
37
- # outputs = model.predict(source=image_path)
38
- # results = outputs[0].cpu().numpy()
39
- # for i, det in enumerate(results.boxes.xyxy):
40
- # cv2.rectangle(
41
- # image,
42
- # (int(det[0]), int(det[1])),
43
- # (int(det[2]), int(det[3])),
44
- # color=(0, 0, 255),
45
- # thickness=2,
46
- # lineType=cv2.LINE_AA
47
- # )
48
- # return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
49
-
50
- def show_preds_image(path:str):
51
- model = YOLO("crack.pt")
52
- image = cv2.imread(path)
53
-
54
- image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
55
- results = model.predict(source=path)
56
- paleta= sns.color_palette("bright", 17)
57
- fig = plt.figure()
58
- vectObjs = results[0].masks.xy
59
- resNumClase = results[0].boxes.cls.numpy().astype(int)
60
- conf = results[0].boxes.conf.numpy()
61
- for i in range(len(vectObjs)):
62
- objDet = vectObjs[i].astype(int)
63
- color = (paleta[i][0]*255, paleta[i][1]*255, paleta[i][2]*255)
64
- image = cv2.polylines(image, [objDet], True, color, 4)
65
- plt.text(objDet[0][0], objDet[0][1], results[0].names[resNumClase[i]]+" "+ str(conf[i]), bbox=dict(facecolor=paleta[i], alpha=0.5))
66
 
67
- plt.imshow(image)
68
- plt.axis('off')
69
- return plt
70
 
71
  inputs_image = [
72
  gr.components.Image(type="filepath", label="Input Image"),
@@ -83,40 +57,6 @@ interface_image = gr.Interface(
83
  cache_examples=False,
84
  )
85
 
86
- # def show_preds_video(video_path):
87
- # cap = cv2.VideoCapture(video_path)
88
- # while(cap.isOpened()):
89
- # ret, frame = cap.read()
90
- # if ret:
91
- # frame_copy = frame.copy()
92
- # outputs = model.predict(source=frame)
93
- # results = outputs[0].cpu().numpy()
94
- # for i, det in enumerate(results.boxes.xyxy):
95
- # cv2.rectangle(
96
- # frame_copy,
97
- # (int(det[0]), int(det[1])),
98
- # (int(det[2]), int(det[3])),
99
- # color=(0, 0, 255),
100
- # thickness=2,
101
- # lineType=cv2.LINE_AA
102
- # )
103
- # yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
104
-
105
- # inputs_video = [
106
- # gr.components.Video(type="filepath", label="Input Video"),
107
-
108
- # ]
109
- # outputs_video = [
110
- # gr.components.Image(type="numpy", label="Output Image"),
111
- # ]
112
- # interface_video = gr.Interface(
113
- # fn=show_preds_video,
114
- # inputs=inputs_video,
115
- # outputs=outputs_video,
116
- # title="Pothole detector",
117
- # examples=video_path,
118
- # cache_examples=False,
119
- # )
120
 
121
  gr.TabbedInterface(
122
  [interface_image],
 
28
  f"image_{i}.jpg"
29
  )
30
 
31
+ # model = YOLO('crack.pt')
32
  path = [['image_0.jpg'], ['image_1.jpg']]
33
  video_path = [['video.mp4']]
34
 
35
+ def show_preds_image(source):
36
+ global model
37
+ res = model(source, conf=.5, iou=.5)
38
+ res_plotted = res[0].plot()
39
+ # converting BGR to RGB
40
+ result = cv2.cvtColor(res_plotted, cv2.COLOR_BGR2RGB)
41
+ return result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
+ model = YOLO("crack.pt") # Select YOLO model
 
 
44
 
45
  inputs_image = [
46
  gr.components.Image(type="filepath", label="Input Image"),
 
57
  cache_examples=False,
58
  )
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
  gr.TabbedInterface(
62
  [interface_image],