def build_graph(input_tensor, train_flag, start_filter_size, n_anchors, n_classes):
# preprocessing
mean = tf.constant(np.load('rgb_mean.npy'), dtype=tf.float32)
x = (input_tensor - mean) / 255
with tf.name_scope('Block_1'):
x = get_block(x, start_filter_size, train_flag, maxpool=True)
with tf.name_scope('Block_2'):
x = get_block(x, start_filter_size * 2 ** 1, train_flag, maxpool=True)
with tf.name_scope('bigBlock_1'):
x = get_block(x, start_filter_size * 2 ** 2, train_flag)
x = get_block(x, start_filter_size * 2 ** 1, train_flag, kernel=(1, 1))
x = get_block(x, start_filter_size * 2 ** 2, train_flag, maxpool=True)
with tf.name_scope('bigBlock_2'):
x = get_block(x, start_filter_size * 2 ** 3, train_flag)
x = get_block(x, start_filter_size * 2 ** 2, train_flag, kernel=(1, 1))
x = get_block(x, start_filter_size * 2 ** 3, train_flag, maxpool=True)
with tf.name_scope('doubleBigBlock_1'):
x = get_block(x, start_filter_size * 2 ** 4, train_flag)
x = get_block(x, start_filter_size * 2 ** 3, train_flag, kernel=(1, 1))
x = get_block(x, start_filter_size * 2 ** 4, train_flag)
x = get_block(x, start_filter_size * 2 ** 3, train_flag, kernel=(1, 1))
x = get_block(x, start_filter_size * 2 ** 4, train_flag)
with tf.name_scope('passThrough'):
y = get_block(x, start_filter_size * 2 ** 1, train_flag)
y = tf.space_to_depth(y, 2)
with tf.name_scope('doubleBigBlock_2'):
x = tf.layers.max_pooling2d(x, (2, 2), (2, 2), padding='same')
x = get_block(x, start_filter_size * 2 ** 5, train_flag)
x = get_block(x, start_filter_size * 2 ** 4, train_flag, kernel=(1, 1))
x = get_block(x, start_filter_size * 2 ** 5, train_flag)
x = get_block(x, start_filter_size * 2 ** 4, train_flag, kernel=(1, 1))
x = get_block(x, start_filter_size * 2 ** 5, train_flag)
with tf.name_scope('Block_3'):
x = get_block(x, start_filter_size * 2 ** 5, train_flag)
with tf.name_scope('Block_4'):
x = get_block(x, start_filter_size * 2 ** 5, train_flag)
x = tf.concat([x, y], axis=3)
with tf.name_scope('Block_6'):
x = get_block(x, start_filter_size * 2 ** 5, train_flag)
with tf.name_scope('Prediction'):
x = get_block(x, n_anchors * (n_classes + 5), train_flag, kernel=(1, 1))
return x
评论列表
文章目录