Create a classifier from VGG16


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)
                      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")
, 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

… and my label 1:

My goal is to detect images containing points.