def __init__(self, model_config_name, model_path, truncate_len=20, batch_size=1): # currently, we use a sliding window fashion for evaluation, that's inefficient but convenient to implement self.truncate_len = truncate_len self.latest_frames = [] for _ in range(truncate_len): self.latest_frames.append(np.zeros((IMSZ, IMSZ, 3), dtype=np.uint8)) # call the config.py for setup import config common_config("eval") config_fun = getattr(config, model_config_name) config_fun("eval") common_config_post("eval") # Tensors in has the format: [images, speed] for basic usage, excluding only_seg # For now, we decide not to support previous speed as input, thus we use a fake speed (-1) now # and ensures the speed is not used by asserting FLAGS.use_previous_speed_feature==False assert (not hasattr(FLAGS, "use_previous_speed_feature")) or ( FLAGS.use_previous_speed_feature == False) # batch size 1 all the time, length undetermined, width and height are IMSZ FLAGS.__setattr__('log_device_placement', True) self.tensors_in = tf.placeholder(tf.uint8, shape=(batch_size, truncate_len, IMSZ, IMSZ, 3), name="images_input") self.speed = None logits_all = model.inference([self.tensors_in, self.speed], -1, for_training=False) # Restore the moving average version of the learned variables for eval. variable_averages = tf.train.ExponentialMovingAverage( model.MOVING_AVERAGE_DECAY) variables_to_restore = variable_averages.variables_to_restore() saver = tf.train.Saver(variables_to_restore) config = tf.ConfigProto(intra_op_parallelism_threads=1) config.gpu_options.allow_growth = True self.sess = tf.Session(config=config) saver.restore(self.sess, model_path) self.logits = tf.nn.softmax(logits_all[0]) init_op = tf.initialize_local_variables() self.sess.run(init_op)
FLAGS = tf.app.flags.FLAGS flags_passthrough = FLAGS._parse_flags() from config import common_config, common_config_post IMSZ = 228 model_config_name = "discrete_fcn_lstm" truncate_len = 20 #sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) #write_dict_to_file('./results/flags_orig.txt', FLAGS.__flags) import config common_config("eval") config_fun = getattr(config, model_config_name) config_fun("eval") common_config_post("eval") #write_dict_to_file('./results/flags_altered.txt', FLAGS.__flags) # Tensors in has the format: [images, speed] for basic usage, excluding only_seg # For now, we decide not to support previous speed as input, thus we use a fake speed (-1) now # and ensures the speed is not used by asserting FLAGS.use_previous_speed_feature==False assert (not hasattr(FLAGS, "use_previous_speed_feature")) or ( FLAGS.use_previous_speed_feature == False) # batch size 1 all the time, length undetermined, width and height are IMSZ #FLAGS.__setattr__('log_device_placement', True) tensors_in = tf.placeholder(tf.uint8, shape=(256, truncate_len, IMSZ, IMSZ, 3),
def __init__(self, model_config_name, model_path, truncate_len=20, config_name="config", config_path=".", is_lstm=False): self.is_lstm = is_lstm if is_lstm: assert truncate_len==1, \ "using lstm should set truncate_len to 1, otherwise waste of computing resource" # currently, we use a sliding window fashion for evaluation, that's inefficient but convenient to implement self.truncate_len = truncate_len self.latest_frames = [] for _ in range(truncate_len): self.latest_frames.append(np.zeros((IMSZ, IMSZ, 3), dtype=np.uint8)) # call the config.py for setup sys.path.append(config_path) config = importlib.import_module(config_name) common_config("eval") config_fun = getattr(config, model_config_name) config_fun("eval") common_config_post("eval") # Tensors in has the format: [images, speed] for basic usage, excluding only_seg # For now, we decide not to support previous speed as input, thus we use a fake speed (-1) now # and ensures the speed is not used by asserting FLAGS.use_previous_speed_feature==False assert (not hasattr(FLAGS, "use_previous_speed_feature")) or (FLAGS.use_previous_speed_feature == False) # batch size 1 all the time, length undetermined, width and height are IMSZ self.tensors_in = tf.placeholder(tf.uint8, shape=(1, truncate_len, IMSZ, IMSZ, 3), name="images_input") self.speed = None if is_lstm: self.initial_state = ((tf.placeholder(tf.float32, shape=(1, int(FLAGS.lstm_hidden_units)), name="state_placeholder1"), tf.placeholder(tf.float32, shape=(1, int(FLAGS.lstm_hidden_units)), name="state_placeholder2")), ) FLAGS.phase = "rnn_inference" else: self.initial_state = None logits_all = model.inference([self.tensors_in, self.speed], -1, for_training=False, initial_state=self.initial_state) # Restore the moving average version of the learned variables for eval. variable_averages = tf.train.ExponentialMovingAverage(model.MOVING_AVERAGE_DECAY) variables_to_restore = variable_averages.variables_to_restore() saver = tf.train.Saver(variables_to_restore) config = tf.ConfigProto(intra_op_parallelism_threads=1) config.gpu_options.allow_growth = True self.sess = tf.Session(config=config) saver.restore(self.sess, model_path) self.logits = logits_all[0] if is_lstm: self.state_tensor = logits_all[-1] self.state_value=[[np.zeros((1, int(FLAGS.lstm_hidden_units)), dtype=np.float32), np.zeros((1, int(FLAGS.lstm_hidden_units)), dtype=np.float32)]] init_op = tf.initialize_local_variables() self.sess.run(init_op)