zhongyy / Face-Transformer

Face Transformer for Recognition
MIT License
252 stars 54 forks source link

Face Transformer Table I Query #6

Open khawar-islam opened 3 years ago

khawar-islam commented 3 years ago

I would like to ask one question about the table I in your Face Transformer paper. How you calculate the speed of Img/Sec in Table I?

I am using the below library but I have no idea how to calculate inference speed? https://github.com/sovrasov/flops-counter.pytorch

zhongyy commented 3 years ago

You can record the inference time of n images and then calculate the mean value.

    import time

    backbone = backbone.to(device)
    backbone.eval() # switch to evaluation mode
    forward_time = 0
    carray = data_set[0]
    idx = 0
    with torch.no_grad():
            while idx < 2000:
                batch = carray[idx:idx + 1]
                batch_device = batch.to(device)
                last_time = time.time()
                backbone(batch_device)
                forward_time += time.time() - last_time
    print("forward_time", 2000, forward_time, 2000/forward_time)
khawar-islam commented 3 years ago

Thank you @zhongyy

khawar-islam commented 3 years ago

@zhongyy Would it be possible for you to check this batch_device = batch.to(device)code again. I am getting errors in this line.

zhongyy commented 3 years ago

@khawar512 The code comes from "test_forward()" of "https://github.com/zhongyy/Face-Transformer/blob/main/util/utils.py", maybe you can try "https://github.com/zhongyy/Face-Transformer/blob/main/test_forward.py".