Reputation: 49
I am using the Passenger Screening Challenge from the Kaggle website for a class project.
I've implemented an out-of-the-box Convolutional Neural Network from this tutorial: https://www.r-bloggers.com/image-recognition-tutorial-in-r-using-deep-convolutional-neural-networks-mxnet-package/.
Here is the code from the tutorial for the architecture:
# 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 fully 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 fully connected layer
fc_2 <- mx.symbol.FullyConnected(data = tanh_3, num_hidden = 40)
# Output. Softmax output since we'd like to get some probabilities.
NN_model <- mx.symbol.SoftmaxOutput(data = fc_2)
However, I have a question about the num_hidden
on the fc_2
. In the tutorial, this number was 40 because there were 40 classes.
In my example, I'm determining if there is a threat present on an image or not. Would my num_hidden
in the last fully connected layer be 2 (threat present or no threat) or 1 (probability that there is a threat present? Am I overthinking?
Upvotes: 0
Views: 319
Reputation: 66
Yes, if you are classifying a binary problem then the number of neurons in the fc2 layer should 2 instead of 40.
Upvotes: 1