答えて

1

心配する必要はありません。モデルを再トレーニングする必要はありません。それは、やるべきことが少しあります。新しい(訂正された)サービンググラフを作成し、そのグラフにチェックポイントをロードして、このグラフをエクスポートします。

たとえば、プレースホルダを追加しても、シェイプを設定していないとします(たとえ、CloudMLを実行することを意図していたとしても)。

# Create the *correct* graph 
with tf.Graph().as_default() as new_graph: 
    x = tf.placeholder(tf.float32, shape=[None]) 
    y = foo(x) 
    saver = tf.train.Saver() 

# (Re-)define the inputs and the outputs. 
inputs = {"x": tf.saved_model.utils.build_tensor_info(x)} 
outputs = {"y": tf.saved_model.utils.build_tensor_info(y)} 
signature = tf.saved_model.signature_def_utils.build_signature_def(
    inputs=inputs, 
    outputs=outputs, 
    method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME 
) 

with tf.Session(graph=new_graph) as session: 
    # Restore the variables 
    vars_path = os.path.join(old_export_dir, 'variables', 'variables') 
    saver.restore(session, vars_path) 

    # Save out the corrected model 
    b = builder.SavedModelBuilder(new_export_dir) 
    b.add_meta_graph_and_variables(session, ['serving_default'], signature) 
    b.save() 
:この問題を修正するには

x = tf.placeholder(tf.float32) 
y = foo(x) 
... 

:その場合は、あなたのグラフは次のように見えたかもしれません

関連する問題