Blessing commited on
Commit
0bdf57c
1 Parent(s): 8510c14

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -28
app.py CHANGED
@@ -7,50 +7,49 @@ import random
7
  from ultralytics import YOLO
8
 
9
  file_urls = [
10
- 'https://www.dropbox.com/scl/fi/34yt1vrl4mc4n9ujdf9gm/all_76.jpg?rlkey=f7b6nq478r2m9yahcalzjzif5&dl=1',
11
- 'https://www.dropbox.com/scl/fi/lns6cewinp7rgf3v2g1n8/all_5.jpg?rlkey=20zvut81b829k9lg5yk8ve99z&dl=1',
12
- 'https://www.dropbox.com/scl/fi/13jr2f1znuzulmsyabl2f/long3.jpg?rlkey=jeyriw5a8c0t42e7y2986y53m&dl=1',
13
- 'https://www.dropbox.com/scl/fi/nglwcza7msjo1vu4kw27r/pot4.jpg?rlkey=1ynm35b4j100ta0p5g3fx7hx4&dl=1',
14
- 'https://www.dropbox.com/s/7sjfwncffg8xej2/video_7.mp4?dl=1'
15
  ]
16
 
17
- # def download_file(url, save_name):
18
- # url = url
19
- # if not os.path.exists(save_name):
20
- # file = requests.get(url)
21
- # open(save_name, 'wb').write(file.content)
22
 
23
- # for i, url in enumerate(file_urls):
24
- # if 'mp4' in file_urls[i]:
25
- # download_file(
26
- # file_urls[i],
27
- # f"video.mp4"
28
- # )
29
- # else:
30
- # download_file(
31
- # file_urls[i],
32
- # f"image_{i}.jpg"
33
- # )
34
 
35
 
36
  model = YOLO('best.pt')
37
- # path = [['image_0.jpg'], ['image_1.jpg'], ['image_2.jpg'], ['image_3.jpg']]
38
 
39
- path = [['IMG_7612.JPG'], ['IMG_7678.JPG'], ['all_33.jpg'], ['all_80.jpg'],
40
- ['DSC02813.JPG'], ['DSC02373.JPG']]
41
 
42
 
43
  # path = [['sc_1_0 (1) (1).JPG'], ['sc_1_0 (16) (1).JPG'],
44
  # ['sc_1_0 (18) (1).JPG'], ['sc_1_0 (18).JPG']]
45
 
46
- video_path = [['VID-20230809-WA0021.mp4'], ['VID-20230809-WA0022.mp4'],
47
- ['VID-20230809-WA0024.mp4'], ['VID-20230809-WA0032.mp4']]
48
 
49
  classes = ['alligator_cracking', 'longitudinal_cracking', 'potholes', 'ravelling']
50
 
51
  def show_preds_image(image_path):
52
  image = cv2.imread(image_path)
53
- outputs = model.predict(source=image_path, agnostic_nms=True, conf=0.25, iou=0.4, imgsz=1024)
54
  results = outputs[0].cpu().numpy()
55
 
56
  re_boxes = results.boxes.data.tolist()
@@ -118,7 +117,7 @@ def show_preds_video(video_path):
118
  ret, frame = cap.read()
119
  if ret:
120
  frame_copy = frame.copy()
121
- outputs = model.predict(source=frame, agnostic_nms=True, conf=0.25, iou=0.4, imgsz=1024)
122
  results = outputs[0].cpu().numpy()
123
  re_boxes = results.boxes.data.tolist()
124
 
 
7
  from ultralytics import YOLO
8
 
9
  file_urls = [
10
+ 'https://www.dropbox.com/scl/fi/5pavu4vvkprrtkwktvei7/DSC02373.JPG?rlkey=fpj636qtkf3vrqfxy45n2d9ii&dl=1',
11
+ 'https://www.dropbox.com/scl/fi/56pbn4r3ohk85rchcvwdj/DSC02813.JPG?rlkey=jnbsidqtthk6p4ysld6o6kc4t&dl=1',
12
+ 'https://www.dropbox.com/scl/fi/av9g5zbmrrzg9064zivat/image_2.jpg?rlkey=ldocvzz5lq98zffqf1lmhbhv1&dl=1',
13
+ 'https://www.dropbox.com/scl/fi/izo2eqqnqzcsaxis1qrbx/IMG_7612.JPG?rlkey=6wfjaux44khtlx454ex0ng0hp&dl=1',
14
+ 'https://www.dropbox.com/scl/fi/e6vgy1et6vjr61uypk5yu/VID-20230809-WA0021.mp4?rlkey=khv8rw074vezzlg8ob38bpmbx&dl=1'
15
  ]
16
 
17
+ def download_file(url, save_name):
18
+ url = url
19
+ if not os.path.exists(save_name):
20
+ file = requests.get(url)
21
+ open(save_name, 'wb').write(file.content)
22
 
23
+ for i, url in enumerate(file_urls):
24
+ if 'mp4' in file_urls[i]:
25
+ download_file(
26
+ file_urls[i],
27
+ f"video.mp4"
28
+ )
29
+ else:
30
+ download_file(
31
+ file_urls[i],
32
+ f"image_{i}.jpg"
33
+ )
34
 
35
 
36
  model = YOLO('best.pt')
37
+ path = [['image_0.jpg'], ['image_1.jpg'], ['image_2.jpg'], ['image_3.jpg']]
38
 
39
+ # path = [['IMG_7612.JPG'], ['IMG_7678.JPG'], ['all_33.jpg'], ['all_80.jpg'],
40
+ # ['DSC02813.JPG'], ['DSC02373.JPG']]
41
 
42
 
43
  # path = [['sc_1_0 (1) (1).JPG'], ['sc_1_0 (16) (1).JPG'],
44
  # ['sc_1_0 (18) (1).JPG'], ['sc_1_0 (18).JPG']]
45
 
46
+ video_path = [['video.mp4']]
 
47
 
48
  classes = ['alligator_cracking', 'longitudinal_cracking', 'potholes', 'ravelling']
49
 
50
  def show_preds_image(image_path):
51
  image = cv2.imread(image_path)
52
+ outputs = model.predict(source=image_path, agnostic_nms=True, conf=0.25, iou=0.4, imgsz=640)
53
  results = outputs[0].cpu().numpy()
54
 
55
  re_boxes = results.boxes.data.tolist()
 
117
  ret, frame = cap.read()
118
  if ret:
119
  frame_copy = frame.copy()
120
+ outputs = model.predict(source=frame, agnostic_nms=True, conf=0.25, iou=0.4, imgsz=640)
121
  results = outputs[0].cpu().numpy()
122
  re_boxes = results.boxes.data.tolist()
123