Comments (5)
And if you truly want to show your attitude toward module re-use that much, warnings is more recommended as it won't interrupt the program. 😄
By raising a Warning, you're generating error, rather than real warning.
from pytorch-opcounter.
Question, does the example code you provide trigger the warning? Though ReLU is forwarded several times, the registration should only happen once.
from pytorch-opcounter.
@Lyken17 Sorry that I didn't dig deep into your code's logic, see the following NN design instead.
class SomeNet(nn.Module):
def __init__(self, reduction=4):
super(SomeNet, self).__init__()
self.activation = nn.LeakyReLU(negative_slope=0.3, inplace=True)
self.encoder_feature = nn.Sequential(OrderedDict([
("conv3x3_bn", conv3x3_bn(in_channel, 2)),
("activation", self.activation),
]))
...
The problem has nothing to do with module reuse in forward function. THOP will recursively enter each leaf nn.Module
and detect if there exist any "re-defined" module.
However, the aforementioned re-defined is legal, since I want to define a globally same activation function and plant it in many sub-modules. And THOP stops me from doing that.
Like I said, even my definition of network is wrong, it is not THOP's job to point it out. And even if THOP would like to point it out, warnings rather than Raise Error should be used.
As a flops counting tools, it should not do extra judgement or security check. A correct flops and params output is the only thing to focus on.
from pytorch-opcounter.
It is a weird usage, I have to say. For your code example, each activation should have its own nn.Module. The proper case should be a recurrent structure where one layer is used in different depth. I have relaxed the check: now it only prints the warning instead of raises it.
from pytorch-opcounter.
Yet a legal one and a convinient one, too. Still unable to get your points of checking user's network... If I were you I would cancel the redundant check, but after all it is your project 😂
from pytorch-opcounter.
Related Issues (20)
- thop/profile.py:12: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead. `if LooseVersion(torch.__version__) < LooseVersion("1.0.0"):` HOT 2
- Does MACs and FLOPs count correctly for and INT8 quantized model? HOT 1
- Upload sdist to PyPI HOT 1
- Problem in bert HOT 1
- multiple inputs HOT 1
- Is the latest version calculate MACs or FLOPs HOT 2
- RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
- How to calculate the FLOPs of each type of layers?
- How to exclude flops of 1st input? HOT 1
- Incorrect macs without specifying batch size for conv layers
- will torch.matmul regards as zero_ops ?
- Is thop also effective for calculating Flops for spiking neural networks?
- rename calculate_conv2d_flops HOT 1
- thop calculates torch.nn module params incorrectly HOT 1
- RuntimeError: Can't add a new parameter
- count_normalization is only correct for batch_norm. wrong flops count for layernorm HOT 1
- Res add will be included when evaluate Resnet's OPs ? HOT 1
- Source distribution (sdist) and Git tags
- I got different results using thop and torchinfo HOT 1
- question about BN
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytorch-opcounter.