gpt4 book ai didi

tensorflow - 在 TensorFlow 对象检测 API 中检测纪元结束

转载 作者:行者123 更新时间:2023-12-03 16:48:14 26 4
gpt4 key购买 nike

如何在 TF 对象检测 API 中检测一个时期的结束(即完成对数据集的一次完整扫描)?这可能有助于在自定义检测模型中进行一些簿记或一些内部处理(即重置一些权重)

最佳答案

您可能想要实现 tf.estimator.SessionRunHook

为此,您需要在 tf.estimator.TrainSpec 编辑 model_lib.py通过添加 hook 参数,或创建您自己的训练文件并在将其传递给 tf.estimator.train_and_evaluate 之前覆盖 train_spec。

使用添加到 Tensorflow 对象检测 API 的 ProfilerHook 的示例:(对于 SessionRunHook 应该是类似的)

config = tf.estimator.RunConfig(model_dir=model_dir, save_checkpoints_steps=save_checkpoints_steps,
save_checkpoints_secs=save_checkpoints_secs, keep_checkpoint_max=keep_checkpoint_max,
log_step_count_steps=log_step_count_steps)

train_and_eval_dict = model_lib.create_estimator_and_inputs(
run_config=config,
hparams=model_hparams.create_hparams(hparams_overrides),
pipeline_config_path=pipeline_config_path,
config_override = cfg_override,
train_steps=num_train_steps,
sample_1_of_n_eval_examples=sample_1_of_n_eval_examples,
sample_1_of_n_eval_on_train_examples=sample_1_of_n_eval_on_train_examples,
save_final_config=save_final_config)

estimator = train_and_eval_dict['estimator']
train_input_fn = train_and_eval_dict['train_input_fn']
eval_input_fns = train_and_eval_dict['eval_input_fns']
eval_on_train_input_fn = train_and_eval_dict['eval_on_train_input_fn']
predict_input_fn = train_and_eval_dict['predict_input_fn']
train_steps = train_and_eval_dict['train_steps']

train_spec, eval_specs = model_lib.create_train_and_eval_specs(
train_input_fn,
eval_input_fns,
eval_on_train_input_fn,
predict_input_fn,
train_steps,
eval_on_train_data=False)

profile_hook = tf.train.ProfilerHook(save_steps=profiler_save_step, save_secs=None, output_dir=profiler_output_dir,
show_dataflow=True, show_memory=True)

train_spec = tf.estimator.TrainSpec(input_fn=train_input_fn
,max_steps=train_steps
,hooks=[profile_hook])

tf.estimator.train_and_evaluate(estimator, train_spec, eval_specs[0])

关于tensorflow - 在 TensorFlow 对象检测 API 中检测纪元结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52191735/

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