2017-08-11 19 views
0

私はTensorflowで私のカスタム実験を構築しようとしていますが、export_strategy引数の使い方は分かりません。また、あなたはserving_input_fnをどのように構築しますか?実験での輸出戦略とは何ですか?

ありがとうございました!触発さ

答えて

0

回答CloudML example

質問1:export_strategy(source)を使用することは何ですか?

質問2の回答も参照してください。ただし、書き出し戦略は(名前が示すように)エクスポート時にグラフを変更する可能性があります。下の例では、モデルを提供するときに使用される適切な入力関数が追加されています。

learn_runner.run(
     generate_experiment_fn(
      min_eval_frequency=args.min_eval_frequency, 
      eval_delay_secs=args.eval_delay_secs, 
      train_steps=args.train_steps, 
      eval_steps=args.eval_steps, 
      export_strategies=[saved_model_export_utils.make_export_strategy(
       model.SERVING_FUNCTIONS[args.export_format], 
       exports_to_keep=1 
     )] 
    ), 
     run_config=tf.contrib.learn.RunConfig(model_dir=args.job_dir), 
     hparams=hparam.HParams(**args.__dict__) 
) 

質問2:どのようにあなたがserving_input_fn(source)を構築するのですか?

実際には、モデルを保存して準備するために、モデルに必要な入力(この場合はjson、csv、...)に基づいて、グラフの入力が必要になりますグラフへの入力の一部が欠落していれば、それを提供するときにグラフを供給することはできません。

def csv_serving_input_fn(): 
    """Build the serving inputs.""" 
    csv_row = tf.placeholder(
     shape=[None], 
     dtype=tf.string 
) 
    features = parse_csv(csv_row) 
    # Ignore label column 
    features.pop(LABEL_COLUMN) 
    return tf.estimator.export.ServingInputReceiver(
     features, {'csv_row': csv_row}) 
def example_serving_input_fn(): 
    """Build the serving inputs.""" 
    example_bytestring = tf.placeholder(
     shape=[None], 
     dtype=tf.string, 
) 
    features = tf.parse_example(
     example_bytestring, 
     tf.feature_column.make_parse_example_spec(INPUT_COLUMNS) 
) 
    return tf.estimator.export.ServingInputReceiver(
     features, {'example_proto': example_bytestring}) 


def json_serving_input_fn(): 
    """Build the serving inputs.""" 
    inputs = {} 
    for feat in INPUT_COLUMNS: 
    inputs[feat.name] = tf.placeholder(shape=[None], dtype=feat.dtype) 
    return tf.estimator.export.ServingInputReceiver(inputs, inputs) 


SERVING_FUNCTIONS = { 
    'JSON': json_serving_input_fn, 
    'EXAMPLE': example_serving_input_fn, 
    'CSV': csv_serving_input_fn 
} 

この質問にもお返事のためのExample of tensorflow.contrib.learn.ExportStrategy

+0

おかげに関連しています。 tf.estimator.EstimatorSpecには、export_outputs引数があります。あなたはそれがexport_stratとどのように関連しているか知っていますか?そして、単純に、モデルをエクスポートするための使用は何ですか? –

+0

GoogleクラウドML(ref https://cloud.google.com/ml-engine/docs/how-tos/getting-started-training-prediction)を使用している場合、最も明白な使用例があります。あなたがモデルを訓練する「訓練」仕事は、訓練されたモデルが保存され、後にモデルを「提供する」ために使用されます。 –

+0

ありがとう! 最後の質問ですが、なぜ次のserving_fnがなぜ使用されるのですか? = { "出力":tf.placeholder(DTYPE = tf.float32、形状= [1、なし])} _feature_specそしてserving_input_fn = tf.estimator.export.build_raw_serving_input_receiver_fn(feature_spec) learn.Experimentを(使用 ...引数... export_strategies = saved_model_export_utils.make_export_strategy(serving_input_fn = serving_input_fn) )_ –

関連する問題