tensorflow 掩模RCNN预测不良

rqenqsqc  于 2023-03-09  发布在  其他
关注(0)|答案(1)|浏览(98)

我正在使用Matterport MRCNN存储库的一个版本对2个对象进行分类(比如说狗和猫)使用~5k图像进行训练(1024X1024)使用mask_rcnn_coco.h5权重进行迁移学习。我想知道我是否做错了什么,需要更改配置参数,调整我的图像数据集,或者这些努力的某种组合。在我训练模型并加载权重后,当我试图对测试集图像进行预测时,对于我尝试的每个测试集图像,边界框将位于图像的顶部边缘上的某个地方,其框坐标类似于[ 0 1801 1 1803],这暗示了较差的预测。
我已经对此进行了广泛的研究,但我找不到一个问题和解决方案,符合我的情况,虽然我想也许我需要尝试一种不同的方法来加载COCO权重或添加更多的无对象图像到训练/验证集。我发现一些关于MRCNN实现的论文使用的训练/验证图像比我在不包括无对象图像的情况下使用的图像更少,并且能够毫无问题地进行预测。有人有什么建议吗?谢谢。
Random predictions during inference for the same image
Predictions for Mask RCNN are not working correctly
下面是我目前拥有的相关代码(tensorflow == 2.10.0):

# define a configuration for the model
class PetConfig(Config):
    # define the name of the configuration
    NAME = "pet_cfg"
    # number of classes (background + 2 detected classes (Cat + Dog))
    NUM_CLASSES = 1 + 2
    # number of training steps per epoch
    STEPS_PER_EPOCH = 100
    IMAGES_PER_GPU = 1
    MAX_GT_INSTANCES = 3
    DETECTION_MAX_INSTANCES = 3
    DETECTION_MIN_CONFIDENCE = 0.95
    BACKBONE = "resnet50"
    TRAIN_ROIS_PER_IMAGE = 10
    VALIDATION_STEPS = 200

配置摘要:
x一个一个一个一个x一个一个二个x
训练后保存和推断:

model.keras_model.save_weights('weights/pet_mask_rcnn.h5')

from matplotlib.patches import Rectangle

# define the prediction configuration
class PredictionConfig(Config):
    # define the name of the configuration
    NAME = "pet_cfg"
    # number of classes (background + 2 detected classes (dog + cat))
    NUM_CLASSES = 1 + 2
    # simplify GPU config
    GPU_COUNT = 1
    IMAGES_PER_GPU = 1
    MAX_GT_INSTANCES = 1
    DETECTION_MAX_INSTANCES = 1
    
predcfg = PredictionConfig()

# Load model in inference mode
K.clear_session()                   # disallocate GPU memory
inf_mod = MaskRCNN(mode="inference", model_dir='weights/', config=predcfg)
inf_mod.load_weights('weights/pet_mask_rcnn.h5', by_name=True)

#Test on a single image
num=random.randint(0, len(test_set.image_ids))
# define image id
image_id = num
# load the image
test_img = test_set.load_image(image_id)

detected = inf_mod.detect([test_img])[0]
pyplot.imshow(test_img)
ax = pyplot.gca()
class_names = ['dog', 'cat']
class_id_counter=1
for box in detected['rois']:
    print(box)
#get coordinates
    detected_class_id = detected['class_ids'][class_id_counter-1]
    #print(detected_class_id)
    #print("Detected class is :", class_names[detected_class_id-1])
    y1, x1, y2, x2 = box
    #calculate width and height of the box
    width, height = x2 - x1, y2 - y1
    #create the shape
    ax.annotate(class_names[detected_class_id-1], (x1, y1), color='black', weight='bold', fontsize=10, ha='center', va='center')
    rect = Rectangle((x1, y1), width, height, fill=False, color='red')
#draw the box
    ax.add_patch(rect)
    class_id_counter+=1
#show the figure
pyplot.show()
zbdgwd5y

zbdgwd5y1#

做更多的研究,我遇到了这个职位,这是相当类似的假阳性与面具RCNN。
what-are-the-best-methods-for-reducing-false-positives-in-tensorflow-mask-rcnn...
根据Stigma的回答,我认为我需要从头开始训练,并添加更多的非物体图像进行训练。

相关问题