當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
labelme2coco问题:TypeError: Object of type 'int64' is not JSON serializable
生活随笔
收集整理的這篇文章主要介紹了
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?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
?
轉載于:https://www.cnblogs.com/BambooEatPanda/p/10444332.html
總結
以上是生活随笔為你收集整理的labelme2coco问题:TypeError: Object of type 'int64' is not JSON serializable的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NLP学习一 形式语言与自动机
- 下一篇: Spring实战Day2