Create a classifier from VGG16

Hello,

I try to create a classifier from two folders containing images from my two labels.


        vgg = vgg16.VGG16(weights='imagenet', include_top=False, input_shape=self.input_shape)

        for layer in vgg.layers:
            layer.trainable = True

        x = vgg.output
        x = GlobalAveragePooling2D()(x)
        x = Dense(1024, activation="relu")(x)
        x = Dense(1024, activation="relu")(x)
        x = Dense(1024, activation="relu")(x)
        x = Dense(2, activation="softmax")(x)

        model = Model(vgg.input, x)
        model.compile(loss="categorical_crossentropy",
                      optimizer=SGD(learning_rate=0.001, momentum=0.9), metrics=["accuracy"])

        image_generator = ImageDataGenerator(rescale=1. / 255, validation_split=0.2)
        train_datagen = image_generator.flow_from_directory(processed_folder_path, class_mode='categorical',
                                                            batch_size=8, subset="training")

        validation_datagen = image_generator.flow_from_directory(processed_folder_path, class_mode='categorical',
                                                                  batch_size=8, subset="training")


        model.fit(x=train_datagen, validation_data=validation_datagen, steps_per_epoch=10, epochs=8, batch_size=batch_size,
                       callbacks=VGGCustomCallback(model=self.model, validation_img_datagen=train_datagen))

I don’t know what I did wrong but the generate score always fit the first label ( prediction result are ~ [1 0]) for both label.

Here is example images from my label 0
image_0_0

… and my label 1:
image_0_2

My goal is to detect images containing points.

@Arnaud_Domes,

Welcome to the Tensorflow Forum!

Improve the training data by cropping the black part of the image and make sure there is no black part in the other labelled images.

Thank you!