TF_APIs_Used_In_Code
tf.nn.conv2d
[ref]: 这是最先去查找的API函数(足见其使用程度), 它定义在 tensorflow/python/ops/nn_ops.py
中, 它对所给的4D input
和filter
张量(Tensor)进行2D的卷积运算(这里的2-D和4-D别搞混了, 一个是卷积, 一个是Tensor的尺寸), 它有别名tf.compat.v1.nn.conv2d
和tf.nn.conv2d
, 它的函数形式为:
1 | tf.nn.conv2d( |
其中, Input和Filter的shape如下:
Input Tensor Shape |
---|
[batch, in_height, in_width, in_channels] |
输入: [批的大小(数据数), 高, 宽, 输入通道数(如RGB)] |
Filter/Kernel Tensor Shape |
---|
[filter_height, filter_width, in_channels, out_channels] |
滤核: [高, 宽, 输入通道数(要被卷积的输入), 输出通道数(输出的特征图数)] |
下面, 再讨论下它的参数:
| 参数名 | 参数说明(针对理解和记忆) |
| —— | —— |
| input
| 参数类型: Tensor(4D), 另: 这里4D中维度顺序(Order)的含义, 与下面的data_format
参数值有关. |
| filter=None | 参数类型: 4D Tensor, 与input
参数同type, shape是: [filter_height, filter_width, in_channels, out_channels]. |
| strides=None | strides
(步长)参数可以是: 1.int
, 2.[ints]
(长为1, 2或4), 它表示的是滤核窗口(sliding window)在input
的每个维度上的stride. 如果参数值给的是一个单独的int
值, 则它会被重复成(replicated)H
和 W
维度的值. 默认的, N
和C
维度的值被设置为1(要不然我也理解不了:)). 维度顺序的含义见data_format
这个老朋友了. |
| padding=None | 字符串值(表示具体的padding algorithm): 1.”SAME”, 2.”VALID”, 或者一个list: 3.表明每个维度(高/宽)上起始边界的具体padding(alg), 如: a."NHWC"
(data_format) => [[0, 0], [pad_top, pad_bottom], [pad_left, pad_right], [0, 0]]
, b."NCHW"
=> [[0, 0], [0, 0], [pad_top, pad_bottom], [pad_left, pad_right]]
. |
| use_cudnn_on_gpu=True | An optional bool
. Defaults to True
. |
| data_format=’NHWC’ | Optional, 有”NHWC”(默认)和”NCHW”两种, “NHWC”格式的数据存储顺序为: [batch, height, width, channels], “NCHW”也同理. |
| dilations=[1,1,1,1] | 膨胀值(?!), 暂时无解: “An int or list of ints
that has length 1
, 2
or 4
, defaults to 1. The dilation factor for each dimension ofinput
. If a single value is given it is replicated in the H
and W
dimension. By default the N
and C
dimensions are set to 1. If set to k > 1, there will be k-1 skipped cells between each filter element on that dimension. The dimension order is determined by the value of data_format
, see above for details. Dilations in the batch and depth dimensions if a 4-d tensor must be 1”. |
| name=None | A name for the operation (optional). |
| filters=None | Alias for filter. |
返回: A Tensor
. Has the same type as input
, 注: 即返回Tensor的type同输入的type.
https://tensorflow.google.cn/api_docs/python/tf/reshape
https://tensorflow.google.cn/api_docs/python/tf/nn/relu
https://tensorflow.google.cn/api_docs/python/tf/nn/max_pool
https://tensorflow.google.cn/api_docs/python/tf/nn/dropout
https://tensorflow.google.cn/api_docs/python/tf/get_variable
https://tensorflow.google.cn/api_docs/python/tf/nn/bias_add
https://tensorflow.google.cn/api_docs/python/tf/nn/xw_plus_b
https://tensorflow.google.cn/api_docs/python/tf/math/reduce_mean
https://tensorflow.google.cn/api_docs/python/tf/nn/softmax_cross_entropy_with_logits_v2
https://tensorflow.google.cn/api_docs/python/tf/trainable_variables
tf.nn.conv2d: dilations
Others
https://blog.csdn.net/qq_39894692/article/details/84288782
https://blog.csdn.net/he_min/article/details/78694383
权重可视化
https://blog.csdn.net/zxj942405301/article/details/71194359
W3Cschool_TF_Api
主页链接.