36 import tensorflow
as tf
38 from tools
import ResizeAndCrop
40 KITTISEG_ROOT_FOLDER =
'/home/perfetto/KittiSeg_source' +
'/incl/' 42 sys.path.insert(1, KITTISEG_ROOT_FOLDER)
46 import tensorvision.utils
as tv_utils
47 import tensorvision.core
as tv_core
51 logging.error(
"Could not import the submodules.")
54 if not os.path.exists(KITTISEG_ROOT_FOLDER):
55 logging.error(
"KittiSeg folder " + KITTISEG_ROOT_FOLDER +
' in not found')
57 logging.error(
"You use " + KITTISEG_ROOT_FOLDER +
' as KittSeg folder')
60 EX_TYPE, EX, TB = sys.exc_info()
61 traceback.print_tb(TB)
66 """Class to initialize and run KittiSeg""" 67 def __init__(self, logdir, original_image_size, runCPU=False):
68 """Initialize KittiSeg: 69 Inputs: logdir (Directory to KittiSeg model), 70 runCPU (Optional, if set to True TensorFlow runs on CPU instead of GPU""" 72 rospy.loginfo(
"Using weights found in {}".format(logdir))
75 self.
hypes = tv_utils.load_hypes_from_logdir(logdir, base_path=
'hypes')
77 rospy.loginfo(
"self.hypes loaded successfully.")
80 modules = tv_utils.load_modules_from_logdir(logdir)
81 rospy.loginfo(
"Modules loaded successfully. Starting to build tf graph.")
84 with tf.Graph().as_default():
89 with tf.device(tf_device):
93 tf_image.set_shape([1,
None,
None, 3])
97 self.
hypes, modules, image=tf_image)
99 rospy.loginfo(
"Graph build successfully.")
116 tf_saver = tf.train.Saver()
119 tv_core.load_weights(logdir, self.
tf_session, tf_saver)
121 rospy.loginfo(
"Weights loaded successfully.")
127 """A function that runs an image through KittiSeg 128 Input: Image to process 129 Output: tagged_image, time_tf""" 133 time__tf_start = timeit.default_timer()
135 output = self.tf_session.run([softmax], feed_dict=feed)
137 time__tf = timeit.default_timer() - time__tf_start
141 return output[0][:, 1].reshape(shape[0], shape[1]), time__tf
144 """A function that sets up and runs an image through KittiSeg 145 Input: Image to process 146 Output: way_prediction, time_tf""" 157 return self.tools.postprocess_image(
def __init__(self, logdir, original_image_size, runCPU=False)
def run_processed_image(self, image)
def run_model_on_image(self, image)