2015-07-29 6 views
4

Я пытаюсь использовать код реализации от this page. Но я не могу решить, как правильно форматировать данные (набор обучающих наборов/тестов). Мой код:Как отформатировать комплекты обучения/тестирования для нейронной сети Deep Belief

numpy_rng = numpy.random.RandomState(123) 
    dbn = DBN(numpy_rng=numpy_rng, n_ins=2,hidden_layers_sizes=[50, 50, 50],n_outs=1) 

    train_set_x = [ 
     ([1,2],[2,]), #first element in the tuple is the input, the second is the output 
     ([4,5],[5,]) 
    ] 

    testing_set_x = [ 
     ([6,1],[3,]), #same format as the training set 
    ] 

    #when I looked at the load_data function found elsewhere in the tutorial (I'll show the code they used at the bottom for ease) I found it rather confusing, but this was my first attempt at recreating what they did 
    train_set_xPrime = [theano.shared(numpy.asarray(train_set_x[0][0],dtype=theano.config.floatX),borrow=True),theano.shared(numpy.asarray(train_set_x[0][1],dtype=theano.config.floatX),borrow=True)] 

    pretraining_fns = dbn.pretraining_functions(train_set_x=train_set_xPrime,batch_size=10,k=1) 

который произвел эту ошибку:

Traceback (most recent call last): 
     File "/Users/spudzee1111/Desktop/Code/NNChatbot/DeepBeliefScratch.command", line 837, in <module> 
     pretraining_fns = dbn.pretraining_functions(train_set_x=train_set_xPrime,batch_size=10,k=1) 
     File "/Users/spudzee1111/Desktop/Code/NNChatbot/DeepBeliefScratch.command", line 532, in pretraining_functions 
     n_batches = train_set_x.get_value(borrow=True).shape[0]/batch_size 
    AttributeError: 'list' object has no attribute 'get_value' 

Я не могу работать, как предполагается, вход должен быть отформатирован. Я попытался с помощью theano.shared в списке, так что было бы:

train_set_xPrime = theano.shared([theano.shared(numpy.asarray(train_set_x[0][0],dtype=theano.config.floatX),borrow=True),theano.shared(numpy.asarray(train_set_x[0][1],dtype=theano.config.floatX),borrow=True)],borrow=True) 

но потом сказал:

Traceback (most recent call last): 
     File "/Users/spudzee1111/Desktop/Code/NNChatbot/DeepBeliefScratch.command", line 834, in <module> 
     train_set_xPrime = theano.shared([theano.shared(numpy.asarray(train_set_x[0][0],dtype=theano.config.floatX),borrow=True),theano.shared(numpy.asarray(train_set_x[0][1],dtype=theano.config.floatX),borrow=True)],borrow=True) #,borrow=True),numpy.asarray(train_set_x[0][1],dtype=theano.config.floatX),borrow=True)) 
     File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/theano/compile/sharedvalue.py", line 228, in shared 
     (value, kwargs)) 
    TypeError: No suitable SharedVariable constructor could be found. Are you sure all kwargs are supported? We do not support the parameter dtype or type. value="[<TensorType(float64, vector)>, <TensorType(float64, vector)>]". parameters="{'borrow': True}" 

Я попробовал другие комбинации, но ни один из них не работал.

ответ

0

Это должно работать

numpy_rng = numpy.random.RandomState(123) 
dbn = DBN(numpy_rng=numpy_rng, n_ins=2, hidden_layers_sizes=[50, 50, 50], n_outs=1) 

train_set = [ 
    ([1,2],[2,]), 
    ([4,5],[5,]) 
] 

train_set_x = [train_set[i][0] for i in range(len(train_set))] 
nparray = numpy.asarray(train_set_x, dtype=theano.config.floatX) 
train_set_x = theano.shared(nparray, borrow=True) 

pretraining_fns = dbn.pretraining_functions(train_set_x=train_set_x, batch_size=10, k=1) 

Метод pretraining_fns ожидает в качестве вклада в общем переменном размере (количество образцов, измерение входов). Вы можете проверить это, посмотрев на форму набора данных MNIST, стандартный ввод для этого примера

Он не принимает список в качестве ввода, потому что этот метод предназначен только для функций предварительной подготовки. DBN предварительно подготовлены с помощью неконтролируемого алгоритма обучения, поэтому не имеет смысла использовать метки

Кроме того, список ввода для создания вашего массива numpy не имеет смысла. train_set_x[0][0] дает только первый пример обучения. Вы хотите, чтобы train_set_xPrime имел все примеры обучения. Даже если вы сделали train_set_x[0], у вас будет первый пример обучения, но с надписями