我正在googleai平台上使用带有TensorFlow 1.13的tf.estimator
API来构建DNN二进制分类器。由于某些原因,我没有得到eval
图,但是我得到了training
图。在
这里有两种不同的训练方法。第一种是普通python方法,第二种是在本地模式下使用gcpai平台。在
请注意,在这两种方法中,求值只是一个点,表示最终结果。我期待着一个类似于训练的曲线。在
最后,我展示了性能度量的相关模型代码。在
普通python笔记本方法:
%%bash
#echo ${PYTHONPATH}:${PWD}/${MODEL_NAME}
export PYTHONPATH=${PYTHONPATH}:${PWD}/${MODEL_NAME}
python -m trainer.task \
--train_data_paths="${PWD}/samples/train_sounds*" \
--eval_data_paths=${PWD}/samples/valid_sounds.csv \
--output_dir=${PWD}/${TRAINING_DIR} \
--hidden_units="175" \
--train_steps=5000 --job-dir=./tmp
本地gcloud(GCP)ai平台方法:
^{pr2}$性能指标代码
estimator = tf.contrib.estimator.add_metrics(estimator, my_auc)
以及
# This is from the tensorflow website for adding metrics for a DNNClassifier
# https://www.tensorflow.org/api_docs/python/tf/metrics/auc
def my_auc(features, labels, predictions):
return {
#'auc': tf.metrics.auc( labels, predictions['logistic'], weights=features['weight'])
#'auc': tf.metrics.auc( labels, predictions['logistic'], weights=features[LABEL])
# 'auc': tf.metrics.auc( labels, predictions['logistic'])
'auc': tf.metrics.auc( labels, predictions['class_ids']),
'accuracy': tf.metrics.accuracy( labels, predictions['class_ids'])
}
培训和评估过程中使用的方法
eval_spec = tf.estimator.EvalSpec(
input_fn = read_dataset(
filename = args['eval_data_paths'],
mode = tf.estimator.ModeKeys.EVAL,
batch_size = args['eval_batch_size']),
steps=100,
throttle_secs=10,
exporters = exporter)
# addition of throttle_secs=10 above and this
# below as a result of one of the suggested answers.
# The result is that these mods do no print the final
# evaluation graph much less the intermediate results
tf.estimator.RunConfig(save_checkpoints_steps=10)
tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)
使用tf.估计器
estimator = tf.estimator.DNNClassifier(
model_dir = model_dir,
feature_columns = final_columns,
hidden_units=hidden_units,
n_classes=2)
model_trained/eval dir.文件的屏幕截图。
此目录中只有这一个文件。 它被命名为model_trained/eval/events.out.tfevents事件.1561296248。我的主机名.local看起来像
在
estimator.train_and_evaluate()
中指定train_spec
和eval_spec
。eval_spec
通常有不同的输入函数(例如,开发评估数据集,非无序)每隔N步,来自train进程的一个检查点被保存,eval进程加载这些相同的权重并根据
eval_spec
运行。这些评估总结记录在检查点的步骤号下,因此您可以比较列车和测试性能。在在您的例子中,evaluation只在图上为每个要求值的调用生成一个点。此点包含整个求值调用的平均值。 看看this类似的问题:
我将使用
throttle_secs
小值(默认值为600)和tf.estimator.RunConfig
中的save_checkpoints_steps
修改为一个小值:tf.estimator.RunConfig(save_checkpoints_steps=SOME_SMALL_VALUE_TO_VERIFY)
随着评论和建议以及参数的调整,以下是对我有用的结果。在
启动张力板、训练模型等的代码。使用-表示笔记本单元
^{pr2}$
相关型号代码
结果图
相关问题 更多 >
编程相关推荐