def _model_infer_to_count(self, lstm_output, mask_list, model_params): wd = model_params["weight_decay"] desmap_scale = model_params["desmap_scale"] count_list = list() with tf.variable_scope("count_fc"): for i, output in enumerate(lstm_output): if i != 0: tf.get_variable_scope().reuse_variables() count_bias = mf.fully_connected_layer(output, 1, wd, "fc") count_bias_decay = tf.mul(tf.nn.l2_loss(count_bias), wd, name='bias_decay_%d' % i) tf.add_to_collection("losses", count_bias_decay) pred_img = self._filter_mask(self.predict_list[i][-1], mask_list[i]) image_sum = tf.expand_dims(tf.reduce_sum(pred_img, [1, 2, 3]), 1) / desmap_scale count = count_bias + image_sum tf.summary.scalar("check/image_sum/%d" % (i), tf.reduce_mean(image_sum)) tf.summary.scalar("check/count_bias/%d" % (i), tf.reduce_mean(count_bias)) count_list.append(count) return count_list
def model_infer(self, data_ph, model_params): input_ph = data_ph.get_input() leaky_param = model_params["leaky_param"] wd = model_params["weight_decay"] image_ph_0 = tf.image.resize_images(input_ph, [72, 72]) stage_0 = self._single_hydra_cnn(image_ph_0, model_params, 0) print(stage_0) image_ph_1 = iuf.batch_center_crop_frac(image_ph_0, 0.9) image_ph_1 = tf.image.resize_images(image_ph_1, [72, 72]) stage_1 = self._single_hydra_cnn(image_ph_1, model_params, 1) print(stage_1) image_ph_2 = iuf.batch_center_crop_frac(image_ph_0, 0.8) image_ph_2 = tf.image.resize_images(image_ph_2, [72, 72]) stage_2 = self._single_hydra_cnn(image_ph_2, model_params, 2) print(stage_2) concat_feature = tf.concat(1, [stage_0, stage_1, stage_2]) print(concat_feature) fc6 = mf.fully_connected_layer(concat_feature, 1024, wd, "fc6") fc7 = mf.fully_connected_layer(fc6, 1024, wd, "fc7") fc8 = mf.fully_connected_layer(fc7, 1024, wd, "fc8") batch_size = model_params["batch_size"] output = tf.expand_dims(tf.reshape(fc8, [batch_size, 32, 32]), 3) print(output) l_ph_r = model_params["label_ph_row"] l_ph_c = model_params["label_ph_col"] resized_output = tf.image.resize_images(output, [l_ph_r, l_ph_c]) print(resized_output) with tf.variable_scope("image_sum"): self._add_image_sum(data_ph.get_input(), data_ph.get_label(), resized_output, data_ph.get_mask()) self.predict_list = list() self.predict_list.append(resized_output)
def _model_infer_to_count(self, lstm_output, model_params): wd = model_params["weight_decay"] count_list = list() with tf.variable_scope("count_fc"): for i, output in enumerate(lstm_output): if i != 0: tf.get_variable_scope().reuse_variables() count = mf.fully_connected_layer(output, 1, wd, "fc") count_list.append(count) return count_list