nicholas-leonard / dp

A deep learning library for streamlining research and development using the Torch7 distribution.
Other
343 stars 140 forks source link

How to create a dataSource for CNN? #136

Closed deepakjnath closed 9 years ago

deepakjnath commented 9 years ago

Hello @nicholas-leonard ,

I am working on a classification problem for images. I have local training data which i have extracted to a tensor of 35000 images classified into 5 labels. {tensor(35000x3x256x256), labels}

I am trying to create a dataSource to work with https://github.com/nicholas-leonard/dp/blob/master/examples/convolutionneuralnetwork.lua

I am finding it difficult to get information on this. I looked at facialkeypoint example,

Could you please help me on how to create a DataSource?

Thanks a ton & appreciate your excellent work. Deepak

deepakjnath commented 9 years ago

Here is the code that I used to get it working.

require 'dp'

function djLoadData(which_set)

trData = torch.load('train_data.t7','ascii')
trLabel = torch.load('train_label.t7','ascii')

local input_v, target_v = dp.ImageView(), dp.ClassView()
input_v:forward('bchw', trData)

targets = trLabel
targets:add(1)
targets = targets:type('torch.DoubleTensor')

--print(trData[1])
--print(trLabel[1])
--print(trLabel)
target_v:forward('bt',trLabel)
target_v:setClasses({0,1,2,3,4})

local ds = dp.DataSet{inputs=input_v,targets=target_v,which_set=which_set}
ds:ioShapes('bchw', 'b')
return ds

end