vlfeat / matconvnet

MatConvNet: CNNs for MATLAB
Other
1.4k stars 752 forks source link

How to deal with one-channel data #224

Open tzczsq opened 9 years ago

tzczsq commented 9 years ago

Hi, I have 1000 samples with 45 dimension (45-1000). The class is 6. I change data into two channels, as done below. testdata = reshape(testdata,45,1,[]); traindata = reshape(traindata,45,1,[]); When I implement, an error is emerged, as described below. "The number of filter groups does not divide the total number of filters". It seems that CNN can not directly deal with one channnel data?

The CNN model is given below. %%%% input data: 45-1-number f=1/100 ; net.layers = {} ; net.layers{end+1} = struct('type', 'conv', ... 'filters', f_randn(6,1,1,120, 'single'), ... 'biases', zeros(1, 120, 'single'), ... 'stride', 1, ... 'pad', 0) ; net.layers{end+1} = struct('type', 'pool', ... 'method', 'max', ... 'pool', [1 1], ... 'stride', 1, ... 'pad', 0) ; net.layers{end+1} = struct('type', 'sigmoid') ;%%%{'sigmoid','tanh','relu','softmax'} net.layers{end+1} = struct('type', 'conv', ... 'filters', f_randn(40,1,120,6, 'single'),... 'biases', zeros(1,6,'single'), ... 'stride', 1, ... 'pad', 0) ; net.layers{end+1} = struct('type', 'softmaxloss') ;

CASIAHYH commented 9 years ago

Notice that, no matter how many channels the data has, the input data should always be a 4-D array: height x width x channel x num. In your case, I think it should be 1 x 1 x 45 x num, each sample is represented as a 3-D array, so the convoluiton can be applied. You have to understand the data structure that MatConvNet can accept.

tzczsq commented 9 years ago

Maybe you are wrong. I means that data dimension with one channnel is 45 x1. It should be be 45 x1 x1 x num, rather than 1 x1 x45 xnum, since the number of channel is one.

rahman-mdatiqur commented 9 years ago

I am in need of feeding data with dimension HxWxCx1 (batch size is 1). Is it possible to feed such data in MatconvNet? I am asking so because matlab drops any trailing singleton dimension, and therefore, would leave my data with HxWxC dimension instead of a 4-D array.

anyone could put some comment on it?

vedaldi commented 9 years ago

Hi, that should not be a problem as implicitly any array has infinite singleton dimensions suffixed. Unless there is a piece of code in MatConvNet that does something wrong, of course, but that would probably be a bug

On 6 Aug 2015, at 00:54, atique81 notifications@github.com wrote:

I am in need of feeding data with dimension HxWxCx1 (batch size is 1). Is it possible to feed such data in MatconvNet? I am asking so because matlab drops any trailing singleton dimension, and therefore, would leave my data with HxWxC dimension instead of a 4-D array.

anyone could put some comment on it?

— Reply to this email directly or view it on GitHub https://github.com/vlfeat/matconvnet/issues/224#issuecomment-128174648.

raphaeli commented 9 years ago

Hi, I try to use matconvnet in a time-series problem. The dataset is D=Num_recs x Num_dim where Num_recs=9545 stands for the number of records and Num_dim for the dimensionality which is 227. So D is a collection of 9545 different cases of 1x227 vectors. I reshape D using reshape(data,1,227,1,9545) to 1x227x1x9545 as it is obviously a 1-channel problem. The first layer is: net.layers{end+1} = struct('type', 'conv', ... 'weights', {{0.01*randn(1,11,1,96, 'single'), zeros(1, 96, 'single')}}, ... 'stride', 4, ... 'pad', 0) ;

Please note that I take a net from the examples of matconvnet that expects as input a 227x227 image and I just turn the number of channels of the net to 1 and the first dimension to 1 and kind of expected to work. Do you see something wrong with the above? Has anyone even a trivial example on time-series classification using matconvnet to share? I get the same error as tzczsq

Thank you