1. 程式人生 > >tensorflow隨筆-tf.nn.conv2d卷積運算(5)

tensorflow隨筆-tf.nn.conv2d卷積運算(5)

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Tue Oct  2 13:23:27 2018

@author: myhaspl
@email:[email protected]
tf.nn.conv2d
"""

import tensorflow as tf

x=range(16)
a = tf.constant(x,dtype=tf.float32,shape=[1,2,4,2])
b = tf.constant([range(8)],dtype=tf.float32,shape=[2,2,2,1])
c =
tf.nn.conv2d(a,b,strides=[1, 1, 1, 1],padding='SAME') with tf.Session() as sess: print "==" print sess.run(a) print "==" print sess.run(b) print "==" print sess.run(c) print "=="

==
[[[[ 0.  1.]
   [ 2.  3.]
   [ 4.  5.]
   [ 6.  7.]]

  [[ 8.  9.]
   [10. 11.]
   [12. 13.]
   [14. 15.]]]]
==
[[[[0.]
   [1.]]

  [[2.]
   [3.]]]


 [[[4.]
   [5.]]

  [[6.]
   [7.]]]]
==
[[[[228.]
   [284.]
   [340.]
   [138.]]

  [[ 62.]
   [ 74.]
   [ 86.]
   [ 15.]]]]
==