(args)
| 120 | |
| 121 | |
| 122 | def main(args): |
| 123 | print("Running in benchmark mode") |
| 124 | tf_infer = TensorFlowInfer(args.saved_model) |
| 125 | input_size = [int(v) for v in args.input_size.split(",")] |
| 126 | assert len(input_size) == 2 |
| 127 | tf_infer.override_input_shape(0, [args.batch_size, input_size[0], input_size[1], 3]) |
| 128 | spec = tf_infer.input_spec() |
| 129 | batch = 255 * np.random.rand(*spec[0]).astype(spec[1]) |
| 130 | iterations = 200 |
| 131 | times = [] |
| 132 | for i in range(20): # Warmup iterations |
| 133 | tf_infer.infer(batch) |
| 134 | for i in range(iterations): |
| 135 | start = time.time() |
| 136 | tf_infer.infer(batch) |
| 137 | times.append(time.time() - start) |
| 138 | print("Iteration {} / {}".format(i + 1, iterations), end="\r") |
| 139 | print("Benchmark results include TensorFlow host overhead") |
| 140 | print("Average Latency: {:.3f} ms".format( |
| 141 | 1000 * np.average(times))) |
| 142 | print("Average Throughput: {:.1f} ips".format( |
| 143 | tf_infer.batch_size / np.average(times))) |
| 144 | |
| 145 | print() |
| 146 | print("Finished Processing") |
| 147 | |
| 148 | |
| 149 | if __name__ == "__main__": |
no test coverage detected