Using Convolution Neural Net with Lasagne in Python error -
i have used frame work provided daniel nouri on eponymous website. here code used.it looks fine change made change output_nonlinearity=lasagne.nonlinearities.softmax , regression false.otherwise looks pretty straight forward
from lasagne import layers import theano lasagne.updates import sgd,nesterov_momentum nolearn.lasagne import neuralnet sklearn.metrics import classification_report import lasagne import cv2 import numpy np sklearn.cross_validation import train_test_split sklearn.datasets import fetch_mldata import sys mnist = fetch_mldata('mnist original') x = np.asarray(mnist.data, dtype='float32') y = np.asarray(mnist.target, dtype='int32') (trainx, testx, trainy, testy) = train_test_split(x,y,test_size =0.3,random_state=42) trainx = trainx.reshape(-1, 1, 28, 28) testx = testx.reshape(-1, 1, 28, 28) clf = neuralnet( layers=[ ('input', layers.inputlayer), ('conv1', layers.conv2dlayer), ('pool1', layers.maxpool2dlayer), ('dropout1', layers.dropoutlayer), # ! ('conv2', layers.conv2dlayer), ('pool2', layers.maxpool2dlayer), ('dropout2', layers.dropoutlayer), # ! ('hidden4', layers.denselayer), ('dropout4', layers.dropoutlayer), # ! ('hidden5', layers.denselayer), ('output', layers.denselayer), ], input_shape=(none,1, 28, 28), conv1_num_filters=20, conv1_filter_size=(3, 3), pool1_pool_size=(2, 2), dropout1_p=0.1, # ! conv2_num_filters=50, conv2_filter_size=(3, 3), pool2_pool_size=(2, 2), dropout2_p=0.2, # ! hidden4_num_units=500, dropout4_p=0.5, # ! hidden5_num_units=500, output_num_units=10, output_nonlinearity=lasagne.nonlinearities.softmax, update=nesterov_momentum, update_learning_rate=theano.shared(float32(0.03)), update_momentum=theano.shared(float32(0.9)), regression=false, max_epochs=3000, verbose=1, ) clf.fit(trainx,trainy)
however on running nan
input (none, 1, 28, 28) produces 784 outputs conv1 (none, 20, 26, 26) produces 13520 outputs pool1 (none, 20, 13, 13) produces 3380 outputs dropout1 (none, 20, 13, 13) produces 3380 outputs conv2 (none, 50, 11, 11) produces 6050 outputs pool2 (none, 50, 6, 6) produces 1800 outputs dropout2 (none, 50, 6, 6) produces 1800 outputs hidden4 (none, 500) produces 500 outputs dropout4 (none, 500) produces 500 outputs hidden5 (none, 500) produces 500 outputs output (none, 10) produces 10 outputs epoch train loss valid loss train/val valid acc dur ------- ------------ ------------ ----------- ----------- ------ 1 nan nan nan 0.09923 16.18s 2 nan nan nan 0.09923 16.45s
thanks in advance.
i'm late game, finds answer useful!
in experience, there number of things going wrong here. i'll write out steps debugging kind of problem in nolearn/lasagne:
using theano's
fast_compile
optimizer can lead underflow issues, result innan
output (this ultimate problem in case)when output starts
nan
values, or ifnan
values start appearing after training starts, learning rate may high. if0.01
, try , make0.001
.the input or output values may close 1 another, , may want try scaling them. standard approach scale input subtracting mean , dividing standard deviation.
make sure using
regression=true
when using nolearn regression problemtry using linear output instead of softmax. other nonlinearities help, in experience not often.
if fails, try , isolate whether issue network or data. if feed in random values within expected range , still
nan
output, it's not specific dataset training on.
hope helps!
Comments
Post a Comment