0

I am using MaskR-CNN to do object segmentation in 2d-pictures. I use previously written code from someone else. My problem is, that I got problems with many false positives. Now I'd like to check the validation results after each epoch and check for false positives to optimize on that. Maybe not just on that but mixed with F1 score.

The code I use just calls the maskrcnn train method like that:

model.train(dataset_train, dataset_val,
                learning_rate=config.LEARNING_RATE,
                epochs=epochs,
                layers='heads')

My Config looks like this:

class MaskConfig(Config):
    NAME = "myName"
    IMAGES_PER_GPU = 1
    NUM_CLASSES = len(current_labels) + 1
    STEPS_PER_EPOCH = 100
    IMAGE_RESIZE_MODE = "square"
    IMAGE_MIN_DIM = 480
    IMAGE_MAX_DIM = 640
    DETECTION_MIN_CONFIDENCE = 0.8
    BACKBONE = "resnet101"
    LEARNING_RATE = learnrate
    LOSS_WEIGHTS = {
        "rpn_class_loss": 1.,
        "rpn_bbox_loss": 10.,
        "mrcnn_class_loss": 1.,
        "mrcnn_bbox_loss": 10.,
        "mrcnn_mask_loss": 10.
    }
    
config = MaskConfig()

I don't know where I can interfere with what is done after every epoch. I checked the 'train'-Method of the maskrcnn but couldn't really figure out how to do that. Is there any example somewhere on how to be able to manipulate on how the model is optimized and how to do early stopping?

Thank you so much for your help.

progNewbie
  • 4,362
  • 9
  • 48
  • 107

1 Answers1

1

In your model.train() you should need to use a custom callback in order to solve this problem.

For example:

model.train(train_set,
            test_set,
            learning_rate=config.LEARNING_RATE,
            custom_callbacks = [my_callback],
            epochs=5,
            layers='heads')

Now, the question comes, how do I implement my own callback?

Two resources:

  1. https://www.tensorflow.org/guide/keras/custom_callback
  2. Written by me, here: How to get other metrics in Tensorflow 2.0 (not only accuracy)?

At the same time, please pay attention to the version of Keras and TensorFlow.

To my knowledge, some of the versions in Mask-RCNN are dated. If there are more problems w.r.t errors in the code, I offer to help.

Timbus Calin
  • 13,809
  • 5
  • 41
  • 59