Using count_ops to calculate FLOPS for a neural network model gives me the error mentioned in the title. I have changed a pretrained model (resnet18) by using assignments. My goal is to calculate the FLOPS for each edited model (to make sure the model is passing inputs).
net = resnet18()
phi = math.pow(math.sqrt(2), 7)
# net.conv1 = nn.Conv2d(math.ceil(phi*3), math.ceil(phi*64), kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
net.conv1 = nn.Conv2d(math.ceil(3), math.ceil(phi*64), kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
net.bn1 = nn.BatchNorm2d(math.ceil(phi*64), eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
net.relu = nn.ReLU(inplace=True)
net.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False)
net.layer1[0].conv1 = nn.Conv2d(math.ceil(phi*64), math.ceil(phi*64), kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
.
.
net.layer2[0].conv1 = nn.Conv2d(math.ceil(phi*64), math.ceil(phi*128), kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
.
.
net.layer3[0].conv1 = nn.Conv2d(math.ceil(phi*128), math.ceil(phi*256), kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
.
.
net.layer4[0].conv1 = nn.Conv2d(math.ceil(phi*256), math.ceil(phi*512), kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
.
.
# net.avgpool = Identity()
net.avgpool = nn.AdaptiveAvgPool2d(output_size=(1, 1))
nn.fc = nn.Linear(in_features=math.ceil(phi*512), out_features=1000, bias=True)
The edited model works when I use model.named_parameters(). I am thinking that I messed up by directly assigning layers with new values (I am not sure of the order of parameters for the layers, printing my model seems to be fine, but for the love of god not a single input passes throught the model). Want to know where I messed up in the syntax, because of which my inputs are not passing through the model.
ip = torch.rand(1,3,224,224).to(dev)
count_ops(net, ip) # Count the number of FLOPs