gl.neuralnet_classifier.create throws error - hidden units is different than output class

User 1241 | 1/31/2015, 1:13:51 AM

Hi, I am trying to create a neuralnet_classifier using the deep learning api, and I couldn't manage to create the training model. See API call and the error below. The error suggests that I could call net.verify() to set the same hidden units and the same output classes. So, I do the following.

net.params['numhiddenunits'] = 2 net.verify(inputshape=[256,256,3], outputshape=2)

which also give producing similar error. Any guidance would be appreciated. Thanks

ERROR: m = gl.neuralnetclassifier.create(train[['image', 'id']],
target='id', network=net, mean
image=meanimage,
metric=['accuracy','recall@5'],
max
iterations=35,
modelcheckpointpath=WORKINGDIR + '/result/modelcheckpoint', modelcheckpointinterval=5,
batch_size=150)


ValueError Traceback (most recent call last) <ipython-input-29-456ff103f62e> in <module>() 8 modelcheckpointpath=WORKINGDIR + '/result/modelcheckpoint', 9 modelcheckpointinterval=5, ---> 10 batch_size=150)

/home/graphlab/graphlabvirtualenv/local/lib/python2.7/site-packages/graphlab/toolkits/classifier/neuralnetclassifier.pyc in create(dataset, target, features, maxiterations, network, validationset, verbose, **kwargs) 944 "Please change the network and use net.verify() with " 945 "inputshape=%s, and outputshape=%s" % (str(inputshape), str(outputshape))) --> 946 raise ValueError(e.message + "\n" + msg) 947 948 # update network params

ValueError: The last FullConnectionLayer must have the same number of hidden units as the number of output classes. Try setting numhiddenunits to 2. The input network is valid, but is not compatible with the input and output shape of the dataset. Please change the network and use net.verify() with inputshape=[256, 256, 3], and outputshape=2

Comments

User 1190 | 1/31/2015, 8:21:34 PM

Hi,

The error message suggest the output layer should only have 2 hidden units because the data have two classes. However, the net you give to the create function have a different number of hidden units, which is incompatible with your data. You can verify this by print net.

To change the number of hidden units for the last layer, you can try

<pre><code> net.layers[-1].numhiddenunits = 2. </code></pre>

For more details please see our documentation page. https://dato.com/products/create/docs/graphlab.toolkits.deeplearning.html

Thanks, Jay


User 1241 | 2/2/2015, 7:19:14 PM

Hey Jay,

The solution works, but I change the layer id to -2. Thanks for pointing to the right direction.

Thanks for the quick reply.
Kevin