当前位置:网站首页>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里面的值首先变为数值。
边栏推荐
- Oracle EBS ADI development steps
- Oracle general ledger balance table GL for foreign currency bookkeeping_ Balance change (Part 1)
- oracle-外币记账时总账余额表gl_balance变化(上)
- Alpha Beta Pruning in Adversarial Search
- Explanation of suffix of Oracle EBS standard table
- PM2 simple use and daemon
- 中年人的认知科普
- Changes in foreign currency bookkeeping and revaluation general ledger balance table (Part 2)
- php中树形结构转数组(拉平树结构,保留上下级排序)
- ORACLE APEX 21.2安装及一键部署
猜你喜欢
随机推荐
使用Matlab实现:Jacobi、Gauss-Seidel迭代
实现接口 Interface Iterable&lt;T&gt;
spark sql任务性能优化(基础)
view的绘制机制(三)
Build FRP for intranet penetration
Sqli-labs customs clearance (less6-less14)
TCP攻击
How to call WebService in PHP development environment?
Changes in foreign currency bookkeeping and revaluation general ledger balance table (Part 2)
CSRF attack
类加载器及双亲委派机制
php中获取汉字拼音大写首字母
SSM学生成绩信息管理系统
RMAN增量恢复示例(1)-不带未备份的归档日志
使用Matlab实现:弦截法、二分法、CG法,求零点、解方程
Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"
Analysis of MapReduce and yarn principles
Oracle rman自动恢复脚本(生产数据向测试迁移)
php中根据数字月份返回月份的英文缩写
The first quickapp demo









