ZJF-Thunder commited on
Commit
4c710ed
1 Parent(s): e26e560

添加文件

Browse files
.gitignore CHANGED
@@ -20,7 +20,7 @@ parts/
20
  sdist/
21
  var/
22
  wheels/
23
- *.egg-info/
24
  .installed.cfg
25
  *.egg
26
  MANIFEST
@@ -113,9 +113,9 @@ venv.bak/
113
  *.pkl
114
  *.pkl.json
115
  *.log.json
116
- work_dirs/
117
 
118
  # Pytorch
119
- *.pth
120
  *.py~
121
  *.sh~
 
20
  sdist/
21
  var/
22
  wheels/
23
+ #*.egg-info/
24
  .installed.cfg
25
  *.egg
26
  MANIFEST
 
113
  *.pkl
114
  *.pkl.json
115
  *.log.json
116
+ #work_dirs/
117
 
118
  # Pytorch
119
+ #*.pth
120
  *.py~
121
  *.sh~
demo/1.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:de01ef2f627f1d9cb07fd3a4706c6263ba5cc01c31780875994d5e08768aac4a
3
+ size 3414636
demo/2.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:de01ef2f627f1d9cb07fd3a4706c6263ba5cc01c31780875994d5e08768aac4a
3
+ size 3414636
demo/27.jpg ADDED

Git LFS Details

  • SHA256: 69b1ce6d57e0e1b9d587bf4312a3234f2eeab1212d13d5b4835e09f2b3f61add
  • Pointer size: 131 Bytes
  • Size of remote file: 131 kB
demo/3.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8c7b5c369303a095a28cc6c63fd7ea275135fd3636db8f30bae038548b74c000
3
+ size 2833382
demo/30.jpg ADDED

Git LFS Details

  • SHA256: e05a504c45eb933ea1dce333cdec75f44572754f3c61e2b2502bf84db2cc1d3a
  • Pointer size: 131 Bytes
  • Size of remote file: 167 kB
demo/31.jpg ADDED

Git LFS Details

  • SHA256: b36f63c82d1f3c7b7b586e18f925ec823b29ca524f2338ce1085d662d9c0c312
  • Pointer size: 131 Bytes
  • Size of remote file: 157 kB
demo/4.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2c6349db8e2ca67d4f480f88024bb1caae7bb45f53468991f28a8d3e5ece4438
3
+ size 2510028
demo/40.jpg ADDED

Git LFS Details

  • SHA256: 7f1fda1b8dd8ca53aacdae3780036de6207595b35643eaafb90f09a84a466931
  • Pointer size: 130 Bytes
  • Size of remote file: 97.8 kB
demo/6.jpg ADDED

Git LFS Details

  • SHA256: 5a0883d0e8773b0717c4e89e5719aeace55f1d8f14884984bab837a623a51732
  • Pointer size: 131 Bytes
  • Size of remote file: 388 kB
demo/MMDet_Tutorial.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
demo/create_result_gif.py ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import os
3
+ import os.path as osp
4
+
5
+ import matplotlib.patches as mpatches
6
+ import matplotlib.pyplot as plt
7
+ import mmcv
8
+ import numpy as np
9
+
10
+ try:
11
+ import imageio
12
+ except ImportError:
13
+ imageio = None
14
+
15
+
16
+ def parse_args():
17
+ parser = argparse.ArgumentParser(description='Create GIF for demo')
18
+ parser.add_argument(
19
+ 'image_dir',
20
+ help='directory where result '
21
+ 'images save path generated by ‘analyze_results.py’')
22
+ parser.add_argument(
23
+ '--out',
24
+ type=str,
25
+ default='result.gif',
26
+ help='gif path where will be saved')
27
+ args = parser.parse_args()
28
+ return args
29
+
30
+
31
+ def _generate_batch_data(sampler, batch_size):
32
+ batch = []
33
+ for idx in sampler:
34
+ batch.append(idx)
35
+ if len(batch) == batch_size:
36
+ yield batch
37
+ batch = []
38
+ if len(batch) > 0:
39
+ yield batch
40
+
41
+
42
+ def create_gif(frames, gif_name, duration=2):
43
+ """Create gif through imageio.
44
+
45
+ Args:
46
+ frames (list[ndarray]): Image frames
47
+ gif_name (str): Saved gif name
48
+ duration (int): Display interval (s),
49
+ Default: 2
50
+ """
51
+ if imageio is None:
52
+ raise RuntimeError('imageio is not installed,'
53
+ 'Please use “pip install imageio” to install')
54
+ imageio.mimsave(gif_name, frames, 'GIF', duration=duration)
55
+
56
+
57
+ def create_frame_by_matplotlib(image_dir,
58
+ nrows=1,
59
+ fig_size=(300, 300),
60
+ font_size=15):
61
+ """Create gif frame image through matplotlib.
62
+
63
+ Args:
64
+ image_dir (str): Root directory of result images
65
+ nrows (int): Number of rows displayed, Default: 1
66
+ fig_size (tuple): Figure size of the pyplot figure.
67
+ Default: (300, 300)
68
+ font_size (int): Font size of texts. Default: 15
69
+
70
+ Returns:
71
+ list[ndarray]: image frames
72
+ """
73
+
74
+ result_dir_names = os.listdir(image_dir)
75
+ assert len(result_dir_names) == 2
76
+ # Longer length has higher priority
77
+ result_dir_names.reverse()
78
+
79
+ images_list = []
80
+ for dir_names in result_dir_names:
81
+ images_list.append(mmcv.scandir(osp.join(image_dir, dir_names)))
82
+
83
+ frames = []
84
+ for paths in _generate_batch_data(zip(*images_list), nrows):
85
+
86
+ fig, axes = plt.subplots(nrows=nrows, ncols=2)
87
+ fig.suptitle('Good/bad case selected according '
88
+ 'to the COCO mAP of the single image')
89
+
90
+ det_patch = mpatches.Patch(color='salmon', label='prediction')
91
+ gt_patch = mpatches.Patch(color='royalblue', label='ground truth')
92
+ # bbox_to_anchor may need to be finetuned
93
+ plt.legend(
94
+ handles=[det_patch, gt_patch],
95
+ bbox_to_anchor=(1, -0.18),
96
+ loc='lower right',
97
+ borderaxespad=0.)
98
+
99
+ if nrows == 1:
100
+ axes = [axes]
101
+
102
+ dpi = fig.get_dpi()
103
+ # set fig size and margin
104
+ fig.set_size_inches(
105
+ (fig_size[0] * 2 + fig_size[0] // 20) / dpi,
106
+ (fig_size[1] * nrows + fig_size[1] // 3) / dpi,
107
+ )
108
+
109
+ fig.tight_layout()
110
+ # set subplot margin
111
+ plt.subplots_adjust(
112
+ hspace=.05,
113
+ wspace=0.05,
114
+ left=0.02,
115
+ right=0.98,
116
+ bottom=0.02,
117
+ top=0.98)
118
+
119
+ for i, (path_tuple, ax_tuple) in enumerate(zip(paths, axes)):
120
+ image_path_left = osp.join(
121
+ osp.join(image_dir, result_dir_names[0], path_tuple[0]))
122
+ image_path_right = osp.join(
123
+ osp.join(image_dir, result_dir_names[1], path_tuple[1]))
124
+ image_left = mmcv.imread(image_path_left)
125
+ image_left = mmcv.rgb2bgr(image_left)
126
+ image_right = mmcv.imread(image_path_right)
127
+ image_right = mmcv.rgb2bgr(image_right)
128
+
129
+ if i == 0:
130
+ ax_tuple[0].set_title(
131
+ result_dir_names[0], fontdict={'size': font_size})
132
+ ax_tuple[1].set_title(
133
+ result_dir_names[1], fontdict={'size': font_size})
134
+ ax_tuple[0].imshow(
135
+ image_left, extent=(0, *fig_size, 0), interpolation='bilinear')
136
+ ax_tuple[0].axis('off')
137
+ ax_tuple[1].imshow(
138
+ image_right,
139
+ extent=(0, *fig_size, 0),
140
+ interpolation='bilinear')
141
+ ax_tuple[1].axis('off')
142
+
143
+ canvas = fig.canvas
144
+ s, (width, height) = canvas.print_to_buffer()
145
+ buffer = np.frombuffer(s, dtype='uint8')
146
+ img_rgba = buffer.reshape(height, width, 4)
147
+ rgb, alpha = np.split(img_rgba, [3], axis=2)
148
+ img = rgb.astype('uint8')
149
+
150
+ frames.append(img)
151
+
152
+ return frames
153
+
154
+
155
+ def main():
156
+ args = parse_args()
157
+ frames = create_frame_by_matplotlib(args.image_dir)
158
+ create_gif(frames, args.out)
159
+
160
+
161
+ if __name__ == '__main__':
162
+ main()
demo/demo.jpg ADDED

Git LFS Details

  • SHA256: 8e9ab135da7eacabdeeeee11ba4b7bcdd1bfac128cf92a9de9c79f984060ae1e
  • Pointer size: 131 Bytes
  • Size of remote file: 260 kB
demo/demo.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:510a80cf99607d625a267b0fb21ce405cedb3c9352e25bb42b9972490cf5a1c7
3
+ size 297688
demo/demo_27_result.jpg ADDED

Git LFS Details

  • SHA256: 9835fbc9d822d5e9211a48b1f31ff7df0ce5c6ea678c424364c7b48c14239815
  • Pointer size: 131 Bytes
  • Size of remote file: 329 kB
demo/demo_27_result2.jpg ADDED

Git LFS Details

  • SHA256: c3ae95ddbc971fd1d349630ac4f52af6d1bd4737480aa2b9becf2d37d412917b
  • Pointer size: 131 Bytes
  • Size of remote file: 323 kB
demo/demo_31_result2.jpg ADDED

Git LFS Details

  • SHA256: 3e58d27ffbd37708e8b3d215b7777660963ea276ef9c9f33fd5f197d6b1b9253
  • Pointer size: 131 Bytes
  • Size of remote file: 350 kB
demo/demo_40_result2.jpg ADDED

Git LFS Details

  • SHA256: ff376ec1dbca2b5d642beb671f07484b25e2066639f707dd80aecfdda0e3468d
  • Pointer size: 131 Bytes
  • Size of remote file: 241 kB
demo/demo_6_result.jpg ADDED

Git LFS Details

  • SHA256: ac255579c1074aa2109b7c84899cc0d8288bd5eca0801c5cfc432dd0ce6c870e
  • Pointer size: 131 Bytes
  • Size of remote file: 804 kB
demo/demo_6_result2.jpg ADDED

Git LFS Details

  • SHA256: 1d3a184ab02dcdbecbd300f6320a845510feb6fdecf1bd635c6229dcaf648280
  • Pointer size: 131 Bytes
  • Size of remote file: 802 kB
demo/demo_result.jpg ADDED

Git LFS Details

  • SHA256: 905c0f68b5f4137f37fd7019657a09a6ae1e842aaa9c0415d5be24cfd032818b
  • Pointer size: 131 Bytes
  • Size of remote file: 325 kB
demo/image_demo.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from argparse import ArgumentParser
2
+
3
+ from mmdet.apis import inference_detector, init_detector, show_result_pyplot
4
+
5
+
6
+ def main():
7
+ parser = ArgumentParser()
8
+ parser.add_argument('img', help='Image file')
9
+ parser.add_argument('config', help='Config file')
10
+ parser.add_argument('checkpoint', help='Checkpoint file')
11
+ parser.add_argument(
12
+ '--device', default='cuda:0', help='Device used for inference')
13
+ parser.add_argument(
14
+ '--score-thr', type=float, default=0.3, help='bbox score threshold')
15
+ args = parser.parse_args()
16
+
17
+ # build the model from a config file and a checkpoint file
18
+ model = init_detector(args.config, args.checkpoint, device=args.device)
19
+ # test a single image
20
+ result = inference_detector(model, args.img)
21
+ # show the results
22
+ show_result_pyplot(model, args.img, result, score_thr=args.score_thr)
23
+
24
+
25
+ if __name__ == '__main__':
26
+ main()
demo/inference_demo.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
demo/test.png ADDED

Git LFS Details

  • SHA256: 80cd63b93e1c0a5403c34a36b1554e8b8b4a9b88aaab1efe7e92d2e2eb268b71
  • Pointer size: 131 Bytes
  • Size of remote file: 120 kB
demo/video_demo.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+
3
+ import cv2
4
+ import mmcv
5
+
6
+ from mmdet.apis import inference_detector, init_detector
7
+
8
+
9
+ def parse_args():
10
+ parser = argparse.ArgumentParser(description='MMDetection video demo')
11
+ parser.add_argument('video', help='Video file')
12
+ parser.add_argument('config', help='Config file')
13
+ parser.add_argument('checkpoint', help='Checkpoint file')
14
+ parser.add_argument(
15
+ '--device', default='cuda:0', help='Device used for inference')
16
+ parser.add_argument(
17
+ '--score-thr', type=float, default=0.3, help='Bbox score threshold')
18
+ parser.add_argument('--out', type=str, help='Output video file')
19
+ parser.add_argument('--show', action='store_true', help='Show video')
20
+ parser.add_argument(
21
+ '--wait-time',
22
+ type=float,
23
+ default=1,
24
+ help='The interval of show (s), 0 is block')
25
+ args = parser.parse_args()
26
+ return args
27
+
28
+
29
+ def main():
30
+ args = parse_args()
31
+ assert args.out or args.show, \
32
+ ('Please specify at least one operation (save/show the '
33
+ 'video) with the argument "--out" or "--show"')
34
+
35
+ model = init_detector(args.config, args.checkpoint, device=args.device)
36
+
37
+ video_reader = mmcv.VideoReader(args.video)
38
+ video_writer = None
39
+ if args.out:
40
+ fourcc = cv2.VideoWriter_fourcc(*'mp4v')
41
+ video_writer = cv2.VideoWriter(
42
+ args.out, fourcc, video_reader.fps,
43
+ (video_reader.width, video_reader.height))
44
+
45
+ for frame in mmcv.track_iter_progress(video_reader):
46
+ result = inference_detector(model, frame)
47
+ frame = model.show_result(frame, result, score_thr=args.score_thr)
48
+ if args.show:
49
+ cv2.namedWindow('video', 0)
50
+ mmcv.imshow(frame, 'video', args.wait_time)
51
+ if args.out:
52
+ video_writer.write(frame)
53
+
54
+ if video_writer:
55
+ video_writer.release()
56
+ cv2.destroyAllWindows()
57
+
58
+
59
+ if __name__ == '__main__':
60
+ main()
demo/webcam_demo.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+
3
+ import cv2
4
+ import torch
5
+
6
+ from mmdet.apis import inference_detector, init_detector
7
+
8
+
9
+ def parse_args():
10
+ parser = argparse.ArgumentParser(description='MMDetection webcam demo')
11
+ parser.add_argument('config', help='test config file path')
12
+ parser.add_argument('checkpoint', help='checkpoint file')
13
+ parser.add_argument(
14
+ '--device', type=str, default='cuda:0', help='CPU/CUDA device option')
15
+ parser.add_argument(
16
+ '--camera-id', type=int, default=0, help='camera device id')
17
+ parser.add_argument(
18
+ '--score-thr', type=float, default=0.5, help='bbox score threshold')
19
+ args = parser.parse_args()
20
+ return args
21
+
22
+
23
+ def main():
24
+ args = parse_args()
25
+
26
+ device = torch.device(args.device)
27
+
28
+ model = init_detector(args.config, args.checkpoint, device=device)
29
+
30
+ camera = cv2.VideoCapture(args.camera_id)
31
+
32
+ print('Press "Esc", "q" or "Q" to exit.')
33
+ while True:
34
+ ret_val, img = camera.read()
35
+ result = inference_detector(model, img)
36
+
37
+ ch = cv2.waitKey(1)
38
+ if ch == 27 or ch == ord('q') or ch == ord('Q'):
39
+ break
40
+
41
+ model.show_result(
42
+ img, result, score_thr=args.score_thr, wait_time=1, show=True)
43
+
44
+
45
+ if __name__ == '__main__':
46
+ main()