I trained my model based on the link here. It achieved almost 90%
accuracy when i trained it. I am using the vgg_bn_drop.lua
model that you will find on the link. But the problem is, i don't know how to test it for a single image.
I know how to test a model. By forward passing the image through the network.
So, testing the model will require modelname:forward(image)
. Where the modelname
is the name of the model that i trained and forward
is used to forward the model and 'image' is the image location that i want to forward. Now, I cannot figure what the dimension of the single image will be from this network.
So, what i want to do is, take an image. Say the image has dimension [3x32x32]. Pass it through the network and get the result. Is it possible with this network?
There was no documentation there how to test it for a single image.
What i tried so far was,
1) Declare a tensor of size (3x32x32). Lets call it image. `image = torch.Tensor(3x32x32). forward pass this.
model:forward(image)
It produces the error ...h/install/share/lua/5.1/nn/SpatialBatchNormalization.lua:68: only mini-batch supported (4D tensor), got 3D tensor instead
2) I reshaped the image to (1,3,32,32)
image = image:reshape(1,3,32,32)
forward pass this
model:forward(image)
It produces the error ...ch/torch/install/share/lua/5.1/nn/BatchNormalization.lua:67: only mini-batch supported (2D tensor), got 1D tensor instead
So I tried out approaches. But could not figure out how to pass a single image to that network. Can you help me out?
The model definition is
require 'nn' local vgg = nn.Sequential() -- building block local function ConvBNReLU(nInputPlane, nOutputPlane) vgg:add(nn.SpatialConvolution(nInputPlane, nOutputPlane, 3,3, 1,1, 1,1)) vgg:add(nn.SpatialBatchNormalization(nOutputPlane,1e-3)) vgg:add(nn.ReLU(true)) return vgg end -- Will use "ceil" MaxPooling because we want to save as much feature space as we can local MaxPooling = nn.SpatialMaxPooling ConvBNReLU(3,64):add(nn.Dropout(0.3)) ConvBNReLU(64,64) vgg:add(MaxPooling(2,2,2,2):ceil()) ConvBNReLU(64,128):add(nn.Dropout(0.4)) ConvBNReLU(128,128) vgg:add(MaxPooling(2,2,2,2):ceil()) ConvBNReLU(128,256):add(nn.Dropout(0.4)) ConvBNReLU(256,256):add(nn.Dropout(0.4)) ConvBNReLU(256,256) vgg:add(MaxPooling(2,2,2,2):ceil()) ConvBNReLU(256,512):add(nn.Dropout(0.4)) ConvBNReLU(512,512):add(nn.Dropout(0.4)) ConvBNReLU(512,512) vgg:add(MaxPooling(2,2,2,2):ceil()) ConvBNReLU(512,512):add(nn.Dropout(0.4)) ConvBNReLU(512,512):add(nn.Dropout(0.4)) ConvBNReLU(512,512) vgg:add(MaxPooling(2,2,2,2):ceil()) vgg:add(nn.View(512)) vgg:add(nn.Dropout(0.5)) vgg:add(nn.Linear(512,512)) vgg:add(nn.BatchNormalization(512)) vgg:add(nn.ReLU(true)) vgg:add(nn.Dropout(0.5)) vgg:add(nn.Linear(512,10)) -- initialization from MSR local function MSRinit(net) local function init(name) for k,v in pairs(net:findModules(name)) do local n = v.kW*v.kH*v.nOutputPlane v.weight:normal(0,math.sqrt(2/n)) v.bias:zero() end end init'nn.SpatialConvolution' end MSRinit(vgg) return vgg