对卷积神经网络中 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 卷积的直观理解[关闭] 的相关文章

  • 如何使用node.js获取屏幕分辨率

    我需要使用 node js 获取屏幕分辨率 但以下代码不起作用 var w screen width var h screen height 这也行不通 var w window screen width var h window scre
  • 调用一个从 AngularJS 表达式本地计算值的函数是不是很糟糕?

    我读了关于使用范围的一些 AngularJS 陷阱的文章 http thenittygritty co angularjs pitfalls using scopes 并且它指出您不应在表达式中使用函数 并且我知道每次框架认为需要时都可能会
  • 在 ASP.NET 中生成新的 SessionId

    登录时我想生成一个新的 SessionId 我已经发现一种有效的解决方案 https stackoverflow com questions 1368403 generating a new asp net session in the c
  • 禁用 ASPNET 身份 2.0 中的用户

    我正在寻找一种方法来禁用用户而不是从系统中删除它们 这是为了保持相关数据的数据完整性 但似乎 ASPNET 身份只提供删除帐户 有一个新的锁定功能 但似乎可以控制锁定以禁用用户 但只有在尝试了一定次数的错误密码后才将用户锁定 还有其他选择吗
  • 按照说明后“找不到您尝试购买的商品”

    所以我按照以下说明进行操作http developer android com google play billing billing admin html http developer android com google play bi
  • 收到 Python 错误“来自:无法读取 /var/mail/Bio”

    我正在运行一个 bio python 脚本 这会导致以下错误 from can t read var mail Bio 由于我的脚本与邮件没有任何关系 我不明白为什么我的脚本在 var mail 中查找 这里似乎有什么问题 我怀疑这会有帮助
  • 什么时候使用静态库需要头文件?

    如果我在 Linux 中用 C 创建一个静态库并生成 a 文件 我 或其他人 如何使用该库 例如 我的库定义了一个类 我认为仅仅提供 a 文件是不够的 还需要提供头文件 我如何知道 a 文件必须提供哪些头文件 例如 我是否需要提供我的库代码
  • 如何将 char 转换为 unsigned int?

    我有一个字符数组 它实际上用作字节数组 而不是用于存储文本 在数组中 有两个特定字节表示我需要存储到无符号 int 值中的数值 下面的代码解释了设置 char bytes bytes 2 bytes 0 0x0C For the sake
  • Symfony2 dev环境可以工作,prod环境给出404错误

    我最近在我的机器上成功安装了 Symfony2 我可以访问http localhost app dev php 开发环境 但是 当我尝试访问 prod 环境时 http localhost app php 我在浏览器中收到以下错误消息 哎呀
  • 当从 HDFS 手动删除分区数据时,如何更新 Hive 中的分区元数据

    自动更新Hive分区表元数据的方法是什么 如果新的分区数据被添加到HDFS 不执行alter table添加分区命令 然后我们可以通过执行命令 msck Repair 来同步元数据 如果从HDFS中删除了大量分区数据 没有执行alter t
  • 了解客户端文件的对象 URL 以及如何释放内存

    我在用createObjectURL获取本地图像文件的引用 URL 当我完成文件 图像后 我打电话revokeObjectURL释放该内存 一切对我来说都很好 但我只是想确保我释放了我能释放的所有内存 我检查后出现了我的担忧chrome b
  • RecyclerView 不调用 onCreateViewHolder 或 onBindView

    没有收到任何错误 所有数据似乎都有效 由于某种原因 没有调用与视图相关的方法 我已确定以下事项 getItemCount 是唯一被调用的适配器方法 并且返回一个正整数值 我知道这将是你们将要查看的区域 构造函数正在被调用 成员变量有效 Pa
  • 将 scanf 与 NSString 一起使用

    我希望用户输入一个字符串 然后将输入分配给 NSString 现在我的代码如下所示 NSString word scanf s word The scanf http www cplusplus com reference clibrary
  • 如何在 Xcode 10 中恢复快速帮助?

    在我升级到 Xcode 10 后 快速帮助信息仅提供所选类或结构的声明 是否有某个设置可以使其与 Xcode 9 中的设置相同 升级后我遇到了同样的问题 其中函数签名是单击选项时唯一显示的内容 当我删除里面的所有内容后 快速帮助再次出现 L
  • Docker-compose:npm 安装成功后卷中不存在 node_modules

    我有一个具有以下服务的应用程序 web 在端口 5000 上保存并运行 python 3 Flask Web 服务器 使用 sqlite3 worker 有一个index js文件是队列的工作人员 Web 服务器通过端口使用 json AP
  • 如何向 SvelteKit/Vite 应用添加版本号?

    我正在尝试在我的 SvelteKit 应用程序中创建一个系统 它会在某个页面上向您显示有关当前应用程序版本的信息 最好是 Git 提交哈希和描述 我尝试使用Vite的定义功能 https vitejs dev config define在构
  • Android On Focus Listener 和 On Click Listener on ImageView

    我有一个 imageview 它具有两个属性 可聚焦的 and 可聚焦触摸模式 set to true
  • Cakephp - CSRF 令牌不匹配

    我在 Cakephp 3 6 中有一个项目 其中 MessageController 中的 3 个操作由 Ajax 调用 但是 我有一个问题 当我向其中一个操作发送请求时 XHR 会向我返回以下内容 message CSRF token m
  • 带有 .htaccess 的漂亮网址?

    我刚刚创建了一个新的 WordPress 页面模板 在其中运行一些 php mysql 脚本 我想对其子页面应用 mod 重写 例如我生成了以下链接 http www quotist com quotes by authors html l
  • 首选项和操作栏中的开/关切换按钮 - 冰淇淋三明治风格

    我指的是 ICS 手机上默认 Android 设置应用程序中看到的蓝色开 关样式 也可以在这里看到 http android developers blogspot com 2012 02 android design v2 now wit

随机推荐

  • 如何在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 计