您的位置:首页 > 其它

tf.nn.conv2d用法简介

2017-12-12 15:50 609 查看


tf.nn.conv2d(1.3.0版本)



#-*- coding:utf-8 -*-
import numpy as np
import tensorflow as tf

# 生成大小为[1,5,5,3]的输入图像
batch = 1
in_height = in_width = 5
in_channels = 3
input = tf.constant(1.0, shape=[batch, in_height, in_width, in_channels])

# 生成大小为[3,3,3,1]的卷积核
filter_width = filter_height = 3
filter = tf.constant(1.0, shape=[filter_width, filter_height, in_channels, 1])

# 卷积运算
output1 = tf.nn.conv2d(input, filter, strides=[1,2,2,1], padding="SAME", name="conv1")
output2 = tf.nn.conv2d(input, filter, strides=[1,2,2,1], padding="VALID", name="conv2")

# 显示输出图像尺寸
print("output1: %s" %np.shape(output1))
print("output2: %s" %np.shape(output2))

# 输出结果
output1: (1, 3, 3, 1)
output2: (1, 2, 2, 1)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  tensorflow tf.nn.conv2d