-
Notifications
You must be signed in to change notification settings - Fork 3
/
demo.py
67 lines (56 loc) · 1.84 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import tqdm
import argparse
import torch
import numpy as np
import cv2
import glob
import streamer_pytorch as streamer
parser = argparse.ArgumentParser(description='.')
parser.add_argument(
'--camera', action="store_true", help="whether to use webcam.")
parser.add_argument(
'--images', default="", nargs="*", help="paths of image.")
parser.add_argument(
'--image_folder', default=None, help="path of image folder.")
parser.add_argument(
'--videos', default="", nargs="*", help="paths of video.")
parser.add_argument(
'--loop', action="store_true", help="whether to repeat images/video.")
parser.add_argument(
'--vis', action="store_true", help="whether to visualize.")
args = parser.parse_args()
def visulization(data):
window = data[0].numpy()
window = window.transpose(1, 2, 0)
window = (window * 0.5 + 0.5) * 255.0
window = np.uint8(window)
window = cv2.cvtColor(window, cv2.COLOR_BGR2RGB)
window = cv2.resize(window, (0, 0), fx=2, fy=2)
cv2.imshow('window', window)
cv2.waitKey(1)
if args.camera:
data_stream = streamer.CaptureStreamer(pad=False)
elif len(args.videos) > 0:
data_stream = streamer.VideoListStreamer(
args.videos * (10 if args.loop else 1))
elif len(args.images) > 0:
data_stream = streamer.ImageListStreamer(
args.images * (10000 if args.loop else 1))
elif args.image_folder is not None:
images = sorted(glob.glob(args.image_folder+'/*.jpg'))
images += sorted(glob.glob(args.image_folder+'/*.png'))
data_stream = streamer.ImageListStreamer(
images * (10 if args.loop else 1))
loader = torch.utils.data.DataLoader(
data_stream,
batch_size=1,
num_workers=1,
pin_memory=False,
)
try:
for data in tqdm.tqdm(loader):
if args.vis:
visulization(data)
except Exception as e:
print (e)
del data_stream