2017-01-26 5 views
1

Ich wollte mein Netz (Bildklassifizierung, leider auf der CPU) trainieren und ich habe 71.000 Datensätze: 48x48 (Graustufen) Bilder. (Wenn ich es zu einem numpy Array speichern ist es 1,4 Gb)Keras MemoryError: Alloc fehlgeschlagen auf Windows

Nach ein paar Minuten habe ich diese Fehlermeldung:

Epoch 1/50 
    3200/57419 [>.............................] - ETA: 5381s - loss: 1.9127 - acc: 0.2338Traceback (most recent call last): 
    File "D:/Emotion-Recognition/trainEmotionRecognizer.py", line 68, in <module> 
     verbose=1, callbacks=callbacks) 
    File "C:\Users\Gabor\Anaconda2\lib\site-packages\keras\models.py", line 664, in fit 
     sample_weight=sample_weight) 
    File "C:\Users\Gabor\Anaconda2\lib\site-packages\keras\engine\training.py", line 1143, in fit 
     initial_epoch=initial_epoch) 
    File "C:\Users\Gabor\Anaconda2\lib\site-packages\keras\engine\training.py", line 843, in _fit_loop 
     outs = f(ins_batch) 
    File "C:\Users\Gabor\Anaconda2\lib\site-packages\keras\backend\theano_backend.py", line 919, in __call__ 
     return self.function(*inputs) 
    File "C:\Users\Gabor\Anaconda2\lib\site-packages\theano\compile\function_module.py", line 886, in __call__ 
     storage_map=getattr(self.fn, 'storage_map', None)) 
    File "C:\Users\Gabor\Anaconda2\lib\site-packages\theano\gof\link.py", line 325, in raise_with_op 
     reraise(exc_type, exc_value, exc_trace) 
    File "C:\Users\Gabor\Anaconda2\lib\site-packages\theano\compile\function_module.py", line 873, in __call__ 
     self.fn() if output_subset is None else\ 
    MemoryError: alloc failed 
    Apply node that caused the error: Alloc(TensorConstant{(1L, 1L, 1..1L) of 0.0}, if{shape,inplace}.0, TensorConstant{64}, if{shape,inplace}.2, if{shape,inplace}.3) 
    Toposort index: 126 
    Inputs types: [TensorType(float32, (True, True, True, True)), TensorType(int64, scalar), TensorType(int64, scalar), TensorType(int64, scalar), TensorType(int64, scalar)] 
    Inputs shapes: [(1L, 1L, 1L, 1L),(),(),(),()] 
    Inputs strides: [(4L, 4L, 4L, 4L),(),(),(),()] 
    Inputs values: [array([[[[ 0.]]]], dtype=float32), array(64L, dtype=int64), array(64L, dtype=int64), array(24L, dtype=int64), array(24L, dtype=int64)] 
    Outputs clients: [[if{inplace}(keras_learning_phase, Alloc.0, CorrMM_gradInputs{half, (1, 1), (1, 1)}.0), if{inplace}(keras_learning_phase, CorrMM_gradInputs{half, (1, 1), (1, 1)}.0, Alloc.0)]] 

    Backtrace when the node is created(use Theano flag traceback.limit=N to make it longer): 
    File "C:\Users\Gabor\Anaconda2\lib\site-packages\theano\gradient.py", line 1272, in access_grad_cache 
     term = access_term_cache(node)[idx] 
    File "C:\Users\Gabor\Anaconda2\lib\site-packages\theano\gradient.py", line 965, in access_term_cache 
     output_grads = [access_grad_cache(var) for var in node.outputs] 
    File "C:\Users\Gabor\Anaconda2\lib\site-packages\theano\gradient.py", line 1272, in access_grad_cache 
     term = access_term_cache(node)[idx] 
    File "C:\Users\Gabor\Anaconda2\lib\site-packages\theano\gradient.py", line 965, in access_term_cache 
     output_grads = [access_grad_cache(var) for var in node.outputs] 
    File "C:\Users\Gabor\Anaconda2\lib\site-packages\theano\gradient.py", line 1272, in access_grad_cache 
     term = access_term_cache(node)[idx] 
    File "C:\Users\Gabor\Anaconda2\lib\site-packages\theano\gradient.py", line 1106, in access_term_cache 
     new_output_grads) 
    File "C:\Users\Gabor\Anaconda2\lib\site-packages\theano\gof\op.py", line 700, in L_op 
     return self.grad(inputs, output_grads) 
    File "C:\Users\Gabor\Anaconda2\lib\site-packages\theano\ifelse.py", line 223, in grad 
     for i, t in enumerate(ts)]) 

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

ich meinen Laptop zu benutzen, die 8GB RAM hat und als ich das sah, Leistung, wenn das Training läuft und nach einer Weile 100% davon verbraucht.

Ich habe keine Ahnung, wie ich mein Netz jetzt trainieren könnte.

Dies ist die Modellstruktur:

model = Sequential() 
model.add(Convolution2D(32, 3, 3, border_mode='same', activation='relu', input_shape=(1,48,48))) 
model.add(Dropout(0.3)) 
model.add(Convolution2D(32, 3, 3, border_mode='same', activation='relu')) 
model.add(Dropout(0.3)) 
model.add(Convolution2D(32, 3, 3, border_mode='same', activation='relu')) 
model.add(MaxPooling2D(pool_size=(2, 2))) 

model.add(Convolution2D(64, 3, 3, border_mode='same', activation='relu')) 
model.add(Dropout(0.3)) 
model.add(Convolution2D(64, 3, 3, border_mode='same', activation='relu')) 
model.add(Dropout(0.3)) 
model.add(Convolution2D(64, 3, 3, border_mode='same', activation='relu')) 
model.add(MaxPooling2D(pool_size=(2, 2))) 

model.add(Convolution2D(128, 3, 3, border_mode='same', activation='relu')) 
model.add(Dropout(0.3)) 
model.add(Convolution2D(128, 3, 3, border_mode='same', activation='relu')) 
model.add(Dropout(0.3)) 
model.add(Convolution2D(128, 3, 3, border_mode='same', activation='relu')) 
model.add(MaxPooling2D(pool_size=(2, 2))) 

model.add(Flatten()) 
model.add(Dense(256, activation='relu')) 
model.add(Dropout(0.5)) 
model.add(Dense(64, activation='relu')) 
model.add(Dropout(0.5)) 
model.add(Dense(32, activation='relu')) 
model.add(Dropout(0.5)) 
model.add(Dense(6, activation='softmax')) 

ich eine Chargengröße von verwenden 64 und den Zug Bildgröße ist (1, 48, 48) with dtype = uint8

Wie kann ich diesen Fehler zu beheben und mein Netzwerk trainieren?

+1

Versuchen kleinere Chargen verwenden –

+0

ich auch vor kurzem über dieses Problem kam. Versuchen Sie, Ihren Python-Kernel neu zu starten, und führen Sie die Modellkompilierung und das Training erneut aus. Es ist wahrscheinlich ein Speicherleck in einer neuesten Version von Theano –

Antwort

0

Um den Speicherbedarf zu reduzieren, kann entweder die Größe des Modells reduziert werden (Dropout benötigt ebenfalls Speicher, der der vorherigen Convolution-Ebene entspricht) oder Sie können die Batchgröße reduzieren. Wie auch immer, ein solches Modell auf der CPU zu trainieren, könnte Tage dauern, wenn nicht Wochen. Ich würde dringend empfehlen, dies auf einer GPU zu berechnen, wenn möglich.

+0

Ich würde das tun, aber leider habe ich keine gute GPU (und unter Windows kann ich nicht erreichen) und ich kann nicht bei AWS registrieren (weil ich nicht keine akzeptierte Kreditkarte haben). Wie ich es berechnet habe, würde es 3 Tage dauern, um es auf CPU zu trainieren. –

1

Es stellt sich heraus, dass Theano Speicherverlust hat. Als ich versuchte, es mit Tensorflow als Keras Backend zu trainieren, war es erfolgreich.

So Wenn Sie ein Problem wie das hat, das Backend ändern (achten Sie auf dim_ordering)