labelme2coco问题:TypeError: Object of type 'int64' is not JSON serializable
最近在做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
jsonis telling you that anintisn'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的更多相关文章
- TypeError: Object of type 'int64' is not JSON serializable
错误类型:TypeError: Object of type 'int64' is not JSON serializable 错误场景:对Numpy和Pandas结果进行json.dumps报错 错 ...
- TypeError: Object of type 'int32' is not JSON serializable ——已解决
将模型用flask封装,返回json时报错:TypeError: Object of type 'int32' is not JSON serializable 网上搜索出的解决方案:重写json.J ...
- TypeError: Object of type 'int32' is not JSON serializable
将模型用flask封装,返回json时报错:TypeError: Object of type 'int32' is not JSON serializable 网上搜索出的解决方案:重写json.J ...
- TypeError: Object of type 'ListSerializer' is not JSON serializable
问题: 解决:ser.data是json数据,你想要的
- typeerror object of type ‘decimal‘ is not json serializable jsonify
当使用flask的jsonify返回json数据时,由于数据库有些字段类型使用decimal,而jsonify无法处理 解决方案 导入下面的包即可解决 pip install simplejson
- TypeError: Object of type 'datetime' is not JSON serializable
我的描述:我在flask框架中引用orm查数据库并返回数据,出现此类问题,如下图: 解决方案: 1.从表面意思看,就是说datetime时间类型无法被序列化.于是我百度了网上的同事的解答,大多说是时间 ...
- 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 ...
- Object of type 'ListSerializer' is not JSON serializable “listserializer”类型的对象不可JSON序列化
Object of type 'ListSerializer' is not JSON serializable “listserializer”类型的对象不可JSON序列化 一般原因为 序列化的对象 ...
- 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 ...
随机推荐
- Three.js实现滚轮放大展现不同的模型
目录 Three.js实现滚轮放大展现不同的模型 修改OrbitControls.js的源码 OrbitControls在透视相机(PerspectiveCamera)的控制原理 具体实现 Three ...
- (2)Go基本数据类型
Go语言的基本类型有: bool string int.int8.int16.int32.int64 uint.uint8.uint16.uint32.uint64.uintptr byte // u ...
- 中山纪中集训Day2又是测试(划水)
A组T1 bzoj 2674 Attack Description chnlich 非常喜欢玩三国志这款游戏,并喜欢用一些策略出奇制胜.现在,他要开始征服世界的旅途了.他的敌人有N 座城市和N 个太守 ...
- border-radius后面写px/rem与百分比有什么区别?
首先百分比,表示的是设置50%表示的是圆是弧度,设置px/rem,是表示你想要变圆弧的半径是多少
- Pycharm中直接安装第三方库
1.点File->Settings 2.在project interpreter(项目解释器)中点击“+”号 3.输入第三方库进行查询,并安排 4.安装成功
- MFC GDI+显示GIF文件《转》
在头文件里面添加: Image* image; GUID Guid ; UINT frameCount; UINT framePos;ULONG_PTR gdiplusToken; afx_msg v ...
- 创建加载bean的实例
一.创建实例 工程的结构如下图 1.创建接口 public interface Person { public void setName(String name); public String say ...
- Java_jdbc 基础笔记之一 数据库连接
方式一: 1.创建一个Driver实现类的对象 2.准备连接数据库的基本信息:url,user,password 3.调用Driver接口的connect(url,info)获取数据库连接 * Dri ...
- 使用注解@Slf4j简化Logger的初始化
一.是不是厌倦了 private final static Logger logger = LoggerFactory.getLogger(Application.class); 的拷贝和修改? 二. ...
- composer Changed current directory to没反应
根据官方手册执行composer global require "laravel/installer" 显示Changed current directory to C:/User ...