无法使用对象检测API开始训练Mask RCNN检测模型

时间:2020-05-02 00:37:00

标签: tensorflow object-detection-api

我正在尝试使用对象检测API来设置mask rcnn对象检测培训。但是,我收到以下错误消息:

INFO:tensorflow:Error reported to Coordinator: 3 root error(s) found.  (0) Invalid argument: assertion failed: [] [Condition x == y did not hold element-wise:] [x (clone_1/Loss/BoxClassifierLoss/assert_equal_2/x:0) = ] [582] [y (clone_1/Loss/BoxClassifierLoss/assert_equal_2/y:0) = ] [11]
         [[node clone_1/Loss/BoxClassifierLoss/assert_equal_2/Assert/Assert (defined at /git/models/research/object_detection/utils/shape_utils.py:323) ]]
         [[clone_3/GridAnchorGenerator/assert_equal/Assert/Assert/data_4/_13]]  (1) Cancelled: Dequeue operation was cancelled
         [[node clone_3/prefetch_queue_Dequeue (defined at /git/models/research/object_detection/core/batcher.py:116) ]]   (2) Invalid argument: assertion failed: [] [Condition x == y did not hold element-wise:] [x (clone_1/Loss/BoxClassifierLoss/assert_equal_2/x:0)
= ] [582] [y (clone_1/Loss/BoxClassifierLoss/assert_equal_2/y:0) = ] [11]
         [[node clone_1/Loss/BoxClassifierLoss/assert_equal_2/Assert/Assert (defined at /git/models/research/object_detection/utils/shape_utils.py:323) ]] 0 successful operations. 2 derived errors ignored.

我通过编写如下实例创建了tfrecord。

with tf.gfile.GFile(os.path.join(path, '{}'.format(group.filename)), 'rb') as fid:
    encoded_jpg = fid.read()
encoded_jpg_io = io.BytesIO(encoded_jpg)
image = Image.open(encoded_jpg_io)
width, height = image.size

filename = group.filename.encode('utf8')
image_format = b'jpg'
xmins = []
xmaxs = []
ymins = []
ymaxs = []
classes_text = []
classes = []
mask = []

for index, row in group.object.iterrows():
    if not class_text_to_int(row['class']):
        continue
    xmins.append(row['xmin'] / width)
    xmaxs.append(row['xmax'] / width)
    ymins.append(row['ymin'] / height)
    ymaxs.append(row['ymax'] / height)
    classes_text.append(row['class'].encode('utf8'))
    classes.append(class_text_to_int(row['class']))
    mask_path = os.path.join(FLAGS.image_dir, "png_masks", "{}_{}_{}.png".format(os.path.splitext(row['filename'])[0], row['class'], index))

    with tf.gfile.GFile(mask_path, 'rb') as fid:
        encoded_mask_png = fid.read()
    encoded_png_io = io.BytesIO(encoded_mask_png)
    mask.append(encoded_png_io.getvalue())

tf_example = tf.train.Example(features=tf.train.Features(feature={
    'image/height': dataset_util.int64_feature(height),
    'image/width': dataset_util.int64_feature(width),
    'image/filename': dataset_util.bytes_feature(filename),
    'image/source_id': dataset_util.bytes_feature(filename),
    'image/encoded': dataset_util.bytes_feature(encoded_jpg),
    'image/format': dataset_util.bytes_feature(image_format),
    'image/object/bbox/xmin': dataset_util.float_list_feature(xmins),
    'image/object/bbox/xmax': dataset_util.float_list_feature(xmaxs),
    'image/object/bbox/ymin': dataset_util.float_list_feature(ymins),
    'image/object/bbox/ymax': dataset_util.float_list_feature(ymaxs),
    'image/object/mask': dataset_util.bytes_list_feature(mask),
    'image/object/class/text': dataset_util.bytes_list_feature(classes_text),
    'image/object/class/label': dataset_util.int64_list_feature(classes),
}))
return tf_example

我还通过用PIL打开mask_path来检查我的mask_path,并且可以正常显示该遮罩。我可以知道如何解决这个问题吗?

0 个答案:

没有答案