当前位置:网站首页>allennlp 中的TypeError: Object of type Tensor is not JSON serializable错误
allennlp 中的TypeError: Object of type Tensor is not JSON serializable错误
2022-07-02 06:25:00 【lwgkzl】
错误展示:
File "/home/yanshangyao/anaconda3/envs/torch14/bin/allennlp", line 8, in <module>
sys.exit(run())
File "/home/yanshangyao/anaconda3/envs/torch14/lib/python3.7/site-packages/allennlp/run.py", line 18, in run
main(prog="allennlp")
File "/home/yanshangyao/anaconda3/envs/torch14/lib/python3.7/site-packages/allennlp/commands/__init__.py", line 102, in main
args.func(args)
File "/home/yanshangyao/anaconda3/envs/torch14/lib/python3.7/site-packages/allennlp/commands/train.py", line 124, in train_model_from_args
args.cache_prefix)
File "/home/yanshangyao/anaconda3/envs/torch14/lib/python3.7/site-packages/allennlp/commands/train.py", line 168, in train_model_from_file
cache_directory, cache_prefix)
File "/home/yanshangyao/anaconda3/envs/torch14/lib/python3.7/site-packages/allennlp/commands/train.py", line 252, in train_model
metrics = trainer.train()
File "/home/yanshangyao/anaconda3/envs/torch14/lib/python3.7/site-packages/allennlp/training/trainer.py", line 529, in train
dump_metrics(os.path.join(self._serialization_dir, f'metrics_epoch_{epoch}.json'), metrics)
File "/home/yanshangyao/anaconda3/envs/torch14/lib/python3.7/site-packages/allennlp/common/util.py", line 419, in dump_metrics
metrics_json = json.dumps(metrics, indent=2)
File "/home/yanshangyao/anaconda3/envs/torch14/lib/python3.7/json/__init__.py", line 238, in dumps
**kw).encode(obj)
File "/home/yanshangyao/anaconda3/envs/torch14/lib/python3.7/json/encoder.py", line 201, in encode
chunks = list(chunks)
File "/home/yanshangyao/anaconda3/envs/torch14/lib/python3.7/json/encoder.py", line 431, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File "/home/yanshangyao/anaconda3/envs/torch14/lib/python3.7/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/home/yanshangyao/anaconda3/envs/torch14/lib/python3.7/json/encoder.py", line 438, in _iterencode
o = _default(o)
File "/home/yanshangyao/anaconda3/envs/torch14/lib/python3.7/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Tensor is not JSON serializable
这个错误发生过很多次了,每次都忘记。首先看到报错中有设计到metric,我就一直以为是meric的格式不对,不符合json.dumps的标准,仔细看错误发现是 Object of type Tensor,其实就是说tensor格式的对象不能dumps,那么我们就需要在get_metirc的时候把塞到metric里面的值首先变为数值。
边栏推荐
猜你喜欢
腾讯机试题
Sqli labs customs clearance summary-page1
sqli-labs通关汇总-page2
TCP attack
sparksql数据倾斜那些事儿
ORACLE EBS ADI 开发步骤
IDEA2020中PySpark的两表关联(字段名相同)
【模型蒸馏】TinyBERT: Distilling BERT for Natural Language Understanding
UEditor . Net version arbitrary file upload vulnerability recurrence
Oracle 11g uses ords+pljson to implement JSON_ Table effect
随机推荐
JS countdown case
Alpha Beta Pruning in Adversarial Search
Sqli-labs customs clearance (less6-less14)
Ceaspectuss shipping company shipping artificial intelligence products, anytime, anywhere container inspection and reporting to achieve cloud yard, shipping company intelligent digital container contr
Agile development of software development pattern (scrum)
ORACLE 11G利用 ORDS+pljson来实现json_table 效果
Illustration of etcd access in kubernetes
Oracle 11g uses ords+pljson to implement JSON_ Table effect
Sqli-labs customs clearance (less15-less17)
php中的二维数组去重
DNS attack details
Oracle EBS interface development - quick generation of JSON format data
Sqli - Labs Clearance (less6 - less14)
如何高效开发一款微信小程序
SSM实验室设备管理
離線數倉和bi開發的實踐和思考
搭建frp进行内网穿透
2021-07-19c CAD secondary development creates multiple line segments
使用MAME32K进行联机游戏
CRP实施方法论