哔哩哔哩推广网站,discuz论坛seo设置,经验推广,泸州中泸建设集团有限公司网站最近在做MaskRCNN 在自己的数据#xff08;labelme#xff09;转为COCOjson格式遇到问题#xff1a;TypeError: Object of type int64 is not JSON serializable 原因是numpy的数据类型不能被json兼容 最简单的做法是自己写一个序列类 class MyEncoder(json.JSONEncoder):de… 最近在做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 intisnt serializable, but really, its telling you that this particular np.int32 (or whatever type you actually have) isnt serializable. The easiest workaround here is probably to write your own serializer 转载于:https://www.cnblogs.com/BambooEatPanda/p/10444332.html