ai平台:使用估计器运行TensorFlow 2.1培训作业时,输出中没有评估文件夹或导出文件夹
问题 我的代码在本地工作,但在升级到TensorFlow 2.1后提交在线培训作业时,我无法从TensorFlow估计器获得任何评估数据或导出。以下是我的大部分代码:ai平台:使用估计器运行TensorFlow 2.1培训作业时,输出中没有评估文件夹或导出文件夹,tensorflow,google-cloud-ml,Tensorflow,Google Cloud Ml,问题 我的代码在本地工作,但在升级到TensorFlow 2.1后提交在线培训作业时,我无法从TensorFlow估计器获得任何评估数据或导出。以下是我的大部分代码: def build_estimator(model_dir, config): return tf.estimator.LinearClassifier( feature_columns=feature_columns, n_classes=2, optimizer=tf.
def build_estimator(model_dir, config):
return tf.estimator.LinearClassifier(
feature_columns=feature_columns,
n_classes=2,
optimizer=tf.keras.optimizers.Ftrl(
learning_rate=args.learning_rate,
l1_regularization_strength=args.l1_strength
),
model_dir=model_dir,
config=config
)
run_config = tf.estimator.RunConfig(save_checkpoints_steps=100,
save_summary_steps=100)
...
estimator = build_estimator(model_dir=args.job_dir, config=run_config)
...
def serving_input_fn():
inputs = {
'feature1': tf.compat.v1.placeholder(shape=None, dtype=tf.string),
'feature2': tf.compat.v1.placeholder(shape=None, dtype=tf.string),
'feature3': tf.compat.v1.placeholder(shape=None, dtype=tf.string),
...
}
split_features = {}
for feature in inputs:
split_features[feature] = tf.strings.split(inputs[feature], "||").to_sparse()
return tf.estimator.export.ServingInputReceiver(features=split_features, receiver_tensors=inputs)
exporter_cls = tf.estimator.LatestExporter('predict', serving_input_fn)
eval_spec = tf.estimator.EvalSpec(
input_fn=lambda: input_eval_fn(args.test_dir),
exporters=[exporter_cls],
start_delay_secs=10,
throttle_secs=0)
tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)
如果我使用本地gcloud命令运行此命令,它工作正常,我将获得我的/eval
和/export
文件夹:
gcloud ai-platform local train \
--package-path trainer \
--module-name trainer.task \
-- \
--train-dir $TRAIN_DATA \
--test-dir $TEST_DATA \
--training-steps $TRAINING_STEPS \
--job-dir $OUTPUT
但是当我尝试在云中运行它时,我没有得到我的/eval
/export
文件夹。这仅在升级到2.1时才开始发生。以前在1.14中一切都很好
gcloud ai-platform jobs submit training $JOB_NAME \
--job-dir $OUTPUT_PATH \
--staging-bucket gs://$STAGING_BUCKET_NAME \
--runtime-version 2.1 \
--python-version 3.7 \
--package-path trainer/ \
--module-name trainer.task \
--region $REGION \
--config config.yaml \
-- \
--train-dir $TRAIN_DATA \
--test-dir $TEST_DATA \
我尝试过的
我没有依赖于EvalSpec
导出我的模型,而是尝试使用tf.estimator.export\u saved\u模型
。虽然这在本地和在线都有效,但如果可能的话,我想继续使用EvalSpec
和train\u和\u evaluate
,因为我可以通过不同的导出方法,如BestExporter
,LastExporter
,等等
我的主要问题是…
我是否错误地导出了TensorFlow 2.1中的模型,或者这是新版本平台上发生的错误 找到了答案… 基于有关
TF_CONFIG
环境变量的文档
master是TensorFlow中不推荐使用的任务类型。master代表了一个任务,该任务执行与主管类似的角色,但在某些配置中也充当评估者。TensorFlow 2不支持包含主任务的TF_配置环境变量
所以之前我们使用的是TF1.X,它使用了一个主工。但是,master在培训TF2.X作业时遭到了抨击。现在默认值为chief,但默认情况下chief不充当评估器。为了获得评估数据,我们需要更新配置yaml以显式分配评估器
我们使用evaluatorType
和evaluatorCount
更新了我们的config.yaml
trainingInput:
scaleTier: CUSTOM
masterType: standard_gpu
workerType: standard_gpu
workerCount: 1
evaluatorType: standard_gpu
evaluatorCount: 1
成功了 你能让最终搬运工工作吗?我们在转换到2.1以使FinalExporter正常工作时遇到问题(可以获得BestExporter和LastExporter)。