'Error: module 'tensorflow._api.v2.train' has no attribute 'write_graph'

I used tensorflow 2.8 but I have a problem. My function

def export_model(saver, model, input_node_names, output_node_name,MODEL_NAME):
tf.train.write_graph(K.get_session().graph_def, 'out', \
                     MODEL_NAME + '_graph.pbtxt')
saver.save(K.get_session(), 'out/' + MODEL_NAME + '.chkp')
freeze_graph.freeze_graph('out/' + MODEL_NAME + '_graph.pbtxt', None, \
                          False, 'out/' + MODEL_NAME + '.chkp', output_node_name, \
                          "save/restore_all", "save/Const:0", \
                          'out/modelim' + MODEL_NAME + '.pb', True, "")
input_graph_def = tf.GraphDef()
with tf.gfile.Open('out/modelim' + MODEL_NAME + '.pb', "rb") as f:
    input_graph_def.ParseFromString(f.read())
output_graph_def = optimize_for_inference_lib.optimize_for_inference(
    input_graph_def, input_node_names, [output_node_name],
    tf.float32.as_datatype_enum)
with tf.gfile.FastGFile('out/opt_' + MODEL_NAME + '.pb', "wb") as f:
    f.write(output_graph_def.SerializeToString())
print("graph kaydedildi")
return

I try export

export_model(tf.compat.v1.train.Saver(), estimator, [inputName], outPutName,"test")

but ı have a problem module 'tensorflow._api.v2.train' has no attribute 'write_graph'



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source