tensorflow学习记录——对于GoogleNet的尝试
在github下载了一个google的demo,尝试了解中
github链接为:
https://github.com/skloisMary/demo-Network/blob/master/GoogleNet/googleNet.py
下面是学习记录
主要是对里面用到的函数的一个学习
tf.contrib.layers.flatten()
https://blog.csdn.net/Sophia_11/article/details/84729102
将一个高维张量展开为二维
tf.contrib.layers.flatten(A)函数使得A保留第一个维度,把第一个维度包含的每一子张量展开成一个行向量,返回张量是一个二维的,返回的shape为[第一维度,子张量乘积)。
注意:
The format of the data to be supplied is [i, j, k, l] where i is the number of training samples, j is the height of the image, k is the weight and l is the channel number.
虽然是二维卷积,但是输入应该是四维张量。i为训练样本数,j,k为高,l为通道数
假设pool是一个100* 7 * 7 *64的矩阵,则通过转换后,得到一个[100,3136]
tf.layers.conv2d
https://blog.csdn.net/caomin1hao/article/details/80600738
二维卷积
tf.layers.conv2d中,filters属性为卷积核数量,kernel_size则为卷积核大小,具体卷积核内容内部自动生成
tf.nn.conv2d中,filter为卷积核,需要具体输入权重值,适合加载已经训练好的内容
tf.layers.max_pooling2d
二维最大池化
事实上,如果将池化步长设置为1的话,池化也不会改变图像大小
tf.concat()
https://blog.csdn.net/leviopku/article/details/82380118
用来拼接两个张量(仅在一个维度上拼接)
用于Inception 模块,它的目的是设计一种具有优良局部拓扑结构的网络,即对输入图像并行地执行多个卷积运算或池化操作,并将所有输出结果拼接为一个非常深的特征图。因为 11、33 或 55 等不同的卷积运算与池化操作可以获得输入图像的不同信息,并行处理这些运算并结合所有结果将获得更好的图像表征。*
大概就是综合各个大小的卷积核得到的结果的意思吧……
在下载的demo里,就是用来将几个卷积得到的结果直接拼接到一起,感觉有点某种意义上的全连接层的意思
ps:在Incepton模块中,几个卷积都没有改变图像的大小
tf.variable_scope()
https://blog.csdn.net/js54100804/article/details/80463520 tf.Variable()和tf.get_variable()区别
https://blog.csdn.net/gqixf/article/details/82770192 tf.variable_scope()
tf.variable_scope()可以定义变量名作用区域,可以允许‘name’属性相同的两个不同变量在两个作用域分别存在
结合tf.get_variable()可以在两个作用域之间引用变量(会变成同一个变量)
tf.layers.dropout()
https://blog.csdn.net/o0haidee0o/article/details/80514578
tf.nn.dropout 中参数 keep_prob :每一个元素被保存下的概率。而 tf.layer.dropout 中参数 rate :每一个元素丢弃的概率。所以,keep_prob = 1 - rate。
在 tf.layer.dropout 中有一个 training 参数:在training模式中,返回应用dropout后的输出;或者在非training模式下,正常返回输出(没有dropout)。这里说的training模式也即是training参数为True的时候。
tf.layers.dense()
https://www.w3cschool.cn/tensorflow_python/tensorflow_python-rn6a2tps.html
全连接层
tf.nn.softmax()
https://blog.csdn.net/wgj99991111/article/details/83586508
tf.contrib.layers.xavier_initializer
https://blog.csdn.net/yinruiyang94/article/details/78354257/
该函数返回一个用于初始化权重的初始化程序 “Xavier” 。
这个初始化器是用来保持每一层的梯度大小都差不多相同。
tf.contrib.layers.xavier_initializer_conv2d
初始化权重