ALEXNET复现

TF_APIs_Used_In_Code

tf.nn.conv2d[ref]: 这是最先去查找的API函数(足见其使用程度), 它定义在 tensorflow/python/ops/nn_ops.py中, 它对所给的4D inputfilter张量(Tensor)进行2D的卷积运算(这里的2-D和4-D别搞混了, 一个是卷积, 一个是Tensor的尺寸), 它有别名tf.compat.v1.nn.conv2dtf.nn.conv2d, 它的函数形式为:

1
2
3
4
5
6
7
8
9
10
11
tf.nn.conv2d(
input,
filter=None,
strides=None,
padding=None,
use_cudnn_on_gpu=True,
data_format='NHWC',
dilations=[1, 1, 1, 1],
name=None,
filters=None
)

其中, InputFilter的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)HW维度的值. 默认的, NC维度的值被设置为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 Cdimensions 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

https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&tn=baidu&wd=tf.nn.conv2d%20dilation%20%E5%8F%82%E6%95%B0&oq=tf.nn.conv2d%2520dilation&rsv_pq=8d8ddefb0011af5f&rsv_t=45242FCcBAE8QexdbB3oC707gBsMK3p7ngPowRwLCZmnebhNPFwmzgLWZ1M&rqlang=cn&rsv_enter=1&inputT=2196&rsv_sug3=32&rsv_sug1=9&rsv_sug7=000&rsv_sug2=0&rsv_sug4=2618&rsv_sug=1

Others

https://blog.csdn.net/qq_39894692/article/details/84288782

https://blog.csdn.net/he_min/article/details/78694383

权重可视化

https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&tn=baidu&wd=alexnet%20%E5%8F%AF%E8%A7%86%E5%8C%96%E6%9D%83%E9%87%8D&oq=alexnet&rsv_pq=9c5db92800069791&rsv_t=885cULoYq21CKR68crNrnhwyPz1pSb9BTb31vxMn8LtPh2of0gD47VM5rYk&rqlang=cn&rsv_enter=1&rsv_sug3=47&rsv_sug1=5&rsv_sug7=100&rsv_sug2=0&inputT=14018&rsv_sug4=14571

https://blog.csdn.net/zxj942405301/article/details/71194359


W3Cschool_TF_Api

主页链接.