def Inception_extract_features_model(): # Build conv and pooling layers according to inception model = Inception(include_top=False, weights=None, input_shape=(240, 320, 3)) model.load_weights(inception_model_path) Inception_inputs = Input(shape=(240, 320, 3)) Inception_outputs = model(Inception_inputs) model = Model(Inception_inputs, GlobalAveragePooling2D()(Inception_outputs)) return model
InceptionV3.add(Dense(128, activation = "relu")) InceptionV3.add(Dense(37, activation = "softmax")) InceptionV3.summary() from keras.callbacks import ModelCheckpoint InceptionV3.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy']) checkpointer = ModelCheckpoint(filepath='weights.best.InceptionV3.hdf5', verbose=1, save_best_only=True, monitor='val_acc') InceptionV3.fit(features_train, target_train, validation_data=(features_valid, target_valid), epochs=50, batch_size=10, callbacks=[checkpointer], verbose=1) InceptionV3.load_weights('weights.best.InceptionV3.hdf5') plant_predictions = [np.argmax(InceptionV3.predict(np.expand_dims(tensor, axis=0))) for tensor in features_test] # report test accuracy test_accuracy = 100*np.sum(np.array(plant_predictions)==np.argmax(target_test, axis=1))/len(plant_predictions) print('Test accuracy: %.4f%%' % test_accuracy) from keras.layers import Conv2D, MaxPooling2D, GlobalAveragePooling2D from keras.layers import Dropout, Flatten, Dense from keras.models import Sequential model = Sequential() model.add(Conv2D(filters = 16, kernel_size = 2, padding = "same", activation = "relu", input_shape = (64,64,3))) model.add(MaxPooling2D(pool_size = 2))