noahzn / Lite-Mono

[CVPR2023] Lite-Mono: A Lightweight CNN and Transformer Architecture for Self-Supervised Monocular Depth Estimation
MIT License
527 stars 58 forks source link

A BUG in thop library #113

Closed vfan26 closed 7 months ago

vfan26 commented 8 months ago

It seems that the thop library does not calculate FLOPs for matrix multiplication used in XCA module. There is a simple example.

import  torch
import torch.nn as nn
from thop import profile, clever_format

class MatMul(nn.Module):
    def __init__(self):
        super(MatMul, self).__init__()

    def forward(self, a, b):
        return a @ b

matmul = MatMul().cuda()
a = torch.randn(1, 1, 100).cuda()
b = torch.randn(1, 100, 1).cuda()

macs, params = profile(matmul, inputs=(a, b))
macs, params = clever_format([macs, params], "%.3f")
print(macs, params)

output

0.000B 0.000B
noahzn commented 7 months ago

Hi! Thanks for your findings! I have just tested with your code. Indeed, thop doesn't count matmul operations.