Search code examples
network-programmingmachine-learningluaneural-networktorch

Temporal CNN to classify sounds: cur_target assertion


I want to build a CNN in Torch to classify (small) audio recordings. I have some samples, each with 16608x1 samples (I can compress them if they are too big). There are about 300 samples (900 if needed, but I want to try with this smaller set first) to be classified into 30 classes.

Here's what I've written so far:

net = nn.Sequential()
-- 1
net:add( nn.TemporalConvolution(1, 640, 1529) )
net:add( nn.TemporalMaxPooling(4) )
net:add( nn.LogSoftMax() )
-- 2
net:add( nn.TemporalConvolution(640, 15, 647) )
net:add( nn.TemporalMaxPooling(9) )
net:add( nn.LogSoftMax() )
-- review
net:add( nn.View(347 * 15) )
net:add( nn.Linear(347 * 15, 450) )
net:add( nn.ReLU() )
net:add( nn.Linear(450, 128) )
net:add( nn.ReLU() )
net:add( nn.Linear(128, 30) )
net:add( nn.LogSigmoid() )

-- class setup
-- mean to 0, stdv to 1

criterion = nn.ClassNLLCriterion()
trainer = nn.StochasticGradient(net, criterion)
trainer.learningRate = 0.01
trainer.maxIteration = 15
trainer:train(trainset)

When I run it, there's an error in ClassNLLCriterion.c with error on the assertion (cur_target >= 0 && cur_target < n_classes).

Also, all numbers are experimental and I'm experimenting (this is one of my first CNN)


Solution

  • It seems that your target class is out of range. You defined the network to have 30 classes as output of your network, but perhaps your trainset has < 1 or > 30 classes.

    Also, be aware that in torch classes are indexed 1 to N.