A
A
Alexey Belov2019-05-26 22:53:33
Python
Alexey Belov, 2019-05-26 22:53:33

How to convert Tensorflow 1 to Tensorflow 2?

Hello everyone, experts, in general, I decided to migrate to the second version, as I understand it, functions are used there, but as for me, the documentation in the style simply replace sessions with functions, not what you need to migrate completely (not using fragments from the first version).
Could you show how to migrate with the example below.

@worker_process_init.connect()
def init_worker(**kwargs):
    global sess, r
    with tf.io.gfile.GFile(MODEL_FILENAME, 'rb') as f:
        graph_def = tf.compat.v1.GraphDef()
        graph_def.ParseFromString(f.read())
        tf.import_graph_def(graph_def)
        
    gpu_options = tf.compat.v1.GPUOptions(per_process_gpu_memory_fraction=0.2, allow_growth=True)
    sess = tf.compat.v1.Session(config=tf.compat.v1.ConfigProto(gpu_options=gpu_options))

@app.task()
def create_mask(path):
    img_rgba = sess.run(
        sess.graph.get_tensor_by_name('import/outputs/hair:0'),
        feed_dict={'import/inputs/images:0': [image]})

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question