title: ResourceExhaustedError error while training neural network
body: <p>All welcome. I'm trying to train my first neural network.</p>
  
  <p>When i'm try to train her - this error appears:</p>
  
  <blockquote>
    <p>tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM
    when allocating tensor with shape[502656,128] and type float on
    /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc</p>
  </blockquote>
  
  <p>I read, I realized that this is due to the fact that little memory in the video card (GTX 1050 2 gb).</p>
  
  <p>It turns out that I can’t use a video card here at all?</p>
  
  <p>Maybe i can somehow "portions" issue video card dataset?</p>
  
  <p>Code:</p>
  
  <pre><code>import keras
  from keras.datasets import mnist
  from keras.models import Sequential
  from keras.layers import Dense, Dropout, Flatten
  from keras.layers import Conv2D, MaxPooling2D
  from keras import backend as K
  import numpy as np
  
  batch_size = 1
  num_classes = 3
  epochs = 2
  
  # input image dimensions
  img_rows, img_cols = 135, 240
  
  dataset = Dataset()
  
  x_train, y_train = dataset.LoadDataset()
  
  x_train = x_train[0]
  y_train = y_train[0]
  
  x_train = np.array(x_train).reshape(10000, 135, 240, 1)
  
  input_shape = (img_rows, img_cols, 1)
  
  x_train = x_train.astype('float32')
  
  x_train = x_train / 255
  
  model = Sequential()
  model.add(Conv2D(32, kernel_size=(1, 1),
                   activation='relu',
                   input_shape=input_shape))
  model.add(Conv2D(64, (3, 3), activation='relu'))
  model.add(MaxPooling2D(pool_size=(2, 2)))
  model.add(Dropout(0.25))
  model.add(Flatten())
  model.add(Dense(128, activation='relu'))
  model.add(Dropout(0.5))
  model.add(Dense(num_classes, activation='softmax'))
  
  model.compile(loss=keras.losses.categorical_crossentropy,
                optimizer=keras.optimizers.Adadelta(),
                metrics=['accuracy'])
  
  model.fit([x_train], [y_train],
            batch_size=batch_size,
            epochs=epochs,
            verbose=1)
  
  model.save("First.model")
  
  score = model.evaluate([x_train], [y_train], verbose=0)
  
  print('Test loss:', score[0])
  print('Test accuracy:', score[1])
  </code></pre>