You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried using wide_resnet_imagenet64_1000, but found that it is giving zero accuracy. So, wanted to double check if this usage is correct. Here I am evaluating its natural accuracy on: Imagenet64_val_npz which I downloaded form ImageNet website (I also tried certfiied accuracy, which is also zero)
Step 1 load the model:
import torch
import torch.nn as nn
import torch.nn.init as init
import torch.nn.functional as F
import sys
import numpy as np
def conv3x3(in_planes, out_planes, stride=1):
return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=1, bias=True)
def conv_init(m):
classname = m.__class__.__name__
if classname.find('Conv') != -1:
init.xavier_uniform_(m.weight, gain=np.sqrt(2))
init.constant_(m.bias, 0)
elif classname.find('BatchNorm') != -1:
init.constant_(m.weight, 1)
init.constant_(m.bias, 0)
class wide_basic(nn.Module):
def __init__(self, in_planes, planes, dropout_rate, stride=1):
super(wide_basic, self).__init__()
self.bn1 = nn.BatchNorm2d(in_planes)
self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, padding=1, bias=True)
# self.dropout = nn.Dropout(p=dropout_rate)
self.bn2 = nn.BatchNorm2d(planes)
self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, padding=1, bias=True)
self.shortcut = nn.Sequential()
if stride != 1 or in_planes != planes:
self.shortcut = nn.Sequential(
nn.Conv2d(in_planes, planes, kernel_size=1, stride=stride, bias=True),
)
def forward(self, x):
# out = self.dropout(self.conv1(F.relu(self.bn1(x))))
out = self.conv1(F.relu(self.bn1(x)))
out = self.conv2(F.relu(self.bn2(out)))
out += self.shortcut(x)
return out
class Wide_ResNet(nn.Module):
def __init__(self, depth, widen_factor, dropout_rate, num_classes,
in_planes=16, in_dim=56):
super(Wide_ResNet, self).__init__()
self.in_planes = in_planes
assert ((depth-4)%6 ==0), 'Wide-resnet depth should be 6n+4'
n = (depth-4)/6
k = widen_factor
print('| Wide-Resnet %dx%d' %(depth, k))
nStages = [in_planes, in_planes*k, in_planes*2*k, in_planes*4*k]
self.conv1 = conv3x3(3,nStages[0])
self.layer1 = self._wide_layer(wide_basic, nStages[1], n, dropout_rate, stride=1)
self.layer2 = self._wide_layer(wide_basic, nStages[2], n, dropout_rate, stride=2)
self.layer3 = self._wide_layer(wide_basic, nStages[3], n, dropout_rate, stride=2)
self.bn1 = nn.BatchNorm2d(nStages[3], momentum=0.1)
self.linear = nn.Linear(nStages[3] * (in_dim//4//7)**2, num_classes)
def _wide_layer(self, block, planes, num_blocks, dropout_rate, stride):
strides = [stride] + [1]*(int(num_blocks)-1)
layers = []
for stride in strides:
layers.append(block(self.in_planes, planes, dropout_rate, stride))
self.in_planes = planes
return nn.Sequential(*layers)
def forward(self, x):
out = self.conv1(x)
out = self.layer1(out)
out = self.layer2(out)
out = self.layer3(out)
out = F.relu(self.bn1(out))
out = F.avg_pool2d(out, 7)
out = torch.flatten(out, 1)
out = self.linear(out)
return out
def wide_resnet_imagenet64(in_ch=3, in_dim=56, in_planes=16, widen_factor=10):
return Wide_ResNet(10, widen_factor, 0.3, 200, in_dim=in_dim, in_planes=in_planes)
def wide_resnet_imagenet64_1000class(in_ch=3, in_dim=56, in_planes=16, widen_factor=10):
return Wide_ResNet(10, widen_factor, 0.3, 1000, in_dim=in_dim, in_planes=in_planes)
model = wide_resnet_imagenet64_1000class()
chkpt = torch.load("wide_resnet_imagenet64_1000")
model.load_state_dict(chkpt['state_dict'])
model.eval()
pass
For ImageNet-1000, scaled to 64x64 if I use code at: https://github.com/Verified-Intelligence/auto_LiRPA/blob/master/examples/vision/imagenet_training.py (as suggested), than do I need to use actual ImageNet with full scale images and crop them at center with 56x56 box as in the code (above result is from that)? OR, as suggested in the doc I shall download val_data.npz from ImageNet? In that case I would need to change the dataloader. Right?
Also, shouldn't it work on val_data.npz for natural accuracy?
What is the expected accuracy for ImageNet-1000? I must have missed it, but where can I find it?
I tried using wide_resnet_imagenet64_1000, but found that it is giving zero accuracy. So, wanted to double check if this usage is correct. Here I am evaluating its natural accuracy on: Imagenet64_val_npz which I downloaded form ImageNet website (I also tried certfiied accuracy, which is also zero)
Step 1 load the model:
Step 2: Load the dataset
Step 3: Evaluate
Here is top 10 output: (No correct prediction). Q: how to evaluate it?
The text was updated successfully, but these errors were encountered: