定义
tf.nn.conv2d (input, filter, strides, padding, use_cudnn_on_gpu=None, data_format=None, name=None)
- input: 输入的要做卷积的图片,要求为一个张量,shape为 [ batch, in_height, in_weight, in_channel ],其中batch为图片的数量,in_height 为图片高度,in_weight 为图片宽度,in_channel 为图片的通道数,灰度图该值为1,彩色图为3。
- filter:卷积核,要求也是一个张量,shape为 [ filter_height, filter_weight, in_channel, out_channels ],其中 filter_height 为卷积核高度,filter_weight 为卷积核宽度,in_channel 是图像通道数 ,和 input 的 in_channel 要保持一致,out_channel 是卷积核数量。
- stride:卷积时在图像每一维的步长,这是一个一维的向量,[ 1, strides, strides, 1],第一位和最后一位固定必须是1
- padding:string类型,值为“SAME” 和 “VALID”,表示的是卷积的形式,是否考虑边界。”SAME”是考虑边界,不足的时候用0去填充周围,”VALID”则不考虑
即为:
SAME:卷积核可以停留在图像边缘,即,宽度为Image_weight / stride + 1
VALID : 卷积核不可以停留在图像边缘,宽度为(Image_weight – filter_weight)/stride +1 - use_cudnn_on_gpu: bool类型,是否使用cudnn加速,默认为true
举例
import tensorflow as tf
------------------------------------------------------------------------------------------------------
# case 1
# 输入是1张 3*3 大小的图片,图像通道数是5,卷积核是 1*1 大小,数量是1
# 步长是[1,1,1,1]最后得到一个 3*3 的feature map
# 1张图最后输出就是一个 shape为[1,3,3,1] 的张量
input = tf.Variable(tf.random_normal([1,3,3,5]))
filter = tf.Variable(tf.random_normal([1,1,5,1]))
op1 = tf.nn.conv2d(input, filter, strides=[1,1,1,1], padding='SAME')
#输出
******************** op1 ********************
[[[[ 0.78366613]
[-0.11703026]
[ 3.533338 ]]
[[ 3.4455981 ]
[-2.40102 ]
[-1.3336506 ]]
[[ 1.9816184 ]
[-3.3166158 ]
[ 2.0968733 ]]]]
-------------------------------------------------------------------------------------------------
# case 2
# 输入是1张 3*3 大小的图片,图像通道数是5,卷积核是 2*2 大小,数量是1
# 步长是[1,1,1,1]最后得到一个 3*3 的feature map
# 1张图最后输出就是一个 shape为[1,3,3,1] 的张量
input = tf.Variable(tf.random_normal([1,3,3,5]))
filter = tf.Variable(tf.random_normal([2,2,5,1]))
op2 = tf.nn.conv2d(input, filter, strides=[1,1,1,1], padding='SAME')
#输出
******************** op2********************
[[[[ 1.9288185]
[-3.872772 ]
[ 1.1486561]]
[[-1.6453924]
[ 1.9384439]
[ 1.5341384]]
[[-0.6960499]
[ 3.108924 ]
[ 0.6097143]]]]
-------------------------------------------------------------------------------------------------
# case 3
# 输入是1张 3*3 大小的图片,图像通道数是5,卷积核是 1*1 大小,数量是1
# 步长是[1,1,1,1]最后得到一个 3*3 的feature map (不考虑边界)
# 1张图最后输出就是一个 shape为[1,3,3,1] 的张量
input = tf.Variable(tf.random_normal([1,3,3,5]))
filter = tf.Variable(tf.random_normal([1,1,5,1]))
op3 = tf.nn.conv2d(input, filter, strides=[1, 1, 1, 1], padding='VALID')
#输出
******************** op3********************
[[[[ 1.6719851 ]
[-0.38163936]
[-0.13288862]]
[[-0.11872166]
[-0.05304074]
[ 1.8199785 ]]
[[ 1.5945687 ]
[-0.38205272]
[ 0.28184414]]]]
-------------------------------------------------------------------------------------------------
# case 4
# 输入是1张 5*5 大小的图片,图像通道数是5,卷积核是 3*3 大小,数量是1
# 步长是[1,1,1,1]最后得到一个 3*3 的feature map (不考虑边界)
# 1张图最后输出就是一个 shape为[1,3,3,1] 的张量
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')
#输出
******************** op4********************
[[[[ 4.93663 ]
[11.300637 ]
[-4.7170043 ]]
[[ 4.4999595 ]
[ 3.7627645 ]
[ 7.033349 ]]
[[ 5.1601 ]
[ 1.9807271 ]
[-0.28120422]]]]
-------------------------------------------------------------------------------------------------
# case 5
# 输入是1张 5*5 大小的图片,图像通道数是5,卷积核是 3*3 大小,数量是1
# 步长是[1,1,1,1]最后得到一个 5*5 的feature map (考虑边界)
# 1张图最后输出就是一个 shape为[1,5,5,1] 的张量
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')
#输出
******************** op5********************
[[[[ 0.615875 ]
[ 2.6127 ]
[ -3.2841504 ]
[ 9.918146 ]
[ -2.5437124 ]]
[[-11.686163 ]
[ -2.0402982 ]
[ -1.4028796 ]
[ -3.1973681 ]
[ 9.569347 ]]
[[ -3.488454 ]
[ 11.750545 ]
[ -5.4785585 ]
[ -5.6196046 ]
[ -5.6271753 ]]
[[ 0.06084216]
[ 4.0636263 ]
[ -0.11393895]
[ 2.4829671 ]
[ 1.6683083 ]]
[[ 6.3058996 ]
[ 1.3491695 ]
[ -0.10401154]
[ 5.943573 ]
[ -2.1095133 ]]]]
-------------------------------------------------------------------------------------------------
# case 6
# 输入是1张 5*5 大小的图片,图像通道数是5,卷积核是 3*3 大小,数量是7
# 步长是[1,1,1,1]最后得到一个 5*5 的feature map (考虑边界)
# 1张图最后输出就是一个 shape为[1,5,5,7] 的张量
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')
#输出
******************** op6********************
[[[[ 3.0887563 -8.757811 -1.9566984 -3.3707764 1.4573003
-2.9470344 4.2769175 ]
[ 6.8355904 -2.8316915 4.151598 -1.9893703 4.5343633
-1.7455567 2.3923404 ]
[ -0.5796106 -8.3059025 2.6339238 -0.407861 4.038948
-0.73221153 5.5349445 ]
[ 1.0038129 -0.23307621 8.721055 -8.745911 -1.0426689
2.7741075 5.2638793 ]
[ -3.619012 9.038741 3.6280208 2.6974936 1.7085941
0.25397038 -3.354182 ]]
[[ 3.2160585 -4.840355 3.6852489 -12.032576 -9.674893
-6.2895727 -4.815977 ]
[ 1.4725536 -4.2549667 -3.4826493 -8.04364 0.25006047
7.7094593 0.86553353]
[ 11.234627 6.4976263 -1.7011687 -1.9686639 -5.7297363
1.469283 5.1969666 ]
[ -1.0064669 11.335008 5.2906194 1.5887578 2.5739172
-6.681587 -10.565671 ]
[ 12.442774 2.3762116 -0.6160493 6.727649 -0.5381024
5.1488156 4.6439753 ]]
[[-15.513361 -2.3790777 -1.9252743 2.2043197 -1.4400063
0.75842166 -10.506536 ]
[ 4.564708 -0.4744407 7.4912853 14.069539 11.6688595
-4.612417 5.4330025 ]
[-11.14007 2.9735382 -0.4313957 -4.6811137 -11.4551
-3.5916057 0.4944711 ]
[ -3.8912075 -3.9660525 0.91355586 -1.3563845 -1.2875407
7.572529 -1.4311553 ]
[ 8.351269 0.19171536 -6.96131 1.5982566 0.5016942
2.9076457 -0.18807316]]
[[ 4.8925915 -5.543425 -0.68927133 -7.493097 -7.4924517
-7.3695526 12.963789 ]
[ 10.933542 11.5189495 -1.674472 1.5411812 14.764674
-7.282252 -5.4992485 ]
[ 0.05787128 -4.8447866 6.0995793 -2.130572 4.788317
4.4105816 -0.76676995]
[ 2.4877496 -9.822114 1.5490786 -11.292644 -6.0652895
-5.461935 10.499823 ]
[ 1.1236672 7.7374783 11.541739 0.2169593 -1.80403
-0.37783074 7.946163 ]]
[[ -4.1483784 3.2257776 6.348017 -2.6234756 -0.872122
-5.1639204 -1.8608298 ]
[ 5.9412355 -5.605309 -7.8225245 -3.0232863 -4.3902245
-1.4678087 -2.756116 ]
[ -0.5923271 -0.6401453 -0.51332414 -2.9427621 -4.3485436
5.7885294 5.46108 ]
[ -3.3316593 5.2753196 2.0999293 -16.171337 1.4345255
-0.9159676 -3.196972 ]
[ 7.209021 3.3031735 -0.87703556 -2.6866136 0.5111834
6.312125 4.067911 ]]]]
-------------------------------------------------------------------------------------------------
# case 7
# 输入是1张 5*5 大小的图片,图像通道数是5,卷积核是 3*3 大小,数量是7
# 步长是[1,2,2,1]最后得到7个 3*3 的feature map (考虑边界)
# 1张图最后输出就是一个 shape为[1,3,3,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')
#输出
******************** op7********************
[[[[ -7.560372 2.0237 -4.8913746 -0.6458702 1.9221705
-4.1618495 -5.0541553 ]
[ -3.027947 6.132785 -1.4402869 -4.5081306 -1.0875907
5.2696166 4.588485 ]
[ 4.8169804 1.6802535 3.742131 0.92543554 3.933595
7.609642 2.3418703 ]]
[[ 4.678027 -10.652521 3.671758 1.9559444 4.3873854
0.69699585 6.387135 ]
[ 4.6600924 -0.90035415 9.562813 -4.2748165 5.088637
-6.6742654 4.0188 ]
[ -4.3796535 7.632821 -6.2888837 1.8178465 -2.6003487
0.8694892 2.5623817 ]]
[[ 2.830203 1.5999559 -3.041421 -6.4916563 0.24484622
0.8900788 -0.68253803]
[ 0.5634527 0.4465307 -1.8369514 4.977104 -0.6233926
6.5963316 7.077495 ]
[ -4.4429035 1.1985601 9.393924 3.1787338 2.5441146
1.5674452 -2.6049848 ]]]]
-------------------------------------------------------------------------------------------------
# case 8
# 输入是10 张 5*5 大小的图片,图像通道数是5,卷积核是 3*3 大小,数量是7
# 步长是[1,2,2,1]最后每张图得到7个 3*3 的feature map (考虑边界)
# 10张图最后输出就是一个 shape为[10,3,3,7] 的张量
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')
[[[[ 3.81172585e+00 -6.58235610e-01 9.39655185e-01 -1.12831044e+00
-1.44241846e+00 -1.69457889e+00 4.36120272e+00]
[ 2.00121582e-01 -5.16375589e+00 1.22973609e+00 9.44681168e+00
-1.00510824e+00 -2.68596339e+00 5.99930286e+00]
[ 7.93656158e+00 -5.48158646e+00 -1.03805804e+00 -2.67814904e-01
1.19332771e+01 -7.91494846e+00 5.40462017e-01]]
[[ 6.18537784e-01 1.22472506e+01 4.73466825e+00 2.60108924e+00
-2.27779555e+00 -1.39395344e+00 9.39258754e-01]
[ 2.11174369e-01 -1.11202860e+01 1.15606651e+01 -2.10358667e+00
-1.91229045e+00 4.73274112e-01 -8.28661203e-01]
[-1.73816741e+00 -9.91873860e-01 -1.29899430e+00 3.11782837e+00
-5.76431704e+00 -4.64563322e+00 -6.76457500e+00]]
[[-3.78995442e+00 -6.68081284e-01 2.67540932e+00 1.45131636e+01
-5.45289516e+00 -7.98859119e-01 2.98502207e+00]
[-4.60981560e+00 -2.43963814e+00 -2.20421195e-01 1.00090513e+01
3.96379256e+00 -1.85508728e-01 -8.32319832e+00]
[-5.96280575e+00 -5.27051866e-01 -3.18238068e+00 -5.42228127e+00
-4.69559002e+00 8.09168816e-02 1.91771030e+00]]]
[[[ 1.53048587e+00 3.10868233e-01 4.89992142e+00 1.96467185e+00
6.57781363e-02 4.64759827e+00 -3.45945859e+00]
[ 7.76488018e+00 -3.91228616e-01 -5.22320509e-01 -1.11246891e+01
4.06208277e+00 -3.44819212e+00 -7.47523904e-01]
[ 5.63401508e+00 -4.41431141e+00 -9.00770283e+00 -4.24449444e-01
-6.22014999e+00 2.03636217e+00 -9.96613204e-01]]
[[-5.48789918e-01 5.95879555e+00 1.20323877e+01 1.08595169e+00
-4.32021350e-01 -3.60252470e-01 1.51402450e+00]
[-2.18106341e+00 1.20968828e+01 -1.47913229e+00 -6.29183245e+00
-1.08375347e+00 7.86020947e+00 -2.51888847e+00]
[-3.51060534e+00 -7.77409649e+00 -3.00079918e+00 4.92167711e-01
-9.36036873e+00 9.77025986e-01 -4.88964081e+00]]
[[ 7.76729643e-01 1.08929138e+01 5.02641439e-01 -3.69875813e+00
-2.96155214e+00 8.67065811e+00 7.10426807e-01]
[ 5.79438925e+00 7.40104389e+00 -1.15843797e+00 -1.13216896e+01
-8.39748192e+00 3.47570372e+00 7.48564816e+00]
[-1.20307946e+00 -2.13643742e+00 5.40993786e+00 -1.48298454e+00
-4.71552181e+00 9.79691207e-01 -9.91011858e-01]]]
[[[ 2.50824261e+00 -2.84440899e+00 1.71533370e+00 7.51872396e+00
-1.03872118e+01 -1.40590143e+00 7.93499374e+00]
[ 7.06769943e-01 4.55543947e+00 -1.12701893e-01 -1.74570131e+00
7.37167931e+00 -6.60094738e+00 1.18070545e+01]
[-3.77333736e+00 -6.92615986e+00 1.58949256e+00 8.52469063e+00
-3.17621326e+00 4.55142117e+00 1.86487818e+00]]
[[ 2.62441111e+00 1.51057935e+00 -1.69782043e+00 -1.06731892e+01
9.10656643e+00 -1.90770149e+00 -3.25653982e+00]
[ 1.25612850e+01 2.38117480e+00 -4.60387325e+00 1.23946321e+00
-6.48248291e+00 8.82726860e+00 1.96533287e+00]
[ 5.56728244e-01 -2.70045996e+00 9.12153625e+00 -7.64613342e+00
7.03843832e+00 1.47829437e+00 -1.13098145e+00]]
[[-2.29912233e+00 4.13240147e+00 6.55635834e-01 1.01796589e+01
-2.68077517e+00 -2.44472027e+00 3.18214369e+00]
[ 7.21115589e+00 3.16968679e+00 1.12844181e+01 -3.52053165e+00
-4.21286821e-02 -4.63994265e-01 7.78382206e+00]
[ 3.35062027e-01 1.86070824e+00 4.23208809e+00 -1.28888645e+01
2.51626110e+00 -7.29913950e-01 4.48049974e+00]]]
[[[-2.28839159e+00 -1.83935964e+00 4.67500973e+00 -8.66911113e-01
7.57640362e+00 -4.49133158e+00 -3.58713269e+00]
[-2.56349277e+00 1.65234530e+00 -3.40921402e+00 -3.57537770e+00
-1.12090588e+00 -4.00662136e+00 -2.31218624e+00]
[-1.59960270e+00 -1.02549422e+00 1.70352447e+00 -5.07849455e-02
5.91472030e-01 -6.75261378e-01 -2.98815727e+00]]
[[-4.95550632e+00 -1.59211278e+00 2.85315514e+00 -3.60998213e-01
1.10690346e+01 -2.92121983e+00 -8.75728607e+00]
[ 1.04558921e+00 -1.10802925e+00 2.20073867e+00 6.86034966e+00
-8.90627098e+00 -8.71938992e+00 -4.64016318e-01]
[ 6.93283558e+00 -7.52256966e+00 2.89755774e+00 -1.97585964e+00
1.34779205e+01 -7.09957218e+00 2.72134781e+00]]
[[-9.07215500e+00 7.41471624e+00 5.28336763e+00 -4.50483036e+00
8.20894718e-01 5.68455124e+00 -2.32907462e+00]
[ 2.75068545e+00 9.57029152e+00 -3.07973957e+00 -3.78625989e+00
-8.29107571e+00 3.85373855e+00 1.01118898e+00]
[ 6.30977154e-02 4.62665367e+00 -4.43314362e+00 1.64909089e+00
-2.61656308e+00 2.18150091e+00 -1.97284305e+00]]]
[[[-4.68610287e+00 4.63123989e+00 1.93239570e+00 -6.24144125e+00
-2.12857890e+00 7.83749342e+00 3.71262431e+00]
[-5.97846508e-01 -4.51939315e-01 4.12002516e+00 -1.59932184e+00
-1.24146347e+01 -3.81853724e+00 6.19719982e+00]
[ 5.69620705e+00 1.17846155e+00 -3.76912522e+00 -2.78199720e+00
-4.14124632e+00 -8.70480537e-01 7.28857422e+00]]
[[ 6.51047325e+00 -9.75043869e+00 -7.16108227e+00 3.37941360e+00
1.78760872e+01 -1.79757142e+00 -9.61674118e+00]
[ 6.94279099e+00 -2.50615239e+00 5.16652727e+00 -9.33402729e+00
7.53117752e+00 -4.19789219e+00 -1.47018957e+00]
[ 6.32885885e+00 3.85915112e+00 5.42673349e-01 -5.80658555e-01
-1.97605848e-01 -1.72271812e+00 -5.95912266e+00]]
[[-3.86114836e+00 1.97221160e-01 -3.30170727e+00 -3.46406794e+00
3.63580871e+00 9.82056856e-01 -1.79573965e+00]
[-4.00891447e+00 8.22873688e+00 8.06672668e+00 -4.28653002e+00
-5.32858133e+00 9.43519115e+00 -3.52467918e+00]
[-4.78855515e+00 5.19511986e+00 -4.68266487e+00 1.17632685e+01
-4.77883863e+00 -1.88284159e-01 -5.56722975e+00]]]
[[[ 1.89772367e-01 3.16071630e-01 3.13395715e+00 3.01754177e-01
4.14337683e+00 -6.85967159e+00 2.19734955e+00]
[-9.88918841e-01 3.14887810e+00 -3.53439212e+00 -2.68401289e+00
-4.27296972e+00 3.57035112e+00 4.22077084e+00]
[ 3.00699210e+00 3.36317134e+00 -9.01305914e-01 -8.24847412e+00
5.16212940e-01 4.10071039e+00 8.48048019e+00]]
[[ 5.30344546e-01 8.90641308e+00 -5.22371292e+00 -9.62609529e-01
-8.23948574e+00 1.11528502e+01 4.19720745e+00]
[ 5.41305363e-01 7.66341686e+00 8.16087127e-01 -1.69427891e+01
-9.43431139e-01 3.76207352e+00 2.09374666e+00]
[-1.97999740e+00 -1.78795707e+00 1.24396682e+00 -5.56382322e+00
-7.98738337e+00 5.25424480e+00 -2.88212180e+00]]
[[ 1.11028862e+01 -9.86741066e+00 -2.52228451e+00 1.31483240e+01
-1.80064118e+00 -4.19618654e+00 4.12672377e+00]
[-2.38205004e+00 3.45358086e+00 3.06554794e+00 1.39153457e+00
1.74696178e+01 -9.50703239e+00 -7.38960409e+00]
[ 1.88154280e-02 6.71151447e+00 7.40723515e+00 -6.85136318e-01
-2.66253185e+00 1.28768826e+00 -1.88888133e+00]]]
[[[-1.81933379e+00 7.67806411e-01 -3.73196530e+00 1.59054911e+00
-3.48422110e-01 9.18928087e-01 -5.09416533e+00]
[-7.46384335e+00 9.51658821e+00 2.05104017e+00 4.65793419e+00
-7.38202190e+00 -3.89330769e+00 1.22091656e+01]
[-6.46189404e+00 -2.52824783e-01 -2.53815079e+00 2.52569151e+00
2.53525639e+00 1.75139821e+00 1.39415288e+00]]
[[-5.36459589e+00 -7.83692455e+00 4.92164993e+00 -1.64086747e+00
3.42228937e+00 -1.28203106e+00 -6.44423771e+00]
[ 6.13428068e+00 2.02679372e+00 -8.31424177e-01 -1.11501341e+01
-6.76840162e+00 8.00881684e-01 8.87121487e+00]
[-3.81009316e+00 -1.20232134e+01 1.93391097e+00 4.11974144e+00
-1.14694452e+00 3.36693192e+00 -3.51179051e+00]]
[[-4.13361931e+00 2.33749223e+00 1.10010195e+01 -3.48916125e+00
9.83463669e+00 1.14318848e-01 -1.02951355e+01]
[-2.07277107e+00 4.58487415e+00 -2.85462832e+00 9.62093830e-01
-1.10009775e+01 2.91307449e-01 -2.71501541e-02]
[ 1.35933065e+00 2.23298883e+00 -1.53114724e+00 -2.99561787e+00
5.05122375e+00 -4.47726011e-01 -1.30996180e+00]]]
[[[-2.30837297e+00 2.31148410e+00 1.62851739e+00 -7.04085350e+00
1.48006344e+00 -8.36053848e-01 -2.05071878e+00]
[-1.38948321e+00 -1.79432559e+00 1.66157138e+00 2.52863026e+00
-7.40308714e+00 -1.66243482e+00 -4.31997442e+00]
[ 4.34525728e-01 -4.86747551e+00 2.63057780e+00 -7.23891139e-01
1.20453250e+00 -3.09287119e+00 1.81485105e+00]]
[[-4.34996891e+00 6.45046651e-01 2.17182612e+00 3.30334997e+00
4.39480066e+00 2.21359074e-01 -9.40736866e+00]
[ 1.32711506e+00 1.82248173e+01 -3.49929571e+00 -7.32633162e+00
-6.05510807e+00 4.97397137e+00 -6.42782402e+00]
[-4.16941261e+00 4.90973854e+00 7.69643211e+00 -2.56850910e+00
-1.23103590e+01 3.96808362e+00 3.48330426e+00]]
[[-1.41771734e+00 3.80652380e+00 6.81313419e+00 3.99951291e+00
-4.59768105e+00 -2.67537093e+00 3.28954649e+00]
[ 3.44624519e-02 3.46278954e+00 -7.19838619e-01 -7.18024731e+00
4.72416639e+00 -8.42012405e+00 1.02093210e+01]
[ 1.77111924e+00 1.76189995e+00 -4.04496670e+00 -8.58612251e+00
-4.48928452e+00 1.99987328e+00 2.11980033e+00]]]
[[[ 5.16344547e+00 -3.28772712e+00 2.55633926e+00 -1.51607990e-02
-4.33142781e-01 -6.92938566e+00 3.01811099e+00]
[ 4.50596237e+00 -2.95426488e+00 6.79820490e+00 6.90650177e+00
1.18538189e+00 -2.41478145e-01 5.52644825e+00]
[-3.45425940e+00 -1.01008582e+00 2.75584054e+00 4.67782021e+00
4.02924681e+00 -3.02245331e+00 -2.42830753e+00]]
[[-1.24309397e+00 2.25454855e+00 -4.99355435e-01 -4.18008947e+00
-3.40147209e+00 3.88633633e+00 -1.01025581e+00]
[ 8.36562634e+00 5.56176138e+00 -3.90685773e+00 -1.72424483e+00
2.73722672e+00 8.00842190e+00 -2.48433948e+00]
[-4.46336555e+00 -3.72679162e+00 -1.26352954e+00 4.95191813e+00
-3.23514009e+00 7.82737851e-01 -7.65897846e+00]]
[[-3.07640934e+00 1.11932468e+00 -2.62503529e+00 -1.19850216e+01
-8.01890469e+00 1.48621440e+00 3.36904168e+00]
[ 3.82285118e-01 2.76505685e+00 1.05706239e+00 -7.88955784e+00
-4.90172768e+00 1.72243714e+00 2.69844866e+00]
[-9.21259785e+00 -3.33890224e+00 5.46678066e+00 -1.62324953e+00
-6.74576473e+00 9.93959785e-01 4.94233227e+00]]]
[[[-4.70427895e+00 3.07578850e+00 1.34436083e+00 6.60757589e+00
6.15761566e+00 1.20834816e+00 -1.43940473e+00]
[-2.02920246e+00 9.61333084e+00 -5.87510967e+00 4.66540051e+00
-2.92267442e-01 -1.75225294e+00 3.57326508e+00]
[ 1.95737648e+00 -1.88611352e+00 -1.09006286e+00 -4.27253246e+00
-2.21520901e-01 9.55001116e-02 2.74844027e+00]]
[[-6.32184601e+00 -5.88555717e+00 -5.94709516e-01 -4.42621136e+00
-1.81127739e+00 1.04070306e-01 8.58660412e+00]
[ 8.64363861e+00 -1.60207062e+01 -1.36644773e+01 1.04534721e+01
2.78887987e+00 9.04768276e+00 -7.40338182e+00]
[ 7.05552197e+00 -4.00396538e+00 3.59226894e+00 -5.75797653e+00
7.61316681e+00 -8.67320824e+00 -8.12954044e+00]]
[[ 1.18172336e+00 8.86805296e-01 1.63558555e+00 4.20765400e+00
4.41581488e+00 -4.85230350e+00 -7.42733288e+00]
[ 4.40815359e-01 -4.11654329e+00 -2.52238703e+00 3.83199716e+00
3.61510658e+00 -5.21432638e+00 6.40418005e+00]
[-1.39663115e+01 5.36948872e+00 1.69813246e-01 5.84380329e-01
-2.94225430e+00 1.31688917e+00 -1.10627632e+01]]]]
#输出
******************** op8********************
-------------------------------------------------------------------------------------------------
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
print('*' * 20 + ' op1 ' + '*' * 20)
print(sess.run(op1))
print('*' * 20 + ' op2 ' + '*' * 20)
print(sess.run(op2))
print('*' * 20 + ' op3 ' + '*' * 20)
print(sess.run(op3))
print('*' * 20 + ' op4 ' + '*' * 20)
print(sess.run(op4))
print('*' * 20 + ' op5 ' + '*' * 20)
print(sess.run(op5))
print('*' * 20 + ' op6 ' + '*' * 20)
print(sess.run(op6))
print('*' * 20 + ' op7 ' + '*' * 20)
print(sess.run(op7))
print('*' * 20 + ' op8 ' + '*' * 20)
print(sess.run(op8))
-------------------------------------------------------------------------------------------------
原文:https://blog.csdn.net/zuolixiangfisher/article/details/80528989