Tensorflow系列:tf.nn.conv2d是怎样实现卷积的?

tf.nn.conv2d是TensorFlow里面实现卷积的函数,参考文档对它的介绍并不是很详细,实际上这是搭建卷积神经网络比较核心的一个非常重要方法。

tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, name=None)

除去name参数用以指定该操作的name,与方法有关的一共五个参数:

第一个参数input:指需要做卷积的输入图像,它要求是一个Tensor,具有[batch, in_height, in_width, in_channels]这样的shape,具体含义是[训练时一个batch的图片数量, 图片高度, 图片宽度, 图像通道数],注意这是一个4维的Tensor,要求类型为float32和float64其中之一

第二个参数filter:相当于CNN中的卷积核,它要求是一个Tensor,具有[filter_height, filter_width, in_channels, out_channels]这样的shape,具体含义是[卷积核的高度,卷积核的宽度,图像通道数,卷积核个数],要求类型与参数input相同,有一个地方需要注意,第三维in_channels,就是参数input的第四维

第三个参数strides:卷积时在图像每一维的步长,这是一个一维的向量,长度4

第四个参数padding:string类型的量,只能是"SAME","VALID"其中之一,这个值决定了不同的卷积方式(后面会介绍)

第五个参数:use_cudnn_on_gpu:bool类型,是否使用cudnn加速,默认为true

结果返回一个Tensor,这个输出,就是我们常说的feature map


那么TensorFlow的卷积具体是怎样实现的呢,用一些例子去解释它:

1.考虑一种最简单的情况,现在有一张3×3单通道的图像(对应的shape:[1,3,3,1]),用一个1×1的卷积核(对应的shape:[1,1,1,1])去做卷积,最后会得到一张3×3的feature map

2.增加图片的通道数,使用一张3×3五通道的图像(对应的shape:[1,3,3,5]),用一个1×1的卷积核(对应的shape:[1,1,1,1])去做卷积,仍然是一张3×3的feature map,这就相当于每一个像素点,卷积核都与该像素点的每一个通道做点积

input = tf.Variable(tf.random_normal([1,3,3,5]))
filter = tf.Variable(tf.random_normal([1,1,5,1]))
op = tf.nn.conv2d(input, filter, strides=[1, 1, 1, 1], padding='VALID')

3.把卷积核扩大,现在用3×3的卷积核做卷积,最后的输出是一个值,相当于情况2的feature map所有像素点的值求和

input = tf.Variable(tf.random_normal([1,3,3,5]))
filter = tf.Variable(tf.random_normal([3,3,5,1]))
op = tf.nn.conv2d(input, filter, strides=[1, 1, 1, 1], padding='VALID')

4.使用更大的图片将情况2的图片扩大到5×5,仍然是3×3的卷积核,令步长为1,输出3×3的feature map

input = tf.Variable(tf.random_normal([1,5,5,5]))
filter = tf.Variable(tf.random_normal([3,3,5,1]))
op = tf.nn.conv2d(input, filter, strides=[1, 1, 1, 1], padding='VALID')

注意我们可以把这种情况看成情况2和情况3的中间状态,卷积核以步长1滑动遍历全图,以下x表示的位置,表示卷积核停留的位置,每停留一个,输出feature map的一个像素

.....

.xxx.
.xxx.
.xxx.
.....

5.上面我们一直令参数padding的值为‘VALID’,当其为‘SAME’时,表示卷积核可以停留在图像边缘,如下,输出5×5的feature map

input = tf.Variable(tf.random_normal([1,5,5,5]))
filter = tf.Variable(tf.random_normal([3,3,5,1]))
op = tf.nn.conv2d(input, filter, strides=[1, 1, 1, 1], padding='SAME')
xxxxx
xxxxx
xxxxx
xxxxx
xxxxx

6.如果卷积核有多个

input = tf.Variable(tf.random_normal([1,5,5,5]))
filter = tf.Variable(tf.random_normal([3,3,5,7]))
op = tf.nn.conv2d(input, filter, strides=[1, 1, 1, 1], padding='SAME')

此时输出7张5×5的feature map

7.步长不为1的情况,文档里说了对于图片,因为只有两维,通常strides取[1,stride,stride,1]

input = tf.Variable(tf.random_normal([1,5,5,5]))
filter = tf.Variable(tf.random_normal([3,3,5,7]))
op = tf.nn.conv2d(input, filter, strides=[1, 2, 2, 1], padding='SAME')

此时,输出7张3×3的feature map

x.x.x

.....
x.x.x
.....
x.x.x

8.如果batch值不为1,同时输入10张图

input = tf.Variable(tf.random_normal([10,5,5,5]))
filter = tf.Variable(tf.random_normal([3,3,5,7]))
op = tf.nn.conv2d(input, filter, strides=[1, 2, 2, 1], padding='SAME')

每张图,都有7张3×3的feature map,输出的shape就是[10,3,3,7]


最后,把程序总结一下:

import tensorflow as tf
#case 2
input = tf.Variable(tf.random_normal([1,3,3,5]))
filter = tf.Variable(tf.random_normal([1,1,5,1]))
op2 = tf.nn.conv2d(input, filter, strides=[1, 1, 1, 1], padding='VALID')

#case 3
input = tf.Variable(tf.random_normal([1,3,3,5]))
filter = tf.Variable(tf.random_normal([3,3,5,1]))
op3 = tf.nn.conv2d(input, filter, strides=[1, 1, 1, 1], padding='VALID')

#case 4
input = tf.Variable(tf.random_normal([1,5,5,5]))
filter = tf.Variable(tf.random_normal([3,3,5,1]))
op4 = tf.nn.conv2d(input, filter, strides=[1, 1, 1, 1], padding='VALID')

#case 5
input = tf.Variable(tf.random_normal([1,5,5,5]))
filter = tf.Variable(tf.random_normal([3,3,5,1]))
op5 = tf.nn.conv2d(input, filter, strides=[1, 1, 1, 1], padding='SAME')

#case 6
input = tf.Variable(tf.random_normal([1,5,5,5]))
filter = tf.Variable(tf.random_normal([3,3,5,7]))
op6 = tf.nn.conv2d(input, filter, strides=[1, 1, 1, 1], padding='SAME')

#case 7
input = tf.Variable(tf.random_normal([1,5,5,5]))
filter = tf.Variable(tf.random_normal([3,3,5,7]))
op7 = tf.nn.conv2d(input, filter, strides=[1, 2, 2, 1], padding='SAME')

#case 8
input = tf.Variable(tf.random_normal([10,5,5,5]))
filter = tf.Variable(tf.random_normal([3,3,5,7]))
op8 = tf.nn.conv2d(input, filter, strides=[1, 2, 2, 1], padding='SAME')

init = tf.initialize_all_variables()
with tf.Session() as sess:
    sess.run(init)
    print("case 2")
    print(sess.run(op2))
    print("case 3")
    print(sess.run(op3))
    print("case 4")
    print(sess.run(op4))
    print("case 5")
    print(sess.run(op5))
    print("case 6")
    print(sess.run(op6))
    print("case 7")
    print(sess.run(op7))
    print("case 8")
    print(sess.run(op8))

因为是随机初始化,我的结果是这样的:

case 2
[[[[-0.63291913]
   [-0.7212057 ]
   [ 2.963513  ]]

  [[ 0.03173107]
   [ 0.13940376]
   [ 2.7860522 ]]

  [[ 3.5999556 ]
   [ 1.6596901 ]
   [-1.7957366 ]]]]
case 3
[[[[5.378774]]]]
case 4
[[[[ 2.1810846]
   [ 6.865189 ]
   [-6.4903646]]

  [[ 6.8779445]
   [ 2.802436 ]
   [-2.1888316]]

  [[-4.668153 ]
   [-1.6869669]
   [ 1.9666238]]]]
case 5
[[[[ 2.3266203 ]
   [ 4.181429  ]
   [-8.371661  ]
   [-1.8303419 ]
   [ 0.6032718 ]]

  [[-7.9350047 ]
   [ 0.22496635]
   [-0.57937753]
   [-7.7791796 ]
   [ 7.8575196 ]]

  [[ 0.7933668 ]
   [-9.728089  ]
   [ 6.077424  ]
   [-1.2621287 ]
   [-3.1175556 ]]

  [[ 8.411166  ]
   [14.311018  ]
   [-8.612913  ]
   [ 1.5057913 ]
   [ 1.1987131 ]]

  [[ 0.13252163]
   [ 3.1023867 ]
   [-1.6454587 ]
   [-0.3878293 ]
   [ 4.329167  ]]]]
case 6
[[[[-4.97415662e-01 -2.11624718e+00 -5.44634104e+00  4.59510040e+00
    -2.82520700e+00 -1.75826800e+00 -1.99100006e+00]
   [ 1.19813490e+00 -1.62173021e+00  8.64818668e+00  1.03270226e+01
     7.96261263e+00 -1.65727198e+00 -1.04183044e+01]
   [-5.79362810e-01 -2.49706602e+00 -1.98799595e-02 -2.67636633e+00
     3.67414570e+00  7.66965723e+00 -4.18583155e+00]
   [-1.03236456e+01 -3.87444735e-01 -2.15530705e+00  8.33926773e+00
    -3.85079575e+00  1.39244890e+00 -8.81353438e-01]
   [-4.43148613e+00  4.86054754e+00 -2.14332080e+00  2.52895713e+00
     1.76540613e+00 -6.28431940e+00  9.46518660e-01]]

  [[-6.34564972e+00  4.25480747e+00 -4.77108526e+00 -1.41297424e+00
     1.24832749e+00  7.98633766e+00 -1.32453227e+00]
   [-9.32927895e+00 -5.24005127e+00 -5.91356230e+00  2.78045392e+00
    -8.65430069e+00  2.12427878e+00 -3.76458502e+00]
   [-1.08824520e+01  8.33929062e+00  1.99131763e+00 -8.57583237e+00
    -5.73151493e+00 -1.16258192e+01  6.31911659e+00]
   [-5.34061432e+00 -4.32692975e-01 -6.34483624e+00  1.17733121e+00
    -8.99379539e+00 -4.20547915e+00  5.09828138e+00]
   [-8.70369530e+00  2.70313203e-01 -4.75004292e+00 -4.46018076e+00
     1.06978149e+01  7.99377203e-01  4.21018124e+00]]

  [[ 6.93225741e-01 -7.52894306e+00 -2.70724130e+00 -2.41052270e+00
     3.85075760e+00  2.99800658e+00  1.01073837e+00]
   [ 1.33971918e+00 -2.33955908e+00 -2.09251356e+00  6.28121495e-01
    -4.44142282e-01 -6.03814697e+00  1.59254646e+00]
   [-1.43245258e+01  3.60023689e+00  1.03576488e+01  1.25927076e+01
     2.68984079e+00 -1.59330578e+01 -2.45854449e+00]
   [ 1.97565258e-01 -2.64123399e-02 -2.74719596e+00 -1.06130095e+01
     1.04247084e+01 -7.30340862e+00  1.45684090e+01]
   [ 5.05515695e-01 -5.69613552e+00 -6.05650043e+00  6.45315456e+00
     5.09401560e-01  4.83682537e+00  9.13227844e+00]]

  [[-5.69503307e-01  4.17630148e+00  1.07541065e+01  9.32796288e+00
    -1.00617886e+00  5.85444450e+00 -3.17653179e-01]
   [-9.49558449e+00 -8.27042580e+00 -7.91274405e+00 -1.21125908e+01
     9.40961742e+00  1.15582495e+01  5.22339153e+00]
   [-2.64766693e+00 -7.68998861e+00 -2.25702553e+01 -2.48214388e+00
    -1.16524992e+01 -1.31043148e+01  7.63653803e+00]
   [ 3.80448222e-01 -2.20568180e+00  3.38546753e+00 -2.85255909e-02
    -1.26267040e+00 -1.59842215e+01  6.94576168e+00]
   [-4.21129608e+00  6.91624498e+00 -3.16624451e+00 -6.26246834e+00
     2.04357719e+00  7.32974720e+00  5.91998816e+00]]

  [[ 5.51788044e+00 -2.66624308e+00 -1.26638985e+00  5.18488884e-02
    -1.15790081e+01 -4.45472860e+00 -1.00575314e+01]
   [-5.82209587e+00 -9.57922816e-01 -3.30669022e+00  6.85232544e+00
    -3.69593906e+00 -9.35012531e+00 -1.10302763e+01]
   [ 4.34310913e+00 -1.69384241e+00 -6.18307018e+00  8.56124878e+00
     6.56793833e+00  1.01738644e+01  7.73807335e+00]
   [-1.23221207e+00 -6.72510481e+00  2.74285150e+00 -8.57383251e+00
     1.22233200e+00 -3.24314141e+00  5.70223141e+00]
   [-8.92883301e+00  4.51321650e+00  6.51444793e-01 -4.28027439e+00
    -6.38545227e+00 -6.41243029e+00  6.75659537e-01]]]]
case 7
[[[[-2.10093713e+00  4.98893309e+00 -6.26441598e-01 -1.07210076e+00
    -5.21579123e+00  2.86855078e+00 -1.39661300e+00]
   [ 7.41614819e+00 -6.71399593e-01 -4.23780012e+00  1.11327391e+01
     4.96339464e+00  1.38730216e+00  3.11091518e+00]
   [-3.47758293e+00 -1.39673471e-01  7.41272497e+00  4.07157326e+00
     6.54771471e+00 -1.13978148e+00  4.52361202e+00]]

  [[ 1.69025755e+00 -1.09877825e-01 -8.76625919e+00 -5.62741831e-02
     4.10044670e+00  1.50082409e+00  1.73212898e+00]
   [-6.93590879e-01 -1.09598339e-02  2.53287745e+00  5.00034761e+00
    -7.55465889e+00  2.79550409e+00 -6.08131981e+00]
   [ 4.12335110e+00 -1.96592808e-02 -2.29713988e+00 -7.45619869e+00
     1.27773275e+01  6.37109041e+00  2.86503077e+00]]

  [[ 1.30594528e+00 -3.55595398e+00 -4.66912746e+00 -4.53261089e+00
     1.82847989e+00  7.36636591e+00  4.75248480e+00]
   [-4.13020372e-01 -1.03852568e+01 -3.44321895e+00  5.60834122e+00
     5.45825863e+00 -1.80749714e+00  2.97447681e-01]
   [ 7.33989620e+00  3.56130600e-02  7.01800823e+00  6.18812275e+00
    -1.02754993e+01  5.37866402e+00  9.66147661e-01]]]]
case 8
[[[[ -3.2344136    0.64207804  -5.228878    -3.3879392    1.3097423
      5.0851016   -2.0364149 ]
   [ -1.7016228   -3.6748013   -3.7690918   -7.825641     8.82084
      4.5985293   -2.6012535 ]
   [ -0.3385992   -6.4497685   -6.03023     -4.5013723    2.7402868
      1.412247    -2.4262505 ]]

  [[ -3.3440087   -7.554824    -1.6605948   -1.59908     -7.7774415
     -2.0941582   -5.6549153 ]
   [ -1.4017278   -4.752401    -8.959063     8.618719    -4.250363
     -8.620439     4.664977  ]
   [ -8.129705     3.5636168   -1.4718032    1.403153     2.487474
     -5.481632    -7.740856  ]]

  [[ -2.946187     8.871243    -4.869481     1.5493891   -5.2645607
     -2.061664     2.624022  ]
   [ -3.9486473    7.2773557    7.6697707   -0.5786922    8.667782
      2.176832    -6.067088  ]
   [ -0.9954526    5.250826    -3.6364436    2.9926648    4.5894985
     -4.583601     0.25069022]]]


 [[[  0.85603225   1.0853565    1.2121092    1.7286056   -5.174011
     13.675236    -4.459283  ]
   [ -0.11594194  -4.1085887   -1.9521186    1.5099523   -0.30228236
     -0.9824225    1.8969318 ]
   [ -3.751532    -0.3406757   -4.9325395   -2.6590052    1.9695889
      6.972105    -1.122458  ]]

  [[ -6.2014194    5.049401    -0.6305958   -2.3439991    4.789456
      7.9238944  -10.5403595 ]
   [  3.3497243    5.6917386   -7.1880684   -6.441324    -2.067538
      4.8397045   10.5511675 ]
   [ -4.325942    -3.491756    -3.963093    -7.3288536    5.808484
      6.125862    -4.5315003 ]]

  [[ -6.448899    -2.1745038    1.2923504   -1.3635528  -12.082916
      3.4292026    3.0958836 ]
   [  0.8231801   -5.196327     0.3445263    0.7378049   -7.1310124
      4.193355     9.42897   ]
   [ -2.3982868    1.6707518    1.127842     0.11248124   3.975556
     -2.0966659   -5.1623526 ]]]


 [[[ -5.6770215   10.089402    -6.2594285   -6.2449718    0.1622923
      8.061353     4.307845  ]
   [ -6.4901185   -0.5611969    2.7403448   -5.3256717    4.7149353
      5.2395606   14.784617  ]
   [ -1.863451     5.9677906   -5.3635783   -3.5850034   -0.532403
      4.4619136   -0.35180956]]

  [[  0.6453708    2.5313597    4.18169     -6.739621    -1.5522428
      7.185923    -0.3274749 ]
   [ -0.0806005   12.551996    -7.239109    -4.919097    -7.562483
      2.356782     7.411401  ]
   [ -3.7317688   -5.3026333   -0.42991507  11.678181    -6.7638154
     -0.53147364  11.965349  ]]

  [[ -1.9813595    6.018738    -0.9850279   -0.2662683   -6.3888426
     -4.1675663    4.8931403 ]
   [ -1.3834362    1.7205615   -1.2530259    4.010069    10.695443
     -6.395365   -11.751938  ]
   [  6.2339115    0.3074224   -0.26036483  -3.904868     0.2733295
      0.9317256    5.006288  ]]]


 [[[ -6.489089     4.271571    -2.4752238   -7.164964     2.0262854
      5.0454793   -8.580285  ]
   [  5.012365    -5.201222    -0.46605015   1.8581799    3.5171306
     -0.7544764    0.59329945]
   [  3.4007866   -5.8264604   -0.60395956  -1.8801146    0.36537772
      2.3627386   -9.558525  ]]

  [[ -4.133124     1.973596    -0.6346631   -2.1765368   -2.6556668
      2.4713001   -2.218635  ]
   [ -7.31272     -1.3075228    8.689704     6.5874267   -6.1276484
     -2.8076982    4.7880507 ]
   [ -0.20493901  -9.929913    -0.08529186   3.082413     2.5240417
    -10.149891    -4.0589504 ]]

  [[  2.195657    -4.3548865    2.7764163    6.6121697   -0.57440627
     -1.0914559   -0.8398527 ]
   [ -4.606847    -7.3435516   12.242287     0.26114607   0.573243
      9.095609    -1.5837816 ]
   [ -2.0314841    4.659019    -1.5979042    1.1739359    5.1365247
     -0.54066014   3.454946  ]]]


 [[[  2.400903     0.14181256   2.9847927    4.8036566    5.924637
     -1.854919     3.586135  ]
   [  0.02162606   1.2999141  -13.966853     5.0090322    1.5231879
     -3.9198272    0.3963855 ]
   [ -6.581806     8.599427     1.4005799  -10.043644   -10.756417
      7.926515    -4.398179  ]]

  [[  2.4634216   -8.820907     8.038887    -6.460607     2.2686412
      2.515935     1.7255648 ]
   [ 12.979544    -9.799437     1.810264    -0.12505686   4.2813277
      5.5351977   -3.0261588 ]
   [ -1.9932687    3.9752626   -6.921649    -9.239646     3.0680888
     -1.8291612  -11.735243  ]]

  [[ -4.3252125    3.0223765    1.1795907   -5.929388    -3.675373
     -3.6191235    7.5196033 ]
   [ -3.280699    -2.5691557   -1.1214452    7.998667    -6.8519554
     -2.5074492    1.3729379 ]
   [ -4.5146856   -7.567935    -3.1870115   -1.6540992   -1.4916413
    -10.883092    -2.624516  ]]]


 [[[ -2.7739341   -9.778795     9.7363405    5.746692    -2.3952553
      3.7842293    7.104442  ]
   [  2.3882189   -5.691002     6.8133245   14.67627     -1.4746639
     -7.236193     2.5920546 ]
   [  1.8653235   -2.9795146    1.3272736    8.978571     5.563953
     -1.2351213   -3.8598847 ]]

  [[  5.4080763    6.46615     -4.113893    -2.8730063    8.743852
      5.5723925    1.6011627 ]
   [-12.144636    11.879005     2.3996239  -10.33647     -1.9105867
     12.786247    -8.664574  ]
   [ -0.5204694   14.625885     3.2142694    4.690938     4.708466
      7.817709     7.3966427 ]]

  [[ -8.729477    -6.1842976   -2.3811848    1.3564312   -3.3171365
     -5.4014273    0.12106967]
   [ -1.2586226   -7.7833066   -1.4832672    1.0455589    0.10661709
      5.7798767   -3.9407158 ]
   [ -1.806744    -5.3785415   -2.3400514    0.34966922  -5.179815
      7.328074     0.04769278]]]


 [[[ -1.8242321    6.7109203    4.7603674   -0.5507413   -1.7882011
      0.06898683   0.31602967]
   [ -1.3883777   11.542858     1.1110207    0.03759412   4.532738
     -0.457775     1.7317785 ]
   [ -2.9914274    4.6539936    5.225711    -0.13895082   8.409312
      0.40692008  -0.45492685]]

  [[ -5.9488225   -5.421607    -2.1813345    6.135817    -5.7512555
     -5.2943935    6.4044976 ]
   [  2.3153205   -9.993226    -1.5110209    0.84325033   0.10096272
    -10.454711     2.8849607 ]
   [ -5.7634687    2.3282714    0.98458385   0.12003112   3.738848
     -2.2919297   -8.709163  ]]

  [[  8.348087    11.821417     0.5500164    0.67266464   2.3070486
      2.2559838    3.0402064 ]
   [ -1.0286527    7.570553    -3.763043     0.45718098  -0.14165545
     -5.401314     2.269547  ]
   [  0.4104256   -3.7541127   -3.3451502    5.4800773    1.463095
     -1.2300699    0.28131425]]]


 [[[  1.8354499    3.6835968    2.5264082   -0.9579525    0.7386626
     -1.9215393    1.2621138 ]
   [ -4.6329813    1.3856003    5.9691358    7.602398    -8.066732
      3.0141196    8.390305  ]
   [  1.6005659    2.0445485    1.3437636    6.40588      1.3964472
      3.5835958    0.9014745 ]]

  [[  3.4012876   12.222017     8.284241     1.1252376    8.186215
      6.0700374   -2.3145843 ]
   [  0.97003514  14.399776    11.005349     6.920521    -1.0725622
     10.866078     6.6982374 ]
   [  8.559503    -2.0125332    3.7856739    2.710576    -8.287237
      4.177312     3.4927533 ]]

  [[ -6.199666   -10.097167    -2.3627596    5.7756267    2.8862982
     -0.76808995  -3.1500194 ]
   [  0.94575214 -21.02441      0.36362886  -2.415611    -4.4020786
     -2.6168022   -2.362568  ]
   [  7.4888635   -5.612376     0.93246365   3.5139668   -1.0576949
      0.7625966   -0.3357528 ]]]


 [[[ -4.6344266   -5.1529984    1.7113249    2.5765207    2.8565693
      6.760303    -4.772575  ]
   [ -4.6257014   -1.2307287   -5.9155264  -12.604766    -0.06021017
     14.431656     6.2952046 ]
   [ -2.3020258    3.4944258    0.49227977   0.12145138  -4.6246567
      8.118302     7.7252493 ]]

  [[ -3.696188   -12.861532    -6.982583    -0.8176162   -5.156015
      7.549295     3.4717333 ]
   [ -5.607452     5.74459     -9.292033    -6.943613     3.7520685
     13.39387     -2.4626062 ]
   [  6.461771     1.587949    -1.5410843   -6.111145     3.4886866
     10.9821005    1.3381654 ]]

  [[ -0.535506     1.6735315   -4.67325     -2.564756     5.012389
     -1.5498025    2.6458597 ]
   [ -4.3485823    3.1670754    0.22036311   1.6818397   -3.1564019
     -0.27644897   3.3108091 ]
   [ -6.9335175    9.952805     1.7686601   -2.664827    -3.9951215
     -2.587521     3.3849297 ]]]


 [[[ -6.8305893    1.5694251    9.411676    -2.1737275    0.6265733
      8.715221     3.8530846 ]
   [  7.2923837    0.9728274   -0.5580957    8.940796     6.1430826
      1.2102466    4.733224  ]
   [  0.1484863   -1.5600936   -1.2597893   -2.6476843   -5.276054
      0.9749373  -13.404699  ]]

  [[  1.509584    -4.520794     7.053476     5.7554717   -3.0075967
      4.4735866    8.437726  ]
   [  3.8938088    3.1715872   -5.0368886   -0.5782852   -4.7868295
      1.9100766   -7.5721064 ]
   [ -2.5621645    4.977721     2.0836809    9.4655      -5.4399843
     -6.1441708    1.5558908 ]]

  [[  8.823681   -15.228354     3.2260053   -1.5408076   -5.2849383
     -1.0936816    2.4890208 ]
   [  2.6916695    4.988661    -3.9675586   -0.973806    10.006417
      5.8663125  -12.677763  ]
   [  7.894119     4.9990516   -2.8276594   -8.839343    -3.6165826
      6.438372     3.9829328 ]]]]

原文: http://www.cnblogs.com/welhzh/p/6607581.html

标签: Tersorflow CNN


评论: