Eval a classification model on the dataset. It assumes the model inputs are named "input" and "label", and contains "wrong-top1" and "wrong-top5" in the graph.
(model, sessinit, dataflow)
| 267 | |
| 268 | |
| 269 | def eval_classification(model, sessinit, dataflow): |
| 270 | """ |
| 271 | Eval a classification model on the dataset. It assumes the model inputs are |
| 272 | named "input" and "label", and contains "wrong-top1" and "wrong-top5" in the graph. |
| 273 | """ |
| 274 | pred_config = PredictConfig( |
| 275 | model=model, |
| 276 | session_init=sessinit, |
| 277 | input_names=['input', 'label'], |
| 278 | output_names=['wrong-top1', 'wrong-top5'] |
| 279 | ) |
| 280 | acc1, acc5 = RatioCounter(), RatioCounter() |
| 281 | |
| 282 | # This does not have a visible improvement over naive predictor, |
| 283 | # but will have an improvement if image_dtype is set to float32. |
| 284 | pred = FeedfreePredictor(pred_config, StagingInput(QueueInput(dataflow), device='/gpu:0')) |
| 285 | for _ in tqdm.trange(dataflow.size()): |
| 286 | top1, top5 = pred() |
| 287 | batch_size = top1.shape[0] |
| 288 | acc1.feed(top1.sum(), batch_size) |
| 289 | acc5.feed(top5.sum(), batch_size) |
| 290 | |
| 291 | print("Top1 Error: {}".format(acc1.ratio)) |
| 292 | print("Top5 Error: {}".format(acc5.ratio)) |
| 293 | |
| 294 | |
| 295 | class ImageNetModel(ModelDesc): |
no test coverage detected