{"action":"created","issue":{"url":"https://api.github.com/repos/alexbw/bayarea-dl-summerschool/issues/4","repository_url":"https://api.github.com/repos/alexbw/bayarea-dl-summerschool","labels_url":"https://api.github.com/repos/alexbw/bayarea-dl-summerschool/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/alexbw/bayarea-dl-summerschool/issues/4/comments","events_url":"https://api.github.com/repos/alexbw/bayarea-dl-summerschool/issues/4/events","html_url":"https://github.com/alexbw/bayarea-dl-summerschool/issues/4","id":192345310,"number":4,"title":"Training error. Help","user":{"login":"ilichev-andrey","id":24242890,"avatar_url":"https://avatars.githubusercontent.com/u/24242890?v=3","gravatar_id":"","url":"https://api.github.com/users/ilichev-andrey","html_url":"https://github.com/ilichev-andrey","followers_url":"https://api.github.com/users/ilichev-andrey/followers","following_url":"https://api.github.com/users/ilichev-andrey/following{/other_user}","gists_url":"https://api.github.com/users/ilichev-andrey/gists{/gist_id}","starred_url":"https://api.github.com/users/ilichev-andrey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ilichev-andrey/subscriptions","organizations_url":"https://api.github.com/users/ilichev-andrey/orgs","repos_url":"https://api.github.com/users/ilichev-andrey/repos","events_url":"https://api.github.com/users/ilichev-andrey/events{/privacy}","received_events_url":"https://api.github.com/users/ilichev-andrey/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-29T17:20:54Z","updated_at":"2016-11-30T16:28:30Z","closed_at":null,"body":"\r\n\r\nHello.\r\nI teach a neural network for two of my classes.\r\nError occurs at the stage of training.\r\nHow to fix it?\r\n\r\nth> require 'nn';\r\nth> trainset = torch.load('animals_peoples2.t7')\r\nth> testset = torch.load('animals_peoples2.t7')\r\nth> classes = {'animals', 'peoples'}\r\n\r\nth> print(trainset)\r\n{\r\ndata : ByteTensor - size: 17299x3x96x96\r\nlabel : ByteTensor - size: 17299\r\n}\r\n\r\nth> print(#trainset.data)\r\n17299\r\n3\r\n96\r\n96\r\n[torch.LongStorage of size 4]\r\n\r\nth> setmetatable(trainset,\r\n..> {__index = function(t, i)\r\n..> return {\r\n..> t.data[i],\r\n..> t.label[i]\r\n..> }\r\n..> end}\r\n..> );\r\n\r\nth> function trainset:size()\r\n..> return self.data:size(1)\r\n..> end\r\n\r\nth> trainset.data = trainset.data:double()\r\n\r\nth> print(trainset:size())\r\n17299\r\n\r\nth> print(trainset[33])\r\n{\r\n1 : DoubleTensor - size: 3x96x96\r\n2 : 1\r\n}\r\n\r\nth> redChannel = trainset.data:select(2, 1)\r\n\r\nth> print(#redChannel)\r\n17299\r\n96\r\n96\r\n[torch.LongStorage of size 3]\r\n\r\nth> mean = {} -- store the mean, to normalize the test set in the future\r\n\r\nth> stdv = {} -- store the standard-deviation for the future\r\n\r\nth> for i=1,3 do -- over each image channel\r\n..> mean[i] = trainset.data:select(2, 1):mean() -- mean estimation\r\n..> print('Channel ' .. i .. ', Mean: ' .. mean[i])\r\n..> trainset.data:select(2, 1):add(-mean[i]) -- mean subtraction\r\n..>\r\n..> stdv[i] = trainset.data:select(2, i):std() -- std estimation\r\n..> print('Channel ' .. i .. ', Standard Deviation: ' .. stdv[i])\r\n..> trainset.data:select(2, i):div(stdv[i]) -- std scaling\r\n..> end\r\nChannel 1, Mean: 0\r\nChannel 1, Standard Deviation: 0\r\nChannel 2, Mean: nan\r\nChannel 2, Standard Deviation: 0\r\nChannel 3, Mean: nan\r\nChannel 3, Standard Deviation: 0\r\n\r\nth> net = nn.Sequential()\r\nth> net:add(nn.SpatialConvolution(3, 6, 9, 9)) -- 3 input image channels, 6 output channels, 5x5 convolution kernel\r\nth> net:add(nn.ReLU()) -- non-linearity\r\nth> net:add(nn.SpatialMaxPooling(2,2,2,2)) -- A max-pooling operation that looks at 2x2 windows and finds the max.\r\nth> net:add(nn.SpatialConvolution(6, 16, 9, 9))\r\nth> net:add(nn.ReLU()) -- non-linearity\r\nth> net:add(nn.SpatialMaxPooling(2,2,2,2))\r\nth> net:add(nn.View(1699)) -- reshapes from a 3D tensor of 16x5x5 into 1D tensor of 1655\r\nth> net:add(nn.Linear(1699, 120)) -- fully connected layer (matrix multiplication between input and weights)\r\nth> net:add(nn.ReLU()) -- non-linearity\r\nth> net:add(nn.Linear(120, 84))\r\nth> net:add(nn.ReLU()) -- non-linearity\r\nth> net:add(nn.Linear(84, 10)) -- 10 is the number of outputs of the network (in this case, 10 digits)\r\nth> net:add(nn.LogSoftMax()) -- converts the output to a log-probability. Useful for classification problems\r\n\r\nth> criterion = nn.ClassNLLCriterion()\r\n\r\nth> trainer = nn.StochasticGradient(net, criterion)\r\nth> trainer.learningRate = 0.001\r\nth> trainer.maxIteration = 5 -- just do 5 epochs of training.\r\n\r\nth> trainer:train(trainset)\r\n\r\ntrainer:train(trainset)\r\nStochasticGradient: training\r\n\r\n/root/facedetect/torch/install/share/lua/5.1/nn/THNN.lua:110: Assertion `THIndexTensor_(size)(target, 0) == batch_size' failed. at /tmp/luarocks_nn-scm-1-1625/nn/lib/THNN/generic/ClassNLLCriterion.c:50\r\nstack traceback:\r\n[C]: in function 'v'\r\n/root/facedetect/torch/install/share/lua/5.1/nn/THNN.lua:110: in function 'ClassNLLCriterion_updateOutput'\r\n...ect/torch/install/share/lua/5.1/nn/ClassNLLCriterion.lua:43: in function 'forward'\r\n...ct/torch/install/share/lua/5.1/nn/StochasticGradient.lua:35: in function 'train'\r\n[string \"_RESULT={trainer:train(trainset)}\"]:1: in main chunk\r\n[C]: in function 'xpcall'\r\n/root/facedetect/torch/install/share/lua/5.1/trepl/init.lua:661: in function 'repl'\r\n...tect/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:199: in main chunk\r\n[C]: at 0x004064f0\r\n"},"comment":{"url":"https://api.github.com/repos/alexbw/bayarea-dl-summerschool/issues/comments/263920550","html_url":"https://github.com/alexbw/bayarea-dl-summerschool/issues/4#issuecomment-263920550","issue_url":"https://api.github.com/repos/alexbw/bayarea-dl-summerschool/issues/4","id":263920550,"user":{"login":"ilichev-andrey","id":24242890,"avatar_url":"https://avatars.githubusercontent.com/u/24242890?v=3","gravatar_id":"","url":"https://api.github.com/users/ilichev-andrey","html_url":"https://github.com/ilichev-andrey","followers_url":"https://api.github.com/users/ilichev-andrey/followers","following_url":"https://api.github.com/users/ilichev-andrey/following{/other_user}","gists_url":"https://api.github.com/users/ilichev-andrey/gists{/gist_id}","starred_url":"https://api.github.com/users/ilichev-andrey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ilichev-andrey/subscriptions","organizations_url":"https://api.github.com/users/ilichev-andrey/orgs","repos_url":"https://api.github.com/users/ilichev-andrey/repos","events_url":"https://api.github.com/users/ilichev-andrey/events{/privacy}","received_events_url":"https://api.github.com/users/ilichev-andrey/received_events","type":"User","site_admin":false},"created_at":"2016-11-30T16:28:30Z","updated_at":"2016-11-30T16:28:30Z","body":"how to determine these parameters:\r\n\r\n5x5 convolution kernel?\r\nnet:add(nn.SpatialConvolution(3, 6, 5, 5))\r\n\r\nreshapes from a 3D tensor of 16x5x5 into 1D tensor of 16*5*5?\r\nnet:add(nn.View(16*5*5))\r\n"}}
{"actor":{"display_login":"ilichev-andrey"}}