Я тренирую модель со следующим резюме, используя tf.keras:
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d (Conv2D) (None, 28, 28, 20) 520
_________________________________________________________________
flatten (Flatten) (None, 15680) 0
_________________________________________________________________
dense (Dense) (None, 5) 78405
=================================================================
Total params: 78,925
Trainable params: 78,925
Non-trainable params: 0
_________________________________________________________________
Я вызываю метод подгонки, используя
model.fit(X_train, y_train, batch_size=32, steps_per_epoch=125, epochs=5, use_multiprocessing=True)
где X_trainпеременная тензорного потока с формой [900000,32,32,1].
Я сталкиваюсь со следующей ошибкой:
Resource exhausted: OOM when allocating tensor with shape[900000,28,28,20] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
[[{{node conv2d_1/Conv2D}}]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.
[[metrics_2/acc/Identity/_53]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.
(1) Resource exhausted: OOM when allocating tensor with shape[900000,28,28,20] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
[[{{node conv2d_1/Conv2D}}]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.
0 successful operations.
0 derived errors ignored.
Я не могу понять, почему он выделяет тензор сформа [900000,28,28,20], когда размер партии составляет 32. Я ожидал [32,28,28,20].
Полный код:
IMAGE_SIZE = 32
BATCH_SIZE = 32
conv1_layer = keras.layers.Conv2D(input_shape=(IMAGE_SIZE, IMAGE_SIZE, 1), filters=20, kernel_size=[5, 5], activation='relu')
f = keras.layers.Flatten()
output_layer = keras.layers.Dense(units=5, activation='softmax')
model = keras.models.Sequential(layers=[conv1_layer, f, output_layer])
model.compile(optimizer='sgd', loss='categorical_crossentropy', metrics=['accuracy'])
model.fit(X_train, y_train, batch_size=BATCH_SIZE, steps_per_epoch=int(X_train.shape[0])//BATCH_SIZE, epochs=5, use_multiprocessing=True)