OliveSensorAPI/scripts/gen_metafile.py

20 lines
528 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import sys
import ruamel.yaml
yaml = ruamel.yaml.YAML()
yaml.preserve_quotes = True
yaml.default_flow_style = False
file_path = 'metafile.yml'
# 读取YAML文件内容
with open(file_path, 'r') as file:
data = yaml.load(file)
# 遍历模型列表
for model in data.get('Models', []):
# 为每个模型添加Weights键值对确保名称被正确引用
model['Weights'] = model['Name']
# 将修改后的数据写回文件
with open(file_path, 'w') as file:
yaml.dump(data, file)
print("Modifications saved to the file.")