matterport / Mask_RCNN

Mask R-CNN for object detection and instance segmentation on Keras and TensorFlow
Other
24.53k stars 11.68k forks source link

TypeError: Expected bytes, got str #1301

Open DaihuaWei opened 5 years ago

DaihuaWei commented 5 years ago

Traceback (most recent call last): File "./coco.py", line 498, in layers='heads') File "/data/g/weidaihua/Mask_RCNN-master/model.py", line 2207, in train validation_data=next(val_generator), File "/data/g/weidaihua/Mask_RCNN-master/model.py", line 1604, in data_generator use_mini_mask=config.USE_MINI_MASK) File "/data/g/weidaihua/Mask_RCNN-master/model.py", line 1163, in load_image_gt mask, class_ids = dataset.load_mask(image_id) File "./coco.py", line 249, in load_mask image_info["width"]) File "./coco.py", line 308, in annToMask rle = self.annToRLE(ann, height, width) File "./coco.py", line 294, in annToRLE rle = maskUtils.merge(rles) File "pycocotools/_mask.pyx", line 145, in pycocotools._mask.merge (pycocotools/_mask.c:3173) File "pycocotools/_mask.pyx", line 122, in pycocotools._mask._frString (pycocotools/_mask.c:2605) TypeError: Expected bytes, got str

who know the reason? thanks

kentaroy47 commented 5 years ago

got the same error as well. Pytorch 1.0 Python 3.6

... I actually got around with this by installing python 2.7 and Pytorch 1.0 (nightly). I think you have to change the versions. https://gist.github.com/kentaroy47/c91af88394da7fba594dd6393ec93893

w121211 commented 5 years ago

Encounter the same error. A workaround shows below.

Instead of the following code: (which cause TypeError: Expected bytes, got str)

from pycocotools.coco import COCO
import pycocotools.mask as mask_utils

coco = COCO("./your/data/annotation.json")
ann_ids = coco.getAnnIds(imgIds=1)
anns = coco.loadAnns(ann_ids)
segmentations = [obj["segmentation"] for obj in anns]
mask_utils.decode(anns)

Change to:

coco = COCO("./your/data/annotation.json")
ann_ids = coco.getAnnIds(imgIds=1)
anns = coco.loadAnns(ann_ids)
rleObjs = [mask_utils.frPyObjects(obj["segmentation"], obj["width"], obj["height"]) for obj in anns]
mask = mask_utils.decode(rleObjs)