小行星

热爱平淡,向往未知


  • 首页

  • 分类

  • 归档

  • 关于

  • 阅读排行

  • 搜索

faster-rcnn 总结

发表于 2018-02-Mon | 阅读次数:

clion cmakelist

发表于 2018-02-Sat | 阅读次数:
1
2
3
4
5
6
7
8
9
10
11
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")

cmake_minimum_required( VERSION 3.8 )
project(hello)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "-g")
set(CMAKE_CXX_FLAGS "-Wall")

add_executable (go src/go.cpp)
add_executable(main src/main.cpp)

atrous卷积

发表于 2018-02-Fri | 阅读次数:

https://www.zhihu.com/question/49630217

tensorflow 变量空间

发表于 2018-02-Fri | 阅读次数:

tf.Variable 和 tf.get_variable 区别

使用tf.Variable时,如果检测到命名冲突,系统会自己处理。使用tf.get_variable()时,系统不会处理冲突,而会报错
所以还是用tf.get_variable()好

name_scope 和 variable_scope

get_variable只看variable_scope, variable都看

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
In [47]: with tf.name_scope('nsc1'):
...: v1 = tf.Variable([1], name="v1")
...: with tf.variable_scope("vsc1"):
...: v2 = tf.Variable([1], name="v2")
...: v3 = tf.get_variable(name="v3", shape=[])
...:

In [48]: print v1.name
nsc1/v1:0

In [49]: print v2.name
nsc1/vsc1/v2:0

In [50]: print v3.name
vsc1/v3:0

tensorflow conv2-same 理解

发表于 2018-02-Fri | 阅读次数:

数字理解

输出结果的shape计算:
‘SAME’ 类型的padding,其输出的height和width计算如下:
out_height = ceil(float(in_height) / float(strides[1])) ceil:向上取整
out_width = ceil(float(in_width) / float(strides[2]))

‘VALID’类型的padding, 其输出的height和width计算如下:
out_height = ceil(float(in_height – filter_height + 1) / float(strides[1]))
out_width = ceil(float(in_width – filter_width + 1) / float(strides[2]))

图片理解

具体计算理解

1
2
3
4
5
6
7
8
9
10
x =
0 1 2 3
1 2 3 4
2 3 4 5
3 4 5 6

w =
0 1 2
1 2 3
2 3 4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def testConv2DSameEven(self):
n, n2 = 4, 2

# Input image.
x = create_test_input(1, n, n, 1)

# Convolution kernel.
w = create_test_input(1, 3, 3, 1)
w = array_ops.reshape(w, [3, 3, 1, 1])

variable_scope.get_variable('Conv/weights', initializer=w)
variable_scope.get_variable('Conv/biases', initializer=array_ops.zeros([1]))
variable_scope.get_variable_scope().reuse_variables()

y1 = layers.conv2d(x, 1, [3, 3], stride=1, scope='Conv')
y1_expected = math_ops.to_float([[14, 28, 43, 26], [28, 48, 66, 37],
[43, 66, 84, 46], [26, 37, 46, 22]])
y1_expected = array_ops.reshape(y1_expected, [1, n, n, 1])

y2 = resnet_utils.subsample(y1, 2)
y2_expected = math_ops.to_float([[14, 43], [43, 84]])
y2_expected = array_ops.reshape(y2_expected, [1, n2, n2, 1])

y3 = resnet_utils.conv2d_same(x, 1, 3, stride=2, scope='Conv')
y3_expected = y2_expected

y4 = layers.conv2d(x, 1, [3, 3], stride=2, scope='Conv')
y4_expected = math_ops.to_float([[48, 37], [37, 22]])
y4_expected = array_ops.reshape(y4_expected, [1, n2, n2, 1])

with self.test_session() as sess:
sess.run(variables.global_variables_initializer())
self.assertAllClose(y1.eval(), y1_expected.eval())
self.assertAllClose(y2.eval(), y2_expected.eval())
self.assertAllClose(y3.eval(), y3_expected.eval())
self.assertAllClose(y4.eval(), y4_expected.eval())

总结

1
2
3
4
5
1. net = conv2d_same(inputs, num_outputs, 3, stride=stride)
2. net = slim.conv2d(inputs, num_outputs, 3, stride=1, padding='SAME')
net = subsample(net, factor=stride)
3. net = slim.conv2d(inputs, num_outputs, 3, stride=stride, padding='SAME')
1和2是等价的,当inputs的高或宽是偶数时3与1,2不一样。

tf-faster-rcnn数据结构

发表于 2018-02-Thu | 阅读次数:

subsample

1
2
3
4
5
6
7
8
9
10
11
12
13
14
def subsample(inputs, factor, scope=None):
"""Subsamples the input along the spatial dimensions.
Args:
inputs: A `Tensor` of size [batch, height_in, width_in, channels].
factor: The subsampling factor.
scope: Optional variable_scope.
Returns:
output: A `Tensor` of size [batch, height_out, width_out, channels] with the
input, either intact (if factor == 1) or subsampled (if factor > 1).
"""
if factor == 1:
return inputs
else:
return slim.max_pool2d(inputs, [1, 1], stride=factor, scope=scope)

bottleneck

开始没理解resnet_utils.subsample和slim.conv2d的区别,后来发现其实
问题在于depth, 如何depth已经搞定了,那么就直接subsample就好了,如果
sample没搞定就得conv. 从这里可以看出一个问题desample的效果会好于conv2d.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def bottleneck(inputs, depth, depth_bottleneck, stride, rate=1,
outputs_collections=None, scope=None):
with tf.variable_scope(scope, 'bottleneck_v2', [inputs]) as sc:
depth_in = slim.utils.last_dimension(inputs.get_shape(), min_rank=4)
preact = slim.batch_norm(inputs, activation_fn=tf.nn.relu, scope='preact')
if depth == depth_in:
shortcut = resnet_utils.subsample(inputs, stride, 'shortcut')
else:
shortcut = slim.conv2d(preact, depth, [1, 1], stride=stride,
normalizer_fn=None, activation_fn=None,
scope='shortcut')

residual = slim.conv2d(preact, depth_bottleneck, [1, 1], stride=1,
scope='conv1')
residual = resnet_utils.conv2d_same(residual, depth_bottleneck, 3, stride,
rate=rate, scope='conv2')
residual = slim.conv2d(residual, depth, [1, 1], stride=1,
normalizer_fn=None, activation_fn=None,
scope='conv3')

output = shortcut + residual

return slim.utils.collect_named_outputs(outputs_collections,
sc.name,
output)

tensorflow 常用命令

发表于 2018-02-Thu | 阅读次数:

config

1
2
3
tfconfig = tf.ConfigProto(allow_soft_placement=True)
tfconfig.gpu_options.allow_growth=True
sess = tf.Session(config=tfconfig)

声明placeholder

1
self._image = tf.placeholder(tf.float32, shape=[1, None, None, 3])

数字转换

1
2
3
tf.to_int32()
tf.ceil()
np.float32()

数组操作

1
2
tf.transpose()
tf.reshape()

py_func

1
2
3
4
5
6
7
py_func(
func,
inp,
Tout,
stateful=True,
name=None
)

时间

loss 常用函数

1
2
3
cross_entropy = -tf.reduce_sum(true_y*tf.log(out_y))
correct_prediction = tf.equal(tf.argmax(out_y,1), tf.argmax(true_y,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))

conda环境迁移

发表于 2018-02-Thu | 阅读次数:
1
2
3
4
5
6
conda env export > environment.yml
conda env create -f environment.yml

conda list --explicit > spec-file.txt
conda create --name myenv --file spec-file.txt
conda install --name myenv --file spec-file.txt

docker使用

发表于 2018-02-Thu | 阅读次数:
1
2
3
4
5
6
7
8
9
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
sudo apt-get install -y docker-engine
sudo service docker start
sudo docker run hello-world
sudo usermod -aG docker $(whoami)

jupyter 隐藏环境名

发表于 2018-02-Thu | 阅读次数:
1
conda config --set changeps1 False
1…495051…59
fangyh

fangyh

最爱的是那苍穹之外的浩渺宇宙

588 日志
4 分类
66 标签
© 2020 fangyh
由 Hexo 强力驱动
|
主题 — NexT.Mist v5.1.3
|本站总访问量次