請看看代碼,可以保存該模型識別率在開始時是好的,但連接模型的第二階段(連接相同的兩個模型)非常糟糕,我認爲它應該是m y保存模型和連接問題的過程,但控制檯中沒有錯誤,謝謝!
(X_train, y_train), (X_test, y_test) = faces_load_data()#the data is an numpy array
model = Sequential()the procedure is not being given
model.add(Convolution2D(32, 3, 3,
border_mode='valid',
input_shape=(48, 48,1)))
model.add(Activation('relu'))
model.add(Convolution2D(32, 3,3))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(256))
model.add(Activation('relu'))
model.add(Dropout(0.25))
model.add(Dense(7))
model.add(Activation('softmax'))
gen = ImageDataGenerator()
gen.fit(X_train)
train_generator =gen.flow(X_train,Y_train,batch_size=32,shuffle=False)
test_generator = gen.flow(X_test, Y_test, batch_size=32,shuffle=False)
train = model.predict_generator(train_generator, 31000)
test= model.predict_generator(test_generator, 3589)
with h5py.File("model_common.h5") as h:
h.create_dataset("train", data=train)
h.create_dataset("test", data=test)
h.create_dataset("label", data=y_train)#sava mode ,there should hava a problem
for filename in ["model_common.h5","model_common.h5"]:
with h5py.File(filename, 'r') as h:
X_train.append(np.array(h['train']))
X_test.append(np.array(h['test']))
y_train = np.array(h['label'])
X_train = np.concatenate(X_train, axis=1)
X_test = np.concatenate(X_test, axis=1)
X_train, y_train = shuffle(X_train, y_train)
input_tensor = Input(X_train.shape[1:])
x = input_tensor
x = Dropout(0.5)(x)
x = Dense(1, activation='relu')(x)
model = Model(input_tensor, x)
model.fit(X_train,y_train, batch_size=32, nb_epoch=1, validation_split=0.2)
如果您希望人們提供幫助,您應該包含您的代碼,而不是它的圖片。 – ted