MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / main

Function main

samples/python/efficientnet/eval_gt.py:28–67  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

26
27
28def main(args):
29 annotations = {}
30 for line in open(args.annotations, "r"):
31 line = line.strip().split(args.separator)
32 if len(line) < 2 or not line[1].isnumeric():
33 print("Could not parse the annotations file correctly, make sure the correct separator is used")
34 sys.exit(1)
35 annotations[os.path.basename(line[0])] = int(line[1])
36
37 trt_infer = TensorRTInfer(args.engine)
38 batcher = ImageBatcher(args.input, *trt_infer.input_spec(), preprocessor=args.preprocessor)
39 top1 = 0
40 top5 = 0
41 total = 0
42 for batch, images in batcher.get_batch():
43 classes, scores, top = trt_infer.infer(batch, top=5)
44 for i in range(len(images)):
45 image = os.path.basename(images[i])
46 if image not in annotations.keys():
47 print(
48 "Image '{}' does not appear in the annotations file, please make sure all evaluated "
49 "images have a corresponding ground truth label".format(image)
50 )
51 sys.exit(1)
52 if annotations[image] == classes[i]:
53 top1 += 1
54 if annotations[image] in top[0][i]:
55 top5 += 1
56 total += 1
57 top1_acc = 100 * (top1 / total)
58 top5_acc = 100 * (top5 / total)
59 print(
60 "Processing {} / {} : Top-1 {:0.1f}% , Top-5: {:0.1f}% ".format(
61 total, batcher.num_images, top1_acc, top5_acc
62 ),
63 end="\r",
64 )
65 print()
66 print("Top-1 Accuracy: {:0.3f}%".format(top1_acc))
67 print("Top-5 Accuracy: {:0.3f}%".format(top5_acc))
68
69
70if __name__ == "__main__":

Callers 1

eval_gt.pyFile · 0.70

Calls 7

input_specMethod · 0.95
get_batchMethod · 0.95
inferMethod · 0.95
TensorRTInferClass · 0.90
ImageBatcherClass · 0.90
printFunction · 0.85
keysMethod · 0.45

Tested by

no test coverage detected