最近在做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的更多相关文章

  1. TypeError: Object of type 'int64' is not JSON serializable

    错误类型:TypeError: Object of type 'int64' is not JSON serializable 错误场景:对Numpy和Pandas结果进行json.dumps报错 错 ...

  2. TypeError: Object of type 'int32' is not JSON serializable ——已解决

    将模型用flask封装,返回json时报错:TypeError: Object of type 'int32' is not JSON serializable 网上搜索出的解决方案:重写json.J ...

  3. TypeError: Object of type 'int32' is not JSON serializable

    将模型用flask封装,返回json时报错:TypeError: Object of type 'int32' is not JSON serializable 网上搜索出的解决方案:重写json.J ...

  4. TypeError: Object of type 'ListSerializer' is not JSON serializable

    问题: 解决:ser.data是json数据,你想要的

  5. typeerror object of type ‘decimal‘ is not json serializable jsonify

    当使用flask的jsonify返回json数据时,由于数据库有些字段类型使用decimal,而jsonify无法处理 解决方案 导入下面的包即可解决 pip install simplejson

  6. TypeError: Object of type 'datetime' is not JSON serializable

    我的描述:我在flask框架中引用orm查数据库并返回数据,出现此类问题,如下图: 解决方案: 1.从表面意思看,就是说datetime时间类型无法被序列化.于是我百度了网上的同事的解答,大多说是时间 ...

  7. celery 4.1下报kombu.exceptions.EncodeError: Object of type 'bytes' is not JSON serializable 处理方式

    #python代码如下 from celery import Celeryimport subprocess app = Celery('tasks', broker='redis://localho ...

  8. Object of type 'ListSerializer' is not JSON serializable “listserializer”类型的对象不可JSON序列化

    Object of type 'ListSerializer' is not JSON serializable “listserializer”类型的对象不可JSON序列化 一般原因为 序列化的对象 ...

  9. Object of type 'ndarray' is not JSON serializable

    Object of type 'ndarray' is not JSON serializable import numpy as np import json arr=np.asarray([345 ...

随机推荐

  1. 关于Ubuntu中snap安装软件太慢解决办法

    两种方法,一是下载好包手动安装,二设置snap的代理. 下载安装包方式 到 https://uappexplorer.com/snaps 搜索需要的 snap 包,然后下载 下载的时候选择对应的平台. ...

  2. エンジニア死滅シタ世界之高層ビル [MISSION LEVEL: B]-Python3

    n = input() pre="" next_str = "" new_str = "" for i in range(int(n)): ...

  3. pyinstaller在64位系统下打包32位程序

    使用环境说明:win10 64位,已安装python3.6-64位版本 遇到的问题:win10 64位打包成exe文件后,不能在32位系统运行 需求:使用python打包生成exe文件,win64位和 ...

  4. Spark(五十二):Spark Scheduler模块之DAGScheduler流程

    导入 从一个Job运行过程中来看DAGScheduler是运行在Driver端的,其工作流程如下图: 图中涉及到的词汇概念: 1. RDD——Resillient Distributed Datase ...

  5. Python: 在CSV文件中写入中文字符

    0.2 2016.09.26 11:28* 字数 216 阅读 8053评论 2喜欢 5 最近一段时间的学习中发现,Python基本和中文字符杠上了.如果能把各种编码问题解决了,基本上也算对Pytho ...

  6. 深拷贝(deep clone)与浅拷贝(shallow clone)

    一.浅复制和深复制概念 浅复制(浅克隆): 被复制对象的所有变量都含有与原来对象相同的值,而所有的对其他对象的引用仍然指向原来的对象.换言之,浅复制仅仅复制所考虑的对象,而不是复制它所引用的对象. 深 ...

  7. Android studio: Android Studio 3.5格式化布局代码时错乱

    Android studio 又来搞事情了,更新到3.5版本后,格式化布局文件代码时,布局文件代码竟然会发生变化,意思是不让格式化代码了呗? 垃圾的IDE. 解决办法: “File”-"Se ...

  8. SpringCloud-Eureka配置instanceId显示IP

    eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/ instance: preferIpAddress: tr ...

  9. PHP 对象接口

    对象接口 (interface) 使用接口(interface),可以指定某个类必须实现哪些方法,但不需要定义这些方法的具体内容. 接口是通过 interface 关键字来定义的,就像定义一个标准的类 ...

  10. iptables 配置场景3

    iptables -I INPUT -i lo -j ACCEPT    #允许本地回环地址访问: iptables -I INPUT -m state --state ESTABLISHED,REL ...