gpt4 book ai didi

python - 如何动态编辑外部 .config 文件?

转载 作者:行者123 更新时间:2023-11-30 09:03:27 28 4
gpt4 key购买 nike

我正在使用 tensorflow 对象检测 API 开发主动机器学习管道。我的目标是动态更改网络 .config 文件中的路径。

标准配置如下:

    train_input_reader: {
tf_record_input_reader {
input_path: "/PATH_TO_CONFIGURE/train.record"
}
label_map_path: "/PATH_TO_CONFIGURE/label_map.pbtxt"
}

“PATH_TO_CONFIGURE”应该从我的 jupyter 笔记本单元中动态替换。

最佳答案

对象检测 API 配置文件采用 protobuf 格式。以下是阅读、编辑和保存它们的大致方法。

import tensorflow as tf
from google.protobuf import text_format
from object_detection.protos import pipeline_pb2

pipeline = pipeline_pb2.TrainEvalPipelineConfig()

with tf.gfile.GFile('config path', "r") as f:
proto_str = f.read()
text_format.Merge(proto_str, pipeline)

pipeline.train_input_reader.tf_record_input_reader.input_path[:] = ['your new entry'] # it's a repeated field
pipeline.train_input_reader.label_map_path = 'your new entry'

config_text = text_format.MessageToString(pipeline)
with tf.gfile.Open('config path', "wb") as f:
f.write(config_text)

您必须调整代码,但总体原理应该很清楚。我建议将其重构为函数并调用 Jupyter。

关于python - 如何动态编辑外部 .config 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58958905/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com