35 import tensorflow
as tf
40 from tools
import ResizeAndCrop
45 if os.path.isdir(model_dir):
46 hypes_name = os.path.join(model_dir,
"deeplab.json")
48 hypes_name = model_dir
50 with open(hypes_name,
'r') as f: 55 """Class to load deeplab model and run inference.""" 57 def __init__(self, model_dir, original_image_size, tensor_io, runCPU, gpu_percent=1):
61 frozen_graph_path = self.
hypes[
'frozen_graph_path']
62 rospy.logwarn(
"Weights to load: " + frozen_graph_path)
64 """Creates and loads pretrained deeplab model.""" 69 with open(frozen_graph_path,
'rb')
as file_handle:
70 graph_def = tf.GraphDef.FromString(file_handle.read())
73 raise RuntimeError(
'Cannot find inference graph in given path.')
75 with self.graph.as_default():
76 tf.import_graph_def(graph_def, name=
'')
78 config = tf.ConfigProto()
79 config.gpu_options.per_process_gpu_memory_fraction = gpu_percent
80 self.
sess = tf.Session(graph=self.
graph, config=config)
84 if "input_image_size" in self.hypes.keys():
89 self.
tools = ResizeAndCrop(self.
hypes, original_image_size)
93 """A function that sets up and runs an image through KittiSeg 94 Input: Image to process 95 Output: way_prediction, time_tf""" 103 """Runs inference on a single image. 106 image: A PIL.Image object, raw input image. 109 resized_image: RGB image resized from original input image. 110 detected_classes: Segmentation map of `resized_image`. 112 time__tf_start = timeit.default_timer()
114 boxes, scores, classes = self.sess.run(
118 time__tf = timeit.default_timer() - time__tf_start
120 detected_classes = {}
121 detected_classes[
'boxes'] = boxes
122 detected_classes[
'scores'] = scores
123 detected_classes[
'classes'] = classes
124 return detected_classes, time__tf
def run_processed_image(self, image)
def __init__(self, model_dir, original_image_size, tensor_io, runCPU, gpu_percent=1)
def run_model_on_image(self, image)
def load_hypes(model_dir)