簡體   English   中英

Theano ValueError:y_i值超出范圍

[英]Theano ValueError: y_i value out of bound

我正在使用Theano實現神經網絡。 我的輸入大小為64個節點,隱藏層為500個節點,輸出為1個節點。

我的輸入是(1,000,000 * 64)矩陣,輸出是(1,000,000 * 1)矩陣。

我正在使用以下教程實現我的神經網絡。 http://deeplearning.net/tutorial/mlp.html#mlp

請幫忙!

我在下一行出錯了它導致我錯誤

##LOADING THE DATA FROM TXT FILE
train_set_x = numpy.loadtxt('x.txt', delimiter=',')
train_set_y = numpy.loadtxt('y.txt', delimiter=',')
train_set_x = theano.shared(numpy.asarray(train_set_x,
                                           dtype=theano.config.floatX),
                             borrow=True)
train_set_y = theano.shared(numpy.asarray(train_set_y,
                                           dtype=theano.config.floatX),
                             borrow=True)     
train_set_y = T.cast(train_set_y, 'int32')


....


##TRAINING FUNCTION
train_model = theano.function(
        inputs=[index],
        outputs=cost,
        updates=updates,
        givens={
            x: train_set_x[index * batch_size: (index + 1) * batch_size],
            y: train_set_y[index * batch_size: (index + 1) * batch_size]
        }
    )

....

##TRAINING
while (epoch < n_epochs) and (not done_looping):
        epoch = epoch + 1
        for minibatch_index in range(n_train_batches):
            minibatch_avg_cost = train_model(minibatch_index)

錯誤:

File "NN_main.py", line 276, in test_mlp
    minibatch_avg_cost = train_model(minibatch_index)
  File "C:\Users\wei\Anaconda2\lib\site-packages\theano\compile\function_module.py", line 871, in __call__
    storage_map=getattr(self.fn, 'storage_map', None))
  File "C:\Users\wei\Anaconda2\lib\site-packages\theano\gof\link.py", line 314, in raise_with_op
    reraise(exc_type, exc_value, exc_trace)
  File "C:\Users\wei\Anaconda2\lib\site-packages\theano\compile\function_module.py", line 859, in __call__
    outputs = self.fn()
ValueError: y_i value out of bounds
Apply node that caused the error: CrossentropySoftmaxArgmax1HotWithBias(Dot22.0, b, Elemwise{Cast{int32}}.0)
Toposort index: 21
Inputs types: [TensorType(float64, matrix), TensorType(float64, vector), TensorType(int32, vector)]
Inputs shapes: [(20L, 1L), (1L,), (20L,)]
Inputs strides: [(8L, 8L), (8L,), (4L,)]
Inputs values: ['not shown', array([ 0.]), 'not shown']
Outputs clients: [[Sum{acc_dtype=float64}(CrossentropySoftmaxArgmax1HotWithBias.0)], [CrossentropySoftmax1HotWithBiasDx(Elemwise{Inv}[(0, 0)].0, CrossentropySoftmaxArgmax1HotWithBias.1, Elemwise{Cast{int32}}.0)], []]

Backtrace when the node is created(use Theano flag traceback.limit=N to make it longer):
  File "NN_main.py", line 332, in <module>
    test_mlp()
  File "NN_main.py", line 193, in test_mlp
    + L2_reg * classifier.L2_sqr
  File "C:\wei\MyChessEngine\MyChessEngine\logistic_sgd.py", line 112, in negative_log_likelihood
    return -T.mean(T.log(self.p_y_given_x)[T.arange(y.shape[0]), y])

HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node.

如果有人仍然遇到同樣的錯誤,我今天遇到了這個問題,原因是因為我將類標記為1而不是0。

向MLP添加邏輯回歸層時,輸出數必須是您擁有的類數。 假設您正在處理二進制分類,則您的n_out必須為2。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM