MCPcopy
hub / github.com/PaddlePaddle/PaddleOCR / eval

Function eval

deploy/slim/auto_compression/test_ocr.py:148–233  ·  view source on GitHub ↗

eval mIoU func

(args)

Source from the content-addressed store, hash-verified

146
147
148def eval(args):
149 """
150 eval mIoU func
151 """
152 # DataLoader need run on cpu
153 paddle.set_device("cpu")
154 devices = paddle.device.get_device().split(":")[0]
155
156 val_loader = build_dataloader(all_config, "Eval", devices, logger)
157 post_process_class = build_post_process(all_config["PostProcess"], global_config)
158 eval_class = build_metric(all_config["Metric"])
159 model_type = global_config["model_type"]
160
161 predictor, rerun_flag = load_predictor(args)
162
163 if rerun_flag:
164 eval_dataset = find_images_with_bounding_size(val_loader.dataset)
165 batch_sampler = paddle.io.BatchSampler(
166 eval_dataset, batch_size=1, shuffle=False, drop_last=False
167 )
168 val_loader = paddle.io.DataLoader(
169 eval_dataset, batch_sampler=batch_sampler, num_workers=4, return_list=True
170 )
171
172 input_names = predictor.get_input_names()
173 input_handle = predictor.get_input_handle(input_names[0])
174 output_names = predictor.get_output_names()
175 output_handle = predictor.get_output_handle(output_names[0])
176 sample_nums = len(val_loader)
177 predict_time = 0.0
178 time_min = float("inf")
179 time_max = float("-inf")
180 print("Start evaluating ( total_iters: {}).".format(sample_nums))
181
182 for batch_id, batch in enumerate(val_loader):
183 images = np.array(batch[0])
184
185 batch_numpy = []
186 for item in batch:
187 batch_numpy.append(np.array(item))
188
189 # ori_shape = np.array(batch_numpy).shape[-2:]
190 input_handle.reshape(images.shape)
191 input_handle.copy_from_cpu(images)
192 start_time = time.time()
193
194 predictor.run()
195 preds = output_handle.copy_to_cpu()
196
197 end_time = time.time()
198 timed = end_time - start_time
199 time_min = min(time_min, timed)
200 time_max = max(time_max, timed)
201 predict_time += timed
202
203 if model_type == "det":
204 preds_map = {"maps": preds}
205 post_result = post_process_class(preds_map, batch_numpy[1])

Callers 1

mainFunction · 0.70

Calls 9

build_dataloaderFunction · 0.90
build_post_processFunction · 0.90
build_metricFunction · 0.90
load_predictorFunction · 0.85
minFunction · 0.85
formatMethod · 0.80
runMethod · 0.45
get_metricMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…