Hi,
Could you share full traceback ? (including the line number)
Ramana
i am doing face recognition with convolution neural network here is my code
>
> def load_dataset():
> x_train=np.loadtxt('c:/database/gray_train.txt')
> #x_train=train.read()
> y_train=np.loadtxt('c:/database/y_train.txt')
> x_val=np.loadtxt('c:/database/gray_test.txt')
> y_val=np.loadtxt('c:/database/y_test.txt')
> return x_train,y_train,x_val,y_val
>
> def build_cnn(input_var=None):
>
> l_in=L.InputLayer(shape=((None,3364)),input_var=input_var) #batch size is
> 100
> l_shape=L.ReshapeLayer(l_in,(-1,1,58,58))
>
> l_conv=L.Conv2DLayer(l_shape,num_filters=16,filter_size=(5,5),stride=(1,1),pad=0,nonlinearity=l.nonlinearities.rectify)
> pool1=L.Pool2DLayer(l_conv,2)
>
> l_conv2=L.Conv2DLayer(pool1,num_filters=32,filter_size=(4,4),stride=(1,1),pad=0,nonlinearity=l.nonlinearities.rectify)
>
> pool2=L.Pool2DLayer(l_conv2,2)
>
> l_conv3=L.Conv2DLayer(pool2,num_filters=48,filter_size=(3,3),stride=(2,2),pad=0,nonlinearity=l.nonlinearities.rectify)
> pool3=L.Pool2DLayer(l_conv3,2)
> fc1=L.DenseLayer(pool3,num_units=128)
> l_output = L.DenseLayer(fc1,
> num_units=16,nonlinearity=l.nonlinearities.softmax)
> return l_output
>
>
> def batch_gen(X,y,N):
> while True:
> idx=np.random.choice(len(y),N)
>
> yield X[idx].astype('float32'),y[idx].astype('int32')
>
> x_train,y_train,x_val,y_val=load_dataset()
> x_sym=T.matrix()
> y_sym=T.ivector()
> l_out=build_cnn(x_sym)
> output=L.get_output(l_out,x_sym)
> pred=output.argmax(-1)
> loss=T.mean(l.objectives.squared_error(output,y_sym))
> acc=T.mean(T.eq(pred,y_sym))
> params=L.get_all_params(l_out,Trainable=True)
> grad=T.grad(loss,params)
> updates=l.updates.sgd(grad,params,learning_rate=0.001)
> f_train=t.function([x_sym,y_sym],[loss,acc],updates=updates)
> f_val=t.function([x_sym,y_sym],[loss,acc])
> f_predict=t.function([x_sym],pred)
> batch_size=100
> regression=True
> max_epoch=10
> verbose=1
> n_batches=len(x_train)//batch_size
> n_val_batches=len(x_val)//batch_size
> train_batches=batch_gen(x_train,y_train,batch_size)
> val_batches=batch_gen(x_val,y_val,batch_size)
> for epoch in range(max_epoch):
> train_loss=0
> train_acc=0
> for _ in range(n_batches):
> x,y=next(train_batches)
> #print(y)
> loss,acc=f_train(x,y)
> train_loss+=loss
> train_acc+=acc
> train_loss/=n_batches
> train_acc/=n_batches
>
> val_loss=0
> val_acc=0
> for _ in range(n_val_batches):
> x,y=next(val_batches)
> loss,acc=f_val(x,y)
> val_loss/=n_val_batches
> val_acc/=n_val_batches
> print(epoch,train_loss,train_acc,val_loss/train_loss)
>
>
> and i am getting error in loss,acc=f_train(x,y) error is x_sym=T.matrix()
>
> Wrong number of dimensions: expected 2, got 1 with shape (100,). how to
> resolve this issue i did resize x after x,y=next(train_batches) but then i
> got an other error that says (100,1) can't be reshaped in [-1 58 58] in
> reshape layer
>
>
--
---
You received this message because you are subscribed to the Google Groups
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.