當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
labelme2coco问题:TypeError: Object of type 'int64' is not JSON serializable
生活随笔
收集整理的這篇文章主要介紹了
labelme2coco问题:TypeError: Object of type 'int64' is not JSON serializable
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
最近在做MaskRCNN
在自己的數(shù)據(jù)(labelme)轉(zhuǎn)為COCOjson格式遇到問題:TypeError: Object of type 'int64' is not JSON serializable
原因是numpy的數(shù)據(jù)類型不能被json兼容
最簡單的做法是自己寫一個(gè)序列類
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
?
轉(zhuǎn)載于:https://www.cnblogs.com/BambooEatPanda/p/10444332.html
總結(jié)
以上是生活随笔為你收集整理的labelme2coco问题:TypeError: Object of type 'int64' is not JSON serializable的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NLP学习一 形式语言与自动机
- 下一篇: Linux学习笔记——网络组成