def _anchor_component(self): """ # 为特征图生产anchors :return: """ with tf.variable_scope('ANCHOR_' + self._tag) as scope: # just to get the shape right height = tf.to_int32( tf.ceil(self._im_info[0] / np.float32(self._feat_stride[0]))) width = tf.to_int32( tf.ceil(self._im_info[1] / np.float32(self._feat_stride[0]))) if cfg.USE_E2E_TF: anchors, anchor_length = generate_anchors_pre_tf( height, width, self._feat_stride, self._anchor_scales, self._anchor_ratios) else: anchors, anchor_length = tf.py_func(generate_anchors_pre, [ height, width, self._feat_stride, self._anchor_scales, self._anchor_ratios ], [tf.float32, tf.int32], name="generate_anchors") anchors.set_shape([None, 4]) anchor_length.set_shape([]) self._anchors = anchors self._anchor_length = anchor_length
def network(is_training=True): global anchors with tf.variable_scope('network') as scope: net = vgg16_head(image_placeholder,1.0) # just to get the shape right height = tf.to_int32(tf.ceil(imgsize_placeholder[0] / np.float32(16))) width = tf.to_int32(tf.ceil(imgsize_placeholder[1] / np.float32(16))) anchors, anchor_length = generate_anchors_pre_tf(height,width) anchors.set_shape([None, 4]) anchor_length.set_shape([]) rois = _region_proposal(net,is_training) if cfg.POOLING_MODE == 'crop': pool5 = _crop_pool_layer(net, rois, "pool5")#128x7x7x512 else: raise NotImplementedError fc7 = vgg16_tail(pool5, is_training) cls_prob, bbox_pred = _region_classification(fc7, is_training, initializer=tf.truncated_normal_initializer(mean=0.0, stddev=0.01), initializer_bbox=tf.truncated_normal_initializer(mean=0.0, stddev=0.001)) _score_summaries.update(_predictions) return rois, cls_prob, bbox_pred
def _anchor_component(self): with tf.variable_scope('ANCHOR_' + self._tag) as scope: # self._im_info np.array(): stores image dimensions. Format: # 0: height # 1: width # 2: layers # number of horizontal and vertical anchors. height = tf.to_int32( tf.ceil(self._im_info[0] / np.float32(self._feat_stride[0]))) width = tf.to_int32( tf.ceil(self._im_info[1] / np.float32(self._feat_stride[0]))) # Use an end-to-end tensorflow model. # Note: models in E2E tensorflow mode have only been tested in feed-forward mode, # but these models are exportable to other tensorflow instances as GraphDef files. if cfg.USE_E2E_TF: # Generates TF anchors anchors, anchor_length = generate_anchors_pre_tf( height, width, self._feat_stride, self._anchor_scales, self._anchor_ratios) else: # Generates numpy anchors anchors, anchor_length = tf.py_func(generate_anchors_pre, [ height, width, self._feat_stride, self._anchor_scales, self._anchor_ratios ], [tf.float32, tf.int32], name="generate_anchors") anchors.set_shape([None, 4]) anchor_length.set_shape([]) self._anchors = anchors self._anchor_length = anchor_length
def _anchor_component(self, selection): with tf.variable_scope('ANCHOR_' + self._tag) as scope: # just to get the shape right height = tf.to_int32( tf.ceil(self._im_info[0] / np.float32(self._feat_stride[0]))) width = tf.to_int32( tf.ceil(self._im_info[1] / np.float32(self._feat_stride[0]))) if cfg.USE_E2E_TF: anchors, anchor_length = generate_anchors_pre_tf( height, width, self._feat_stride, self._anchor_scales, self._anchor_ratios) else: anchors, anchor_length = tf.py_func(generate_anchors_pre, [ height, width, self._feat_stride, self._anchor_scales, self._anchor_ratios ], [tf.float32, tf.int32], name="generate_anchors") anchors.set_shape([1, None, None, self._num_anchors * 4]) self._anchors = tf.reshape(anchors, [-1, 4]) anchor_length.set_shape([]) anchors_as = self.select_scale(anchors, selection, 4) anchors_as = tf.reshape(anchors_as, [-1, 4]) self._anchors_as = anchors_as self._anchor_length = anchor_length
def _anchor_component(self): with tf.variable_scope('ANCHOR_' + self._tag) as scope: # 1. 计算特征图尺寸 # 利用原图尺寸及stride数值,推算出经过特征提取后输出的特征图尺寸:height & width # just to get the shape right height = tf.to_int32( tf.ceil(self._im_info[0] / np.float32(self._feat_stride[0]))) width = tf.to_int32( tf.ceil(self._im_info[1] / np.float32(self._feat_stride[0]))) # 2. 获得所有anchor值,anchor包括H, W, X, Y四个参数 # anchor: [H*W*9, 4] # todo: 修改anchor数量 if cfg.USE_E2E_TF: anchors, anchor_length = generate_anchors_pre_tf( height, width, self._feat_stride, self._anchor_scales, self._anchor_ratios) else: anchors, anchor_length = tf.py_func(generate_anchors_pre, [ height, width, self._feat_stride, self._anchor_scales, self._anchor_ratios ], [tf.float32, tf.int32], name="generate_anchors") anchors.set_shape([None, 4]) anchor_length.set_shape([]) self._anchors = anchors self._anchor_length = anchor_length
def _anchor_component(self): # 生成每张图的anchor with tf.variable_scope('ANCHOR_' + self._tag) as scope: # just to get the shape right # 卷积特征图的尺寸 self._feat_stride[0]=16 经过4次pooling height = tf.to_int32(tf.ceil(self._im_info[0] / np.float32(self._feat_stride[0]))) width = tf.to_int32(tf.ceil(self._im_info[1] / np.float32(self._feat_stride[0]))) # 默认使用tensorflow端到端,不使用numpy if cfg.USE_E2E_TF: anchors, anchor_length = generate_anchors_pre_tf( height, width, self._feat_stride, self._anchor_scales, self._anchor_ratios ) else: anchors, anchor_length = tf.py_func(generate_anchors_pre, [height, width, self._feat_stride, self._anchor_scales, self._anchor_ratios], [tf.float32, tf.int32], name="generate_anchors") anchors.set_shape([None, 4]) anchor_length.set_shape([]) self._anchors = anchors self._anchor_length = anchor_length
def _anchor_component(self): with tf.variable_scope('ANCHOR_') as scope: # just to get the shape right height = tf.to_int32(tf.ceil(self._im_info[0] / np.float32(self._feat_stride[0]))) width = tf.to_int32(tf.ceil(self._im_info[1] / np.float32(self._feat_stride[0]))) anchors, anchor_length = generate_anchors_pre_tf(height, width) anchors.set_shape([None, 5]) anchor_length.set_shape([]) self._anchors = anchors self._anchor_length = anchor_length
def _anchor_component(self): with tf.variable_scope('ANCHOR_' + self._tag) as scope: # just to get the shape right height = tf.to_int32(tf.ceil(self._im_info[0] / np.float32(self._feat_stride[0]))) width = tf.to_int32(tf.ceil(self._im_info[1] / np.float32(self._feat_stride[0]))) if cfg.USE_E2E_TF: anchors, anchor_length = generate_anchors_pre_tf( height, width, self._feat_stride, self._anchor_scales, self._anchor_ratios ) else: anchors, anchor_length = tf.py_func(generate_anchors_pre, [height, width, self._feat_stride, self._anchor_scales, self._anchor_ratios], [tf.float32, tf.int32], name="generate_anchors") anchors.set_shape([None, 4]) anchor_length.set_shape([]) self._anchors = anchors self._anchor_length = anchor_length
def _anchor_component(self, net_conv): """ all_anchors: (-1, 4) """ with tf.variable_scope('ANCHOR_' + self._tag) as scope: # just to get the shape right print('anchor_strides: ', self._anchor_strides) height, width = tf.shape(net_conv)[1], tf.shape(net_conv)[2] if cfg.USE_E2E_TF: anchors, anchor_length = generate_anchors_pre_tf( height, width, self._anchor_strides[0], self._anchor_sizes, self._anchor_ratios) else: anchors, anchor_length = tf.py_func(generate_anchors_pre, [ height, width, self._anchor_strides[0], self._anchor_sizes, self._anchor_ratios ], [tf.float32, tf.int32], name="generate_anchors") anchors.set_shape([None, 4]) anchor_length.set_shape([]) self._anchors = anchors self._anchor_length = anchor_length