Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I have trained a .pb model which is in tf1.2 and I want to use it in the environment of tf2.0, but I fail to use it successfully. Anyone knows how to solve the problem? #7508

Closed
Govan111 opened this issue Aug 29, 2019 · 1 comment

Comments

@Govan111
Copy link

from future import division
from future import print_function

try:
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
except (ImportError, AttributeError):
import tensorflow as tf

import tensorflow as tf
import numpy as np
import os

with tf.Graph().as_default():

output_graph_def = tf.GraphDef()

with open('./myModel.pb', "rb") as f:
    output_graph_def.ParseFromString(f.read())
    tf.import_graph_def(output_graph_def, name="")

gpu_options = tf.GPUOptions(
    per_process_gpu_memory_fraction=self.gpu_memory_fraction,
    visible_device_list=self.visible_device_list,
    allow_growth=self.allow_growth)
tfconfig = tf.ConfigProto(gpu_options=gpu_options, allow_soft_placement=False)
tfconfig.gpu_options.allow_growth = True

with tf.Session(config=tfconfig) as sess:
    sess.run(tf.global_variables_initializer())
    input_photo = sess.graph.get_tensor_by_name('placeholder/photo:0')
    output_photo = sess.graph.get_tensor_by_name('decoder/Sigmoid:0')

################################## erros are as follows:
Traceback (most recent call last):
File "/Users/govan/Project/test.py", line 31, in call
output_graph_def = tf.GraphDef()
AttributeError: module 'tensorflow' has no attribute 'GraphDef'

@saberkun
Copy link
Member

tf.GraphDef() is not available in tf 2.0. In tf 2.0, graph/session concept has changed. Please try to use savedmodel api and do not use session, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants