ValueError: Layer #391 (named "mrcnn_bbox_fc"), weight <tf.Variable 'mrcnn_bbox_fc_1/kernel:0' shape=(1024, 324) dtype=float32> has shape (1024, 324), but the saved weight has shape (1024, 24).
我已经在具有 5 个类的自定义数据集上训练了 MASK-RCNN 模型。当我在笔记本中对模型进行推理并使用 MASK-RCNN 加载模型权重时,modelib它工作正常。
model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config)
model.load_weights(weights_path, by_name=True)
但是当我使用此代码加载模型时,它会引发上述错误。
import pixellib
from pixellib.instance import instance_segmentation
import cv2
import os
def do_instance(img_path):
absolute_path = os.path.abspath("model/mask_rcnn_coco.h5")
segment_image = instance_segmentation(infer_speed="average")
segment_image.load_model(absolute_path)
# Perform instance segmentation
segmask, output = segment_image.segmentImage(img_path, show_bboxes=True)
return output