对卷积神经网络中 1D、2D 和 3D 卷积的直观理解[关闭]

2023-11-26

谁能通过示例清楚地解释卷积神经网络(深度学习中)中 1D、2D 和 3D 卷积之间的区别?


我想用图片来解释C3D.

简而言之,卷积方向 & 输出形状很重要!

enter image description here

↑↑↑↑↑ 一维卷积 - 基础 ↑↑↑↑↑

  • just 1-计算转化率的方向(时间轴)
  • 输入 = [W],滤波器 = [k],输出 = [W]
  • 例如)输入 = [1,1,1,1,1],过滤器 = [0.25,0.5,0.25],输出 = [1,1,1,1,1]
  • 输出形状是一维数组
  • 示例)图形平滑

tf.nn.conv1d 代码玩具示例

import tensorflow as tf
import numpy as np

sess = tf.Session()

ones_1d = np.ones(5)
weight_1d = np.ones(3)
strides_1d = 1

in_1d = tf.constant(ones_1d, dtype=tf.float32)
filter_1d = tf.constant(weight_1d, dtype=tf.float32)

in_width = int(in_1d.shape[0])
filter_width = int(filter_1d.shape[0])

input_1d   = tf.reshape(in_1d, [1, in_width, 1])
kernel_1d = tf.reshape(filter_1d, [filter_width, 1, 1])
output_1d = tf.squeeze(tf.nn.conv1d(input_1d, kernel_1d, strides_1d, padding='SAME'))
print sess.run(output_1d)

enter image description here

↑↑↑↑↑ 2D 卷积 - 基础 ↑↑↑↑↑

  • 2- 方向 (x,y) 计算 conv
  • 输出形状是2D Matrix
  • 输入 = [W, H],滤波器 = [k,k] 输出 = [W,H]
  • 例子)索贝尔边缘过滤器

tf.nn.conv2d - 玩具示例

ones_2d = np.ones((5,5))
weight_2d = np.ones((3,3))
strides_2d = [1, 1, 1, 1]

in_2d = tf.constant(ones_2d, dtype=tf.float32)
filter_2d = tf.constant(weight_2d, dtype=tf.float32)

in_width = int(in_2d.shape[0])
in_height = int(in_2d.shape[1])

filter_width = int(filter_2d.shape[0])
filter_height = int(filter_2d.shape[1])

input_2d   = tf.reshape(in_2d, [1, in_height, in_width, 1])
kernel_2d = tf.reshape(filter_2d, [filter_height, filter_width, 1, 1])

output_2d = tf.squeeze(tf.nn.conv2d(input_2d, kernel_2d, strides=strides_2d, padding='SAME'))
print sess.run(output_2d)

enter image description here

↑↑↑↑↑ 3D 卷积 - 基础 ↑↑↑↑↑

  • 3- 方向 (x,y,z) 计算 conv
  • 输出形状是3D Volume
  • 输入 = [W,H,L],过滤器 = [k,k,d] 输出 = [宽、高、米]
  • d < L很重要!用于进行音量输出
  • 示例)C3D

tf.nn.conv3d - 玩具示例

ones_3d = np.ones((5,5,5))
weight_3d = np.ones((3,3,3))
strides_3d = [1, 1, 1, 1, 1]

in_3d = tf.constant(ones_3d, dtype=tf.float32)
filter_3d = tf.constant(weight_3d, dtype=tf.float32)

in_width = int(in_3d.shape[0])
in_height = int(in_3d.shape[1])
in_depth = int(in_3d.shape[2])

filter_width = int(filter_3d.shape[0])
filter_height = int(filter_3d.shape[1])
filter_depth = int(filter_3d.shape[2])

input_3d   = tf.reshape(in_3d, [1, in_depth, in_height, in_width, 1])
kernel_3d = tf.reshape(filter_3d, [filter_depth, filter_height, filter_width, 1, 1])

output_3d = tf.squeeze(tf.nn.conv3d(input_3d, kernel_3d, strides=strides_3d, padding='SAME'))
print sess.run(output_3d)

enter image description here

↑↑↑↑↑ 具有 3D 输入的 2D 卷积- LeNet,VGG,...,↑↑↑↑↑

  • 即使输入是 3D ex) 224x224x3、112x112x32
  • 输出形状不是3D音量,但是2D Matrix
  • 因为过滤深度=L必须与输入通道匹配 =L
  • 2-方向(x,y)来计算转换!非 3D
  • 输入 = [W,H,L],过滤器 = [k,k,L] 输出 = [宽,高]
  • 输出形状是2D Matrix
  • 如果我们想训练 N 个过滤器怎么办(N 是过滤器的数量)
  • 那么输出形状是(堆叠二维)3D = 2D x N matrix.

conv2d - LeNet、VGG...用于 1 个过滤器

in_channels = 32 # 3 for RGB, 32, 64, 128, ... 
ones_3d = np.ones((5,5,in_channels)) # input is 3d, in_channels = 32
# filter must have 3d-shpae with in_channels
weight_3d = np.ones((3,3,in_channels)) 
strides_2d = [1, 1, 1, 1]

in_3d = tf.constant(ones_3d, dtype=tf.float32)
filter_3d = tf.constant(weight_3d, dtype=tf.float32)

in_width = int(in_3d.shape[0])
in_height = int(in_3d.shape[1])

filter_width = int(filter_3d.shape[0])
filter_height = int(filter_3d.shape[1])

input_3d   = tf.reshape(in_3d, [1, in_height, in_width, in_channels])
kernel_3d = tf.reshape(filter_3d, [filter_height, filter_width, in_channels, 1])

output_2d = tf.squeeze(tf.nn.conv2d(input_3d, kernel_3d, strides=strides_2d, padding='SAME'))
print sess.run(output_2d)

conv2d - LeNet、VGG...用于 N 个过滤器

in_channels = 32 # 3 for RGB, 32, 64, 128, ... 
out_channels = 64 # 128, 256, ...
ones_3d = np.ones((5,5,in_channels)) # input is 3d, in_channels = 32
# filter must have 3d-shpae x number of filters = 4D
weight_4d = np.ones((3,3,in_channels, out_channels))
strides_2d = [1, 1, 1, 1]

in_3d = tf.constant(ones_3d, dtype=tf.float32)
filter_4d = tf.constant(weight_4d, dtype=tf.float32)

in_width = int(in_3d.shape[0])
in_height = int(in_3d.shape[1])

filter_width = int(filter_4d.shape[0])
filter_height = int(filter_4d.shape[1])

input_3d   = tf.reshape(in_3d, [1, in_height, in_width, in_channels])
kernel_4d = tf.reshape(filter_4d, [filter_height, filter_width, in_channels, out_channels])

#output stacked shape is 3D = 2D x N matrix
output_3d = tf.nn.conv2d(input_3d, kernel_4d, strides=strides_2d, padding='SAME')
print sess.run(output_3d)

enter image description here ↑↑↑↑↑ Bonus 1x1 conv in CNN - GoogLeNet, ..., ↑↑↑↑↑

  • 当您将其视为像 sobel 这样的 2D 图像过滤器时,1x1 转换会令人困惑
  • 对于 CNN 中的 1x1 卷积,输入是如上图所示的 3D 形状。
  • 它计算深度过滤
  • 输入 = [W,H,L],过滤器 =[1,1,L]输出 = [宽,高]
  • 输出堆叠形状为3D = 2D x N matrix.

tf.nn.conv2d - 特殊情况 1x1 转换

in_channels = 32 # 3 for RGB, 32, 64, 128, ... 
out_channels = 64 # 128, 256, ...
ones_3d = np.ones((1,1,in_channels)) # input is 3d, in_channels = 32
# filter must have 3d-shpae x number of filters = 4D
weight_4d = np.ones((3,3,in_channels, out_channels))
strides_2d = [1, 1, 1, 1]

in_3d = tf.constant(ones_3d, dtype=tf.float32)
filter_4d = tf.constant(weight_4d, dtype=tf.float32)

in_width = int(in_3d.shape[0])
in_height = int(in_3d.shape[1])

filter_width = int(filter_4d.shape[0])
filter_height = int(filter_4d.shape[1])

input_3d   = tf.reshape(in_3d, [1, in_height, in_width, in_channels])
kernel_4d = tf.reshape(filter_4d, [filter_height, filter_width, in_channels, out_channels])

#output stacked shape is 3D = 2D x N matrix
output_3d = tf.nn.conv2d(input_3d, kernel_4d, strides=strides_2d, padding='SAME')
print sess.run(output_3d)

动画(具有 3D 输入的 2D 转换)

enter image description here

  • 原文链接:LINK
  • 作者:马丁·戈尔纳
  • 推特:@martin_gorner
  • 谷歌+:plus.google.com/+MartinGorne

带有 2D 输入的额外 1D 卷积

enter image description here ↑↑↑↑↑ 1D Convolutions with 1D input ↑↑↑↑↑

enter image description here ↑↑↑↑↑ 1D Convolutions with 2D input ↑↑↑↑↑

  • 即使输入是 2D ex) 20x14
  • 输出形状不是2D , but 1D Matrix
  • 因为过滤器高度 =L必须与输入高度匹配=L
  • 1-方向(x)计算转换!非二维
  • 输入 = [W,L],过滤器 = [k,L] 输出 = [W]
  • 输出形状是1D Matrix
  • 如果我们想训练 N 个过滤器怎么办(N 是过滤器的数量)
  • 那么输出形状是(堆叠一维)2D = 1D x N matrix.

奖金C3D

in_channels = 32 # 3, 32, 64, 128, ... 
out_channels = 64 # 3, 32, 64, 128, ... 
ones_4d = np.ones((5,5,5,in_channels))
weight_5d = np.ones((3,3,3,in_channels,out_channels))
strides_3d = [1, 1, 1, 1, 1]

in_4d = tf.constant(ones_4d, dtype=tf.float32)
filter_5d = tf.constant(weight_5d, dtype=tf.float32)

in_width = int(in_4d.shape[0])
in_height = int(in_4d.shape[1])
in_depth = int(in_4d.shape[2])

filter_width = int(filter_5d.shape[0])
filter_height = int(filter_5d.shape[1])
filter_depth = int(filter_5d.shape[2])

input_4d   = tf.reshape(in_4d, [1, in_depth, in_height, in_width, in_channels])
kernel_5d = tf.reshape(filter_5d, [filter_depth, filter_height, filter_width, in_channels, out_channels])

output_4d = tf.nn.conv3d(input_4d, kernel_5d, strides=strides_3d, padding='SAME')
print sess.run(output_4d)

sess.close()

Tensorflow 中的输入和输出

enter image description here

enter image description here

Summary

enter image description here

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

对卷积神经网络中 1D、2D 和 3D 卷积的直观理解[关闭] 的相关文章

随机推荐

  • 如何在shiny::numericInput 中使标签和框彼此相邻对齐?

    是否有可能创建一个numericInput 对于闪亮的地方 盒子位于标签旁边 而不是默认的标签下方 这是一个简单的例子 library shiny ui lt shinyUI fluidPage titlePanel Shiny with
  • 将文件中每一行的第一个字母更改为大写

    我需要将文件中每一行的第一个字母更改为大写 例如 the bear ate the fish the river was too fast 会成为 The bear ate the fish The river was too fast 该
  • 从 Xsd 构建 UI 的工具包或应用程序

    我需要构建一个用户界面来编辑和创建符合给定 xsd 架构的 xml 文档 我想做的是 尽可能基于该 xsd 架构生成我的用户界面 xsd 模式可以 并且将会 随着时间的推移而改变 因此解决方案需要具有一定的灵活性 用户界面需要是一个 Web
  • Firebase 存储使用 490MB 但我没有存储桶?

    Firebase 存储正在使用 490 MB 但尚未初始化任何存储桶 我无法追踪该存储的来源 但检查 Firebase 对空存储收取 0 10 美元的费用是很奇怪的 我在哪里可以删除此存储以及为什么 firebase 因没有存储桶而收费 目
  • Dijkstra算法:如果有两个或多个权重最小的节点怎么办?

    在 Dijkstra 算法中 如果算法中的某个点有两个或多个权重最小的节点 我该怎么办 在维基百科中 http en wikipedia org wiki Dijkstra 27s algorithm在步骤号 6 它说 将暂定距离最小的未访
  • 使用 pip 安装 TextBlob 时遇到问题

    我在 Windows 10 上使用 pip 在命令行中安装 TextBlob 时遇到了一些困难 根据他们的文档 您需要连续运行两个命令 pip install U textblob python m textblob download co
  • 非轴对齐矩形交集[关闭]

    Closed 这个问题需要多问focused 目前不接受答案 我正在尝试找到一种算法来计算两个矩形 不一定是轴对齐 之间的交集 并返回结果交集 这个问题描述寻找是否存在交叉点 我想要得到交叉点的最终形状 如果存在 我对该算法的应用将使用一个
  • 从“docker ps”获取容器 ID 的 Shell 命令

    我基本上希望实现这两个步骤 1 运行docker镜像 docker run p 80 80 某些图像名称 25 2 现在 docker ps 返回有关容器的完整数据 但我只是在寻找容器 ID 3 对其进行一些测试 例如 docker exe
  • jquery颜色动画间歇性地抛出无效的属性值

    我正在尝试为 ASP Net 超链接的背景设置动画 以在更新面板刷新时进行黄色淡入淡出 到目前为止 它几乎在所有时间都有效 但偶尔会抛出一个 JavaScript 错误 无效的属性值 它调试到jquery颜色插件代码到这一行 fx elem
  • 为 STL 排序算法定义 < - 运算符重载、函子还是独立函数?

    我有一个包含 Widget 类对象的 stl list 它们需要根据 Widget 类中的两个成员进行排序 为了使排序工作 必须定义一个比较两个 Widget 对象的小于比较器 似乎有无数种方法可以做到这一点 据我所知 人们可以 A 在类中
  • 获取内存上的可用空间

    是否可以通过 Android SDK 获取 Android 设备 而不是 SD 卡 上的可用内存量 如果是这样 怎么办 this帖子可能很适合您的问题 还检查这个线程 这里有很多关于SO的信息 谷歌搜索了一下 这是解决方案 位于安卓 git
  • 隐藏超出 DIV 元素的文本

    我有一个固定宽度的 DIV 元素 其中有一些文本 其中没有任何空格供 HTML 解析器自动分成多行 文本超出了 DIV 的限制并弄乱了 pgae 有没有办法让超出边界的文本不可见 是否可以将其分成多行 或者更好地分成多行 并在每条折行的末尾
  • 多线程比单线程快吗?

    我想检查多线程是否比单线程快 然后我在这里做了一个演示 public class ThreadSpeedTest param args public static void main String args System out print
  • 将“C50 型号”转换为“rpart”型号

    有没有办法使用rpart plot用于绘制不属于的对象的库rpart 用于制作决策树 例如 这是经典的rpart and rpart plot正在运行的库 load libraries library rpart library rpart
  • mysql中什么是复合外键?

    在我正在使用的框架的文档中看到这个术语 复合外键 yii 什么是复合外键 在 mySql 数据库中 我的猜测是 考虑到两个表之间的关系 一个表有一列的名称与另一个表的 id 完全相同 免责声明 我做了尽职调查 并在谷歌上搜索了大约两分钟 但
  • VS 2010 Web 服务项目模板丢失?

    这可能是一个愚蠢的问题 但当我尝试创建新项目时 我找不到 Web 服务应用程序模板 您可能需要一个 WCF 服务项目 新建项目 gt Visual C 或 Visual Basic gt WCF 服务应用程序
  • 如何在 JSON 中显示带有尾随零的 BigDecimal 数字(而不是字符串)?

    在我的表示响应中 我有一个 BigDecimal 类型的字段 它的值为 2 30 但 json 响应将其显示为 2 3 有没有办法同时显示尾随零 而不将其显示为字符串 顺便说一句 我正在使用杰克逊库 version 2 3 needs to
  • 还有一个“无法加载文件或程序集......或其依赖项之一。系统找不到指定的文件”

    我有一个带有 NUnit 测试的 dll 运行良好 我将其从 Any CPU 转换为 x86 项目 因为我需要跨不同平台可靠地使用 SQLite 因此我需要包含 32 位 System Data SQLite dll 并让所有内容都引用它
  • 像 iPhone 上的地址簿排序一样对 NSString 的 NSArray 进行排序

    我有一个字符串数组 名称 我想像 iPhone 上的地址簿对它们进行排序一样对它们进行排序 例如 li gt E 下 例如 li gt A 下 例如 4li gt 在 下 有什么建议么 您需要对字符串执行不区分变音符号的比较 NSStrin
  • 对卷积神经网络中 1D、2D 和 3D 卷积的直观理解[关闭]

    Closed 这个问题不符合堆栈溢出指南 目前不接受答案 谁能通过示例清楚地解释卷积神经网络 深度学习中 中 1D 2D 和 3D 卷积之间的区别 我想用图片来解释C3D 简而言之 卷积方向 输出形状很重要 一维卷积 基础 just 1 计