我使用以下代码构建CNN模型
model = Sequential()
model.add(Convolution2D(32, (5, 5), activation='relu', input_shape=(3, height, width), data_format='channels_first'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(filters=36, kernel_size=(5, 5), activation='relu'))
model.add(Conv2D(32, (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(2, activation='softmax'))
model.compile(loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
batch_steps = get_training_data_batch()
model.fit_generator(training_data_generator(), steps_per_epoch=batch_steps, epochs=15, verbose=2)
model.summary()
x_test, y_test = get_testing_data()
score = model.evaluate(x_test, y_test, verbose=0)
print("score:", score[1])
batch_size = 2000
def training_data_generator():
for benchmark_num in training_benchmark_num_list:
x_data, y_data = get_feature_data(benchmark_num)
samples_totals = x_data.shape[0]
print("samples totals:", samples_totals)
batch = samples_totals / batch_size + 1
for x in range(0, int(batch), 1):
x_sub_data = x_data[x*batch_size:(x+1)*batch_size]
y_sub_data = y_data[x*batch_size:(x+1)*batch_size]
x_train = x_sub_data.reshape(x_sub_data.shape[0], 3, height, width)
x_train = x_train.astype('float32')
x_train /= 255
y_train = np_utils.to_categorical(y_sub_data, 2)
yield (x_train, y_train)
程序在代码转储前显示错误:
我跟踪了tensorflow源代码,应该检查操作。而backprop指数不能为负。我不知道张量好,为什么会出现这样的问题?我认为这个错误是代码转储的根本原因。你能帮我解决这个问题吗?F tensorflow / core / kernels / maxpooling_op.cc:177] 检查失败:input_backprop_index> = in_start&& input_backprop_index< in_end输入backprop索引无效:-1491167680,2803712000,2806515712