Erroy GPU ResourceExhaustedError我正在使用nvidia gtx 1050 ti 4GB图形卡

时间:2019-02-25 21:40:39

标签: deep-learning

错误=>

ResourceExhaustedError(请参见上面的回溯):分配形状为[301056,1000]的张量并在/ job:localhost / replica:0 / task:0 / device:GPU:0上通过分配器GPU_0_bfc键​​入float      [[节点训练/ Adam / Variable_10 / Assign(定义在C:\ Users \ Arham \ Anaconda3 \ lib \ site-packages \ keras \ backend \ tensorflow_backend.py:402)=分配[T = DT_FLOAT,_grappler_relax_allocator_constraints = true,use_locking = true,validate_shape = true,_device =“ / job:localhost /副本:0 /任务:0 /设备:GPU:0”](训练/ Adam / Variable_10,训练/ Adam / zeros_10)]] 提示:如果要在发生OOM时查看分配的张量的列表,请将report_tensor_allocations_upon_oom添加到RunOptions中以获取当前分配信息。

from keras.models import Sequential
from keras.layers import Conv2D,ZeroPadding2D,Activation
from keras.layers import MaxPooling2D
from keras.layers import Flatten
from keras.layers import Dense,Dropout

classifier = Sequential()

#Layer1
classifier.add(Conv2D(96, (11, 11), input_shape = (224, 224, 3),padding='same'))
classifier.add(Activation('relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))

#Layer 2
classifier.add(Conv2D(256, (5, 5),padding="same"))
classifier.add(Activation('relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))

#Layer 3
classifier.add(ZeroPadding2D((1, 1)))
classifier.add(Conv2D(384, (3, 3)))
classifier.add(Activation('relu'))

#Layer 4
classifier.add(ZeroPadding2D((1, 1)))
classifier.add(Conv2D(384, (3, 3)))
classifier.add(Activation('relu'))

#Layer 5
classifier.add(ZeroPadding2D((1, 1)))
classifier.add(Conv2D(384, (3, 3)))
classifier.add(Activation('relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))

#Layer 6
classifier.add(Flatten())
classifier.add(Dense(1000))
classifier.add(Activation('relu'))
classifier.add(Dropout(0.5))

#Layer 7
classifier.add(Dense(1000))
classifier.add(Activation('relu'))
classifier.add(Dropout(0.5))

#Layer 8
classifier.add(Dense(3))
classifier.add(Activation('softmax'))


classifier.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['accuracy'])


from keras.preprocessing.image import ImageDataGenerator

train_datagen = ImageDataGenerator(rescale = 1./255,
                                   shear_range = 0.2,
                                   zoom_range = 0.2,
                                   horizontal_flip = True)

test_datagen = ImageDataGenerator(rescale = 1./255)



training_set = train_datagen.flow_from_directory('Data/Images/train',
                                                 target_size = (224, 224),
                                                 batch_size = 8,
                                                 class_mode = 'categorical')

test_set = test_datagen.flow_from_directory('Data/Images/test',
                                            target_size = (224 ,224),
                                            batch_size = 8,
                                            class_mode = 'categorical')


classifier.fit_generator(training_set,
                         steps_per_epoch=15103/8, 
                         epochs=25,
                         validation_data = test_set,
                         validation_steps = 6050/8)

0 个答案:

没有答案