首页 > Web开发 > 详细

labelme2coco问题:TypeError: Object of type 'int64' is not JSON serializable

时间:2019-02-27 16:19:16      阅读:1935      评论:0      收藏:0      [点我收藏+]

最近在做MaskRCNN

在自己的数据(labelme)转为COCOjson格式遇到问题:TypeError: Object of type ‘int64‘ is not JSON serializable

原因是numpy的数据类型不能被json兼容

最简单的做法是自己写一个序列类

class MyEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, numpy.integer):
            return int(obj)
        elif isinstance(obj, numpy.floating):
            return float(obj)
        elif isinstance(obj, numpy.ndarray):
            return obj.tolist()
        else:
            return super(MyEncoder, self).default(obj)

  

it looks like json is telling you that an intisn‘t serializable, but really, it‘s telling you that this particular np.int32 (or whatever type you actually have) isn‘t serializable.

The easiest workaround here is probably to write your own serializer

 

labelme2coco问题:TypeError: Object of type 'int64' is not JSON serializable

原文:https://www.cnblogs.com/BambooEatPanda/p/10444332.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!