当前位置:网站首页>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里面的值首先变为数值。
边栏推荐
- User login function: simple but difficult
- 华为机试题
- ARP attack
- CAD secondary development object
- Analysis of MapReduce and yarn principles
- ERNIE1.0 与 ERNIE2.0 论文解读
- Network security -- intrusion detection of emergency response
- SSM二手交易网站
- Error in running test pyspark in idea2020
- Oracle EBS数据库监控-Zabbix+zabbix-agent2+orabbix
猜你喜欢

IDEA2020中PySpark的两表关联(字段名相同)

Ingress Controller 0.47.0的Yaml文件

在php的开发环境中如何调取WebService?

ORACLE 11G利用 ORDS+pljson来实现json_table 效果

Explain in detail the process of realizing Chinese text classification by CNN

Message queue fnd in Oracle EBS_ msg_ pub、fnd_ Application of message in pl/sql

叮咚,Redis OM对象映射框架来了

读《敏捷整洁之道:回归本源》后感

Oracle apex Ajax process + dy verification

IDEA2020中测试PySpark的运行出错
随机推荐
2021-07-17C#/CAD二次开发创建圆(5)
使用 Compose 实现可见 ScrollBar
Practice and thinking of offline data warehouse and Bi development
Oracle RMAN semi automatic recovery script restore phase
使用Matlab实现:弦截法、二分法、CG法,求零点、解方程
CRP实施方法论
MapReduce concepts and cases (Shang Silicon Valley Learning Notes)
Oracle rman半自动恢复脚本-restore阶段
Sqli labs customs clearance summary-page4
Analysis of MapReduce and yarn principles
oracle EBS标准表的后缀解释说明
Oracle EBS DataGuard setup
ORACLE EBS DATAGUARD 搭建
IDEA2020中测试PySpark的运行出错
Ceaspectuss shipping company shipping artificial intelligence products, anytime, anywhere container inspection and reporting to achieve cloud yard, shipping company intelligent digital container contr
实现接口 Interface Iterable&lt;T&gt;
JSP智能小区物业管理系统
sqli-labs通关汇总-page1
Error in running test pyspark in idea2020
php中树形结构转数组(拉平树结构,保留上下级排序)