tf.nn.conv3d(tf.compat.v1.nn.conv3d)函数

本文详细介绍了tf.nn.conv3d函数,该函数用于计算5-D张量input与5-D张量filter的3-D卷积。文章深入解析了函数的参数、返回值及可能的异常,特别强调了其在信号处理中的应用,如互相关计算。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


tf.nn.conv3d函数别名 tf.compat.v1.nn.conv3d

1.函数功能

计算5-D张量input与5-D张量filter的3-D卷积。

在信号处理中,互相关(cross-correlation)衡量两个信号相似性的指标。cross-correlation也被称为滑动点积或滑动内积。
tf.nn.conv3d是以cross-correlation形式实现的。

2.入参

tf.nn.conv3d(
    input,
    filter=None,
    strides=None,
    padding=None,
    data_format='NDHWC',
    dilations=[1, 1, 1, 1, 1],
    name=None,
    filters=None
)
参数含义
input5-D张量,元素类型必须是half, bfloat16, float32, float64之一。 对于NDHWC格式是[batch, in_depth, in_height, in_width, in_channels],NCDHW是 [batch, in_channels, in_depth, in_height, in_width]。
filters5-D张量,与输入类型一致。格式 [filter_depth, filter_height, filter_width, in_channels, out_channels],其中in_channels必须保持input和filters一致。
strides1-D张量,元素int类型,其长度length >= 5。滑动窗口在input的每个维度上 滑动步长。其元素关系要求strides[0] = strides[4] = 1.
padding指定填充算法,"SAME"或 “VALID”。
data_formatinput和output的格式,可以是"NDHWC"或 “NCDHW”,默认 “NDHWC”。"NDHWC"格式 [batch, in_depth, in_height, in_width, in_channels].,"NCDHW"格式对应[batch, in_channels, in_depth, in_height, in_width]。
dilations膨胀因子。默认 [1, 1, 1, 1, 1]。 长度为5的1-D张量。
name操作名(可选).

3.返回值

输出张量,与输入input一致。

4.可能引发的异常

ValueError,如data_format无效。

# GRADED FUNCTION: forward_propagation def forward_propagation(X, parameters): """ Implements the forward propagation for the model: CONV2D -> RELU -> MAXPOOL -> CONV2D -> RELU -> MAXPOOL -> FLATTEN -> FULLYCONNECTED Arguments: X -- input dataset placeholder, of shape (input size, number of examples) parameters -- python dictionary containing your parameters "W1", "W2" the shapes are given in initialize_parameters Returns: Z3 -- the output of the last LINEAR unit """ # Retrieve the parameters from the dictionary "parameters" W1 = parameters['W1'] W2 = parameters['W2'] ### START CODE HERE ### # CONV2D: stride of 1, padding 'SAME' Z1 = tf.nn.conv2d(X, W1, strides=[1, 1, 1, 1], padding='SAME') # RELU A1 = tf.nn.relu(Z1) # MAXPOOL: window 8x8, sride 8, padding 'SAME' P1 = tf.nn.max_pool(A1, ksize=[1, 8, 8, 1], strides=[1, 8, 8, 1], padding='SAME') # CONV2D: filters W2, stride 1, padding 'SAME' Z2 = tf.nn.conv2d(P1, W2, strides=[1, 1, 1, 1], padding='SAME') # RELU A2 = tf.nn.relu(Z2) # MAXPOOL: window 4x4, stride 4, padding 'SAME' P2 = tf.nn.max_pool(A2, ksize=[1, 4, 4, 1], strides=[1, 4, 4, 1], padding='SAME') # FLATTEN P2 = tf.contrib.layers.flatten(P2) # FULLY-CONNECTED without non-linear activation function (not not call softmax). # 6 neurons in output layer. Hint: one of the arguments should be "activation_fn=None" Z3 = tf.contrib.layers.fully_connected(P2, 6, activation_fn=None) ### END CODE HERE ### return Z3 tf.reset_default_graph() with tf.Session() as sess: np.random.seed(1) X, Y = create_placeholders(64, 64, 3, 6) parameters = initialize_parameters() Z3 = forward_propagation(X, parameters) init = tf.global_variables_initializer() sess.run(init) a = sess.run(Z3, {X: np.random.randn(2,64,64,3), Y: np.random.randn(2,6)}) print("Z3 = " + str(a)) 请根据现在python版本修改这段代码
07-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值