1、自定义对象
class Evaluation:
def __init__(self, train_f1, train_iou, train_loss, valid_f1, valid_iou, valid_loss):
self.trainF1 = train_f1
self.trainIou = train_iou
self.trainLoss = train_loss
self.validF1 = valid_f1
self.validIou = valid_iou
self.validLoss = valid_loss
2、实例化
evaluation = Evaluation(train_f1_list, train_iou_list, train_loss_list, valid_f1_list, valid_iou_list,
valid_loss_list)
3、序列化
import json
evaluation_json = json.dumps(evaluation, ensure_ascii=False, default=lambda obj: obj.__dict__)
文章来源地址https://www.toymoban.com/news/detail-583381.html
文章来源:https://www.toymoban.com/news/detail-583381.html
到了这里,关于python 自定义对象序列化为json的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!