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

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

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

@author: myhaspl
@email:[email protected]
"""

import tensorflow as tf

g=tf.Graph()

with g.as_default():
    x=tf.constant([
            [[[1.],[2.]],[[3.],[4.]],[[5.],[6.]]],
            [[[10.],[20.]],[[30.],[40
.]],[[50.],[60.]]] ]) kernel=tf.constant([[[[2.]]]]) y=tf.nn.conv2d(x,kernel,strides=[1,1,1,1],padding="SAME") with tf.Session(graph=g) as sess: print x.get_shape() print sess.run(y)
(2, 3, 2, 1)
[[[[  2.]
   [  4.]]

  [[  6.]
   [  8.]]

  [[ 10.]
   [ 12.]]]


 [[[ 20.]
   [ 40.]]

  [[ 60.]
   [ 80.]]

  [[100.]
   [120.]]]]