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(    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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.