MCPcopy Create free account
hub / github.com/tensorpack/tensorpack / inference

Function inference

examples/OpticalFlow/flownet2.py:88–116  ·  view source on GitHub ↗
(model, model_path, sintel_path)

Source from the content-addressed store, hash-verified

86
87
88def inference(model, model_path, sintel_path):
89 ds = SintelData(sintel_path)
90
91 def nhwc2nchw(dp):
92 return [dp[0].transpose(2, 0, 1),
93 dp[1].transpose(2, 0, 1),
94 dp[2].transpose(2, 0, 1)]
95
96 ds = MapData(ds, nhwc2nchw)
97 ds = BatchData(ds, 1)
98 ds.reset_state()
99
100 # look at shape information (all images in Sintel has the same shape)
101 h, w = next(ds.__iter__())[0].shape[2:]
102
103 pred = PredictConfig(
104 model=model(height=h, width=w),
105 session_init=SmartInit(model_path),
106 input_names=['left', 'right', 'gt_flow'],
107 output_names=['epe', 'prediction'])
108 pred = SimpleDatasetPredictor(pred, ds)
109
110 avg_epe, count_epe = 0, 0
111
112 for o in pred.get_result():
113 avg_epe += o[0]
114 count_epe += 1
115
116 print('average endpoint error (AEE): %f' % (float(avg_epe) / float(count_epe)))
117
118
119if __name__ == '__main__':

Callers 1

flownet2.pyFile · 0.85

Calls 9

__iter__Method · 0.95
get_resultMethod · 0.95
SintelDataClass · 0.85
MapDataClass · 0.85
BatchDataClass · 0.85
PredictConfigClass · 0.85
SmartInitFunction · 0.85
reset_stateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…