Semantic segmentation with DeepLabV3

Run the following steps to implement semantic segmentation with DeepLabV3:

  1. Define the following function to load the pretrained DeepLab V3 model (frozen-inference graph) and run a forward pass with tensorflow to obtain the segmentation map:
def run_semantic_segmentation(image, model_path):    input_tensor_name = 'ImageTensor:0'    output_tensor_name = 'SemanticPredictions:0'    input_size = 513    graph = tf.Graph()    graph_def = None    with gfile.FastGFile(model_path, 'rb') as f:        graph_def = tf.GraphDef()        graph_def.ParseFromString(f.read())    if graph_def is None:      raise RuntimeError('Cannot find inference graph in tar \                        archive.')    with graph.as_default():      tf.import_graph_def(graph_def, name='') sess = tf.Session(graph=graph) ...

Get Python Image Processing Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.