r - Does the number of hidden nodes in the fully connected layer has to be equal to the number of output categories? -
i tried tutorial image recognition in r using mxnet package https://www.r-bloggers.com/image-recognition-tutorial-in-r-using-deep-convolutional-neural-networks-mxnet-package . aim of tutorial recognize faces of 40 persons. dataframe consists of 400 pictures (10 pictures per person). cnn looks this:
data <- mx.symbol.variable('data') # 1st convolutional layer conv_1 <- mx.symbol.convolution(data = data, kernel = c(5, 5), num_filter = 20) tanh_1 <- mx.symbol.activation(data = conv_1, act_type = "tanh") pool_1 <- mx.symbol.pooling(data = tanh_1, pool_type = "max", kernel = c(2, 2), stride = c(2, 2)) # 2nd convolutional layer conv_2 <- mx.symbol.convolution(data = pool_1, kernel = c(5, 5), num_filter = 50) tanh_2 <- mx.symbol.activation(data = conv_2, act_type = "tanh") pool_2 <- mx.symbol.pooling(data=tanh_2, pool_type = "max", kernel = c(2, 2), stride = c(2, 2)) # 1st connected layer flatten <- mx.symbol.flatten(data = pool_2) fc_1 <- mx.symbol.fullyconnected(data = flatten, num_hidden = 500) tanh_3 <- mx.symbol.activation(data = fc_1, act_type = "tanh") # 2nd connected layer fc_2 <- mx.symbol.fullyconnected(data = tanh_3, num_hidden = 40) # output. softmax output since we'd probabilities. nn_model <- mx.symbol.softmaxoutput(data = fc_2) i used same neuronal network own dataset, consists of 1600 pictures of 5 persons. adjusted number of nodes in connected layer 5.
fc_2 <- mx.symbol.fullyconnected(data = tanh_3, num_hidden = 5) the results of model bad, set ceteris paribus number of nodes in connected layer 80 , got great results (accurancy: 100%).
fc_2 <- mx.symbol.fullyconnected(data = tanh_3, num_hidden = 80) the model generates probabilities 80 categories although got 5, accurancy excellent. don’t understand event. tried add third connected layer right number of catgories:
# 2nd connected layer fc_2 <- mx.symbol.fullyconnected(data = tanh_3, num_hidden = 80) tanh_4 <- mx.symbol.activation(data = fc_2, act_type = "tanh") # 3rd connected layer fc_3 <- mx.symbol.fullyconnected(data = tanh_4, num_hidden = 5) # output. softmax output since we'd probabilities. nn_model <- mx.symbol.softmaxoutput(data = fc_3) but results bad. thought number of nodes in connected layer represents number of output categories model should try distinguish.
- is possible explain event?
- does number of hidden nodes in connected layer has equal number of output categories?
thanks help.
you have more parameters in model samples. typically bad, , can cause on fitting.
another approach can take taking pre-trained model, , re-train last layer data (aka transfer learning). here's mxnet tutorial that: https://mxnet.incubator.apache.org/how_to/finetune.html
Comments
Post a Comment