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

Function eval_classification

examples/DoReFa-Net/imagenet_utils.py:269–292  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

267
268
269def 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
295class ImageNetModel(ModelDesc):

Callers 2

resnet-dorefa.pyFile · 0.90
alexnet-dorefa.pyFile · 0.90

Calls 9

PredictConfigClass · 0.90
RatioCounterClass · 0.90
FeedfreePredictorClass · 0.90
StagingInputClass · 0.90
QueueInputClass · 0.90
sumMethod · 0.80
formatMethod · 0.80
sizeMethod · 0.45
feedMethod · 0.45

Tested by

no test coverage detected