MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / apply

Function apply

examples/OpticalFlow/flownet2.py:17–49  ·  view source on GitHub ↗
(model, model_path, images, ground_truth=None)

Source from the content-addressed store, hash-verified

15
16
17def apply(model, model_path, images, ground_truth=None):
18 left = cv2.imread(images[0])
19 h, w = left.shape[:2]
20 newh = (h // 64) * 64
21 neww = (w // 64) * 64
22 aug = imgaug.CenterCrop((newh, neww))
23 left = aug.augment(left)
24
25 predict_func = OfflinePredictor(PredictConfig(
26 model=model(height=newh, width=neww),
27 session_init=SmartInit(model_path),
28 input_names=['left', 'right'],
29 output_names=['prediction']))
30
31 for idx, right in enumerate(images[1:]):
32 right = aug.augment(cv2.imread(right))
33
34 left_input, right_input = [x.astype('float32').transpose(2, 0, 1)[None, ...]
35 for x in [left, right]]
36 output = predict_func(left_input, right_input)[0].transpose(0, 2, 3, 1)
37 flow = Flow()
38
39 img = flow.visualize(output[0])
40 patches = [left, right, img * 255.]
41 if ground_truth is not None:
42 patches.append(flow.visualize(Flow.read(ground_truth)) * 255.)
43 img = viz.stack_patches(patches, 2, 2)
44
45 cv2.imshow('flow output', img)
46 cv2.imwrite('flow_output{:03d}.png'.format(idx), img)
47 cv2.waitKey(0)
48
49 left = right
50
51
52class SintelData(DataFlow):

Callers 1

flownet2.pyFile · 0.70

Calls 9

visualizeMethod · 0.95
FlowClass · 0.90
OfflinePredictorClass · 0.85
PredictConfigClass · 0.85
SmartInitFunction · 0.85
augmentMethod · 0.80
appendMethod · 0.80
readMethod · 0.80
formatMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…