MCPcopy Create free account
hub / github.com/PaddlePaddle/Research / val

Function val

CV/PWCNet/train.py:86–121  ·  view source on GitHub ↗
(model, batch_reader, epoch, batch_num)

Source from the content-addressed store, hash-verified

84
85
86def val(model, batch_reader, epoch, batch_num):
87 model.eval()
88 loss_cnt = AverageMeter()
89 for batch_id, data in enumerate(batch_reader()):
90 start = time.time()
91 im1_data = np.array(
92 [x[0] for x in data]).astype('float32')
93 im2_data = np.array(
94 [x[1] for x in data]).astype('float32')
95 flo_data = np.array(
96 [x[2] for x in data]).astype('float32')
97 step = im1_data.shape[0]
98
99 im_all = np.concatenate((im1_data, im2_data), axis=3).astype(np.float32)
100 im_all = im_all / 255.0
101 im_all = np.swapaxes(np.swapaxes(im_all, 1, 2), 1, 3)
102 label = flo_data / 20.0
103 label = np.swapaxes(np.swapaxes(label, 1, 2), 1, 3)
104
105 im_all = fluid.dygraph.to_variable(im_all)
106 label = fluid.dygraph.to_variable(label)
107 # im_all, [intPaddingLeft, intPaddingRight, intPaddingTop, intPaddingBottom, intWidth, intHeight] = pad_input(
108 # im_all)
109
110 end = time.time()
111 read_data_time = end - start
112 start = time.time()
113 network_output = model(im_all, output_more=False)
114 loss = realEPE(network_output, label)
115 end = time.time()
116 loss_cnt.update(float(loss), step)
117 print('val epoch {} batch {}/{} run time: {}s read data time {}s loss {}'.format(epoch, batch_id, batch_num,
118 round(end - start, 2),
119 round(read_data_time, 2),
120 loss.numpy()))
121 return round(loss_cnt.avg, 4)
122
123
124def train(model, train_batch_reader, adam, epoch, batch_num, args):

Callers 1

mainFunction · 0.85

Calls 5

updateMethod · 0.95
AverageMeterClass · 0.90
realEPEFunction · 0.90
batch_readerFunction · 0.50
evalMethod · 0.45

Tested by

no test coverage detected