当前位置:网站首页>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通關(less6-less14)
- 【模型蒸馏】TinyBERT: Distilling BERT for Natural Language Understanding
- Build FRP for intranet penetration
- ORACLE EBS中消息队列fnd_msg_pub、fnd_message在PL/SQL中的应用
- Ceaspectuss shipping company shipping artificial intelligence products, anytime, anywhere container inspection and reporting to achieve cloud yard, shipping company intelligent digital container contr
- Two table Association of pyspark in idea2020 (field names are the same)
- Sqli Labs clearance summary - page 2
- Explain in detail the process of realizing Chinese text classification by CNN
- 【论文介绍】R-Drop: Regularized Dropout for Neural Networks
- Alpha Beta Pruning in Adversarial Search
猜你喜欢

sqli-labs通關匯總-page2

Sqli-labs customs clearance (less18-less20)

图解Kubernetes中的etcd的访问

腾讯机试题

ssm垃圾分类管理系统

Agile development of software development pattern (scrum)

IDEA2020中测试PySpark的运行出错

Pratique et réflexion sur l'entrepôt de données hors ligne et le développement Bi

Sqli Labs clearance summary - page 2

Build FRP for intranet penetration
随机推荐
Practice and thinking of offline data warehouse and Bi development
Error in running test pyspark in idea2020
SQLI-LABS通关(less2-less5)
Oracle rman自动恢复脚本(生产数据向测试迁移)
ssm人事管理系统
Oracle APEX 21.2 installation et déploiement en une seule touche
解决万恶的open failed: ENOENT (No such file or directory)/(Operation not permitted)
Data warehouse model fact table model design
oracle apex ajax process + dy 校验
使用Matlab实现:幂法、反幂法(原点位移)
CAD二次开发 对象
Sqli-labs customs clearance (less18-less20)
SQLI-LABS通关(less1)
Yaml file of ingress controller 0.47.0
2021-07-17c /cad secondary development creation circle (5)
Proteus -- RS-232 dual computer communication
Ingress Controller 0.47.0的Yaml文件
2021-07-05C#/CAD二次开发创建圆弧(4)
How to call WebService in PHP development environment?
php中的数字金额转换大写数字