我正在尝试创建一个可以区分任何两个或多个类别的基本图像分类项目。 我已经编写了以下代码,并在标题中收到上面所述的错误。 我该如何解决这个错误? 下面是我的代码
from keras.preprocessing import image
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential
from keras.layers import Conv2D,MaxPooling2D
from keras.layers import Activation,Dropout,Flatten,Dense
from keras import backend as k
import numpy as np
img_width,img_height = 64,64
train_data_dir = 'dataset/training_set'
validation_data_dir = 'dataset/test_set'
nb_train_samples = 1000
nb_validation_samples = 100
epochs = 50
batch_size = 20
if k.image_data_format() == 'channel-first':
input_shape = (3,img_width,img_height)
else:
input_shape = (img_width,img_height,3)
train_datagen = ImageDataGenerator(rescale = 1./255,
shear_range = 0.2,
zoom_range = 0.2,
horizontal_flip = True)
test_datagen = ImageDataGenerator(rescale = 1./255)
train_generator = train_datagen.flow_from_directory(
train_data_dir,
target_size=(img_width,img_height),
batch_size = batch_size,
class_mode = 'binary')
validation_generator=test_datagen.flow_from_directory(
validation_data_dir,
target_size = (img_width,img_height),
batch_size = batch_size,
class_mode = 'binary')
model = Sequential()
model.add(Conv2D(32,(3,3),input_shape = input_shape))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size = (2,2)))
model.summary()
model.add(Conv2D(32,(3,3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size = (2,2)))
#model.add(Conv2D(64,(3,3)))
#model.add(Activation('relu'))
#model.add(MaxPooling2D(pool_size = (2,2)))
model.summary()
model.add(Flatten())
model.add(Dense(units = 128, activation = "relu"))
model.add(Dense(units = 1, activation = "sigmoid"))
model.add(Dropout(0.5))
optimizer = keras.optimizers.sgd(lr = 0.1)
model.compile(loss='binary_crossentropy',
optimizer = optimizer,
metrices = ['accuracy'])
model.fit_generator(train_generator,
steps_per_epoch = nb_train_samples // batch_size,
epochs = epochs,
validation_data = validation_generator,
validation_steps = nb_validation_samples // batch_size)
每行都可以正常工作,但最后一段代码除外。 在运行最后一段代码时, 我收到以下错误
(“目前不支持session_kwargs中的某些键:%s”,dict_keys(['metrices']))
答案 0 :(得分:0)
您要寻找metrics
而不是metrices
吗?