rishizek / tensorflow-deeplab-v3-plus

DeepLabv3+ built in TensorFlow
MIT License
833 stars 307 forks source link

about using the export_inference_graph #51

Open whisperccc opened 5 years ago

whisperccc commented 5 years ago

Maybe it's not a issue and i am sorry to ask here. After training the model(not pretrained model) with 11 classes ,I got the output in ./model (checkpoint file 、model.ckpt-27534(data、meta、index and etc.). Then i use the export_inference_graph.py and got an output in ./dataset/export_output/1558618490/ (saved_model.pb 、 variables.index and variables.data-00000-of-00001) But the problem was that when i tried to use the saved_model.pb 、 variables.index and variables.data-00000-of-00001 in other project i got an error like this:

MODEL = load_model() File "/home/ubuntu/MyFiles/tensorflow/port/portrait-test/utils.py", line 38, in load_model MODEL = DeepLabModel(model_path) File "/home/ubuntu/MyFiles/tensorflow/port/portrait-test/deeplabmodel.py", line 25, in init graph_def = tf.GraphDef.FromString(file_handle.read()) google.protobuf.message.DecodeError: Error parsing message

the method i used to load the graft is from official tensorflow deeplab model and it worked but when I use your model.pb it got an error , is there any differernce? and how to sovled this problem? I would appreciate it if you could reply soon.

INPUT_TENSOR_NAME = 'ImageTensor:0' OUTPUT_TENSOR_NAME = 'SemanticPredictions:0' INPUT_SIZE = 513 FROZEN_GRAPH_NAME = 'frozen_inference_graph'

def __init__(self, tarball_path):
    """Creates and loads pretrained deeplab model."""
    self.graph = tf.Graph()

    graph_def = None
    # Extract frozen graph from tar archive.
    tar_file = tarfile.open(tarball_path)
    for tar_info in tar_file.getmembers():
        if self.FROZEN_GRAPH_NAME in os.path.basename(tar_info.name):
            file_handle = tar_file.extractfile(tar_info)
            graph_def = tf.GraphDef.FromString(file_handle.read())
            break

    tar_file.close()

    if graph_def is None:
        raise RuntimeError('Cannot find inference graph in tar archive.')

    with self.graph.as_default():
        tf.import_graph_def(graph_def, name='')

    self.sess = tf.Session(graph=self.graph)
MIKOCHAO3512 commented 4 years ago

I have the save questions with you, have you settled this one?

Longlingfeng1 commented 4 years ago

I have the save questions with you, have you settled this one?

shakey-cuimiao commented 4 years ago

@Have you solved the problem? I had the same problem,I am already downloading demo.py from from official tensorflow deeplab model,but I get erros:graph_def = tf.GraphDef.FromString(file_handle.read()) google.protobuf.message.DecodeError: Error parsing messag

gouri1694 commented 3 years ago

I had similar issue, it is related to input sensor name and output tensor name which is provided wrong. Even I want to know proper names