'Why my Mask Rcnn predict everything for one class

everyone I run my test codes of Mask Rcnn, it only predcit everything is "cat", however, I have two classes cat and dog except background. I use VIA to annotate the mask images. I only annotate 70 images totally. I am not sure the problem is from my codes or insufficient annotated images. The test codes are shown below.

    import os
import mrcnn.visualize
import cv2
import time
from mrcnn.config import Config
from datetime import datetime
# Root directory of the project
ROOT_DIR = os.getcwd()
# Root directory of the project


# Directory to save logs and trained model
MODEL_DIR = os.path.join(ROOT_DIR, "logs")

# Local path to trained weights file
COCO_MODEL_PATH = os.path.join(ROOT_DIR, "mask_rcnn_balloon_0030.h5")
# Download COCO trained weights from Releases if needed
# Directory of images to run detection on
IMAGE_DIR = os.path.join(ROOT_DIR, "images2")



class_names = ['BG', 'cat', 'dog']
class SimpleConfig(mrcnn.config.Config):
    NAME = "coco_inference"
    GPU_COUNT = 1
    IMAGES_PER_GPU = 1
    NUM_CLASSES = len(class_names)

import mrcnn.model

# Create model object in inference mode.
model = mrcnn.model.MaskRCNN(mode="inference", model_dir=ROOT_DIR, config=SimpleConfig())

model.load_weights(filepath=COCO_MODEL_PATH, by_name=True)

class_names = ['BG', 'cat', 'dog']
# Load a random image from the images folder
image = cv2.imread(r'C:\Users\Owner\Downloads\Mask_RCNN-2.1\images2\test3.jpg')
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

r = model.detect([image], verbose=1)

r = r[0]

mrcnn.visualize.display_instances(image=image,
                                  boxes=r['rois'],
                                  masks=r['masks'],
                                  class_ids=r['class_ids'],
                                  class_names=class_names,
                                  scores=r['scores'])

Thank you very much! Hope for help!

The wrong predcit image



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source