()
| 36 | |
| 37 | |
| 38 | def main(): |
| 39 | # init arguments |
| 40 | args = get_parser() |
| 41 | torch.cuda.set_device(0) |
| 42 | # create model |
| 43 | model, _ = build_segmenter(args) |
| 44 | model = model.cuda() |
| 45 | model.eval() |
| 46 | # set cudnn state |
| 47 | cudnn.benchmark = True |
| 48 | cudnn.deterministic = False |
| 49 | cudnn.enabled = True |
| 50 | # init dummy tensor |
| 51 | image = torch.randn(1, 3, 416, 416).cuda() |
| 52 | text = torch.randint(4096, size=(1, args.word_len)).long().cuda() |
| 53 | # init time & memory |
| 54 | avg_time = 0 |
| 55 | avg_mem = 0 |
| 56 | # record initial gpu memory |
| 57 | mem = torch.cuda.max_memory_allocated() |
| 58 | |
| 59 | with torch.no_grad(): |
| 60 | for i in range(500): |
| 61 | start_time = time.time() |
| 62 | _ = model(image, text) |
| 63 | torch.cuda.synchronize() |
| 64 | if (i+1) >= 100: |
| 65 | avg_time += (time.time() - start_time) |
| 66 | avg_mem += (torch.cuda.max_memory_allocated() - mem) / 1.073742e9 |
| 67 | params = count_parameters(model) * 1e-6 |
| 68 | print('#########################################') |
| 69 | print("Average Parameters : {:.2f} M".format(params)) |
| 70 | print("Average FPS: {:.2f}".format(400/avg_time)) |
| 71 | print("Average GPU Memory: {:.2f} GB".format(avg_mem/400)) |
| 72 | print('#########################################') |
| 73 | |
| 74 | |
| 75 | if __name__ == '__main__': |
no test coverage detected