博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
labelme2coco问题:TypeError: Object of type 'int64' is not JSON serializable
阅读量:4568 次
发布时间:2019-06-08

本文共 775 字,大约阅读时间需要 2 分钟。

最近在做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 

 

转载于:https://www.cnblogs.com/BambooEatPanda/p/10444332.html

你可能感兴趣的文章
2011年5款备受关注的开源 NoSQL 数据库
查看>>
2-4-1 元组
查看>>
476. Number Complement(补数)
查看>>
生成函数
查看>>
HTMl5的存储方式sessionStorage和localStorage详解
查看>>
BZOJ 4516: [Sdoi2016]生成魔咒——后缀数组、并查集
查看>>
《JAVA程序设计》实训第一天——《猜猜看》游戏
查看>>
普通用户 crontab 任务不运行
查看>>
第三次冲刺(三)
查看>>
android实现静默安装demo
查看>>
数据缓存方案
查看>>
HDU 1086:You can Solve a Geometry Problem too
查看>>
HIPO图
查看>>
工作日志2014-06-30
查看>>
稀疏矩阵
查看>>
OpenCV2马拉松第14圈——边缘检測(Sobel,prewitt,roberts)
查看>>
移动端事件点透问题
查看>>
P1896 [SCOI2005]互不侵犯
查看>>
ESP定律手工脱壳步骤
查看>>
wex5 教程 之 图文讲解 登陆,注册,页面跳转
查看>>