コード例 #1
0
    def build_xception(self):
        """
        Load pre-trained Xception from keras applications
        """
        # Input image to extract features from
        img = Input(shape=(self.img_rows, self.img_cols, 3))

        # Get the vgg network from Keras applications
        xception = Xception(weights="imagenet", include_top=False)

        # Output the first three pooling layers
        xception.outputs = [
            xception.layers[i].output for i in self.xception_layers
        ]

        # Create model and compile
        model = Model(inputs=img, outputs=xception(img))
        model.trainable = False
        model.compile(loss='mse', optimizer='adam')

        return model
コード例 #2
0
                            cooldown=0,
                            min_lr=0)
save_model = ModelCheckpoint('xception{epoch:02d}-{val_ctg_out_1_acc:.2f}.h5',
                             period=2)
if os.path.exists('dog_xception.h5'):
    model = load_model('dog_xception.h5')
else:
    # create the base pre-trained model
    input_tensor = Input(shape=(299, 299, 3))
    base_model = Xception(include_top=True,
                          weights='imagenet',
                          input_tensor=None,
                          input_shape=None)
    plot_model(base_model, to_file='xception_model.png')
    base_model.layers.pop()
    base_model.outputs = [base_model.layers[-1].output]
    base_model.layers[-1].outbound_nodes = []
    base_model.output_layers = [base_model.layers[-1]]

    feature = base_model
    img1 = Input(shape=(299, 299, 3), name='img_1')
    img2 = Input(shape=(299, 299, 3), name='img_2')

    feature1 = feature(img1)
    feature2 = feature(img2)
    # let's add a fully-connected layer
    category_predict1 = Dense(100, activation='softmax',
                              name='ctg_out_1')(Dropout(0.5)(feature1))
    category_predict2 = Dense(100, activation='softmax',
                              name='ctg_out_2')(Dropout(0.5)(feature2))