- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我找到了以下方法tf.extract_image_patches在 tensorflow API 中,但我不清楚它的功能。
假设 batch_size = 1
,图像大小为 225x225x3
,我们要提取大小为 32x32
的 block 。
这个函数的具体表现如何?具体来说,文档提到输出张量的维度是 [batch, out_rows, out_cols, ksize_rows * ksize_cols * depth]
,但是 out_rows
和 out_cols
没有提到。
理想情况下,给定大小为 1x225x225x3
的输入图像张量(其中 1 是批量大小),我希望能够获得 Kx32x32x3
作为输出,其中 K
是补丁的总数,32x32x3
是每个补丁的维度。 tensorflow 中是否已经实现了这一点?
最佳答案
这是该方法的工作原理:
ksized
用于决定每个补丁的尺寸,或者换句话说,每个补丁应该包含多少像素。
strides
表示原始图像中一个补丁的开始与下一个连续补丁的开始之间的间隙长度。
rates
是一个数字,本质上意味着我们的补丁应该在原始图像中以 rates
个像素为单位跳跃,以达到我们补丁中的每个连续像素。 (下面的例子有助于说明这一点。)
padding
要么是“VALID”,这意味着每个补丁必须完全包含在图像中,或者是“SAME”,这意味着允许补丁不完整(剩余的像素将用零填写)。
以下是一些示例代码,其输出有助于演示其工作原理:
import tensorflow as tf
n = 10
# images is a 1 x 10 x 10 x 1 array that contains the numbers 1 through 100 in order
images = [[[[x * n + y + 1] for y in range(n)] for x in range(n)]]
# We generate four outputs as follows:
# 1. 3x3 patches with stride length 5
# 2. Same as above, but the rate is increased to 2
# 3. 4x4 patches with stride length 7; only one patch should be generated
# 4. Same as above, but with padding set to 'SAME'
with tf.Session() as sess:
print tf.extract_image_patches(images=images, ksizes=[1, 3, 3, 1], strides=[1, 5, 5, 1], rates=[1, 1, 1, 1], padding='VALID').eval(), '\n\n'
print tf.extract_image_patches(images=images, ksizes=[1, 3, 3, 1], strides=[1, 5, 5, 1], rates=[1, 2, 2, 1], padding='VALID').eval(), '\n\n'
print tf.extract_image_patches(images=images, ksizes=[1, 4, 4, 1], strides=[1, 7, 7, 1], rates=[1, 1, 1, 1], padding='VALID').eval(), '\n\n'
print tf.extract_image_patches(images=images, ksizes=[1, 4, 4, 1], strides=[1, 7, 7, 1], rates=[1, 1, 1, 1], padding='SAME').eval()
输出:
[[[[ 1 2 3 11 12 13 21 22 23]
[ 6 7 8 16 17 18 26 27 28]]
[[51 52 53 61 62 63 71 72 73]
[56 57 58 66 67 68 76 77 78]]]]
[[[[ 1 3 5 21 23 25 41 43 45]
[ 6 8 10 26 28 30 46 48 50]]
[[ 51 53 55 71 73 75 91 93 95]
[ 56 58 60 76 78 80 96 98 100]]]]
[[[[ 1 2 3 4 11 12 13 14 21 22 23 24 31 32 33 34]]]]
[[[[ 1 2 3 4 11 12 13 14 21 22 23 24 31 32 33 34]
[ 8 9 10 0 18 19 20 0 28 29 30 0 38 39 40 0]]
[[ 71 72 73 74 81 82 83 84 91 92 93 94 0 0 0 0]
[ 78 79 80 0 88 89 90 0 98 99 100 0 0 0 0 0]]]]
因此,例如,我们的第一个结果如下所示:
* * * 4 5 * * * 9 10
* * * 14 15 * * * 19 20
* * * 24 25 * * * 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
* * * 54 55 * * * 59 60
* * * 64 65 * * * 69 70
* * * 74 75 * * * 79 80
81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99 100
如您所见,我们有 2 行 2 列的补丁,这就是 out_rows
和 out_cols
。
关于python - 了解 tf.extract_image_patches 以从图像中提取补丁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40731433/
我正在尝试在站点列表中添加站点名称,以便在 publish:end:remote 上清除 HTML 缓存事件。 mysite 但是,它没有按预期工
我正在尝试使用不同目录中的多个文件制作补丁。我不想包含所有未提交的文件,因为我有很多不适用于补丁。 我知道这个命令可以使用特定文件创建补丁,唯一的问题是这是一个文件: svn diff -up ori
我经常使用 gnu-utils 补丁和差异。使用 git,我经常这样做: git diff 通常简单的更改会创建一个大补丁,因为唯一的更改是,例如,添加一个 if/else 循环,并且里面的所有内容都
我使用命令(从 ~ 执行)生成了一个 diff.txt 文件: diff -r /full/path/to/directory/A /full/path/to/directory/B > diff.t
我正在编写一个项目,我需要通过网络传输一组相似的图像。为了加快速度,我考虑过做大多数电影编解码器所做的事情。有关键帧,然后发送更改。 现在,我得到的是一组 BufferedImage,因此类似于文本文
我正在尝试将更改拆分为多个提交,但在手动编辑大块时我遇到了问题。 原始大块头: @@ -116,8 +116,8 @@ context context -
我想自动测试一组仍然干净利落地适用于(更新的)代码库的补丁。为此,我打算运行 patch -p 1 a echo b > b diff -Nu a b > p rm a b patch -p 1 <
我已经从一个模块中导入了一个类,但是当我尝试在没有模块作为前缀的情况下修补类名时,我得到一个类型错误: TypeError: Need a valid target to patch. You sup
最近我从 SVN 迁移到 git,我的团队已经开始在新的 git 存储库中工作。 后来我发现了一些转换问题,并从 SVN 制作了第二个 git repo,并进行了一些修复和历史重写。 现在我有了 SV
我正在尝试为我的应用程序创建一个补丁。实现描述的示例 here按预期工作。但是,每个版本的文件都存储在单独的目录中。 1.0 版文件在 c:sample\1.0 中,1.1 版文件在 c:sample
首先请原谅我的长文,但我会尽量详细。 我正在为一个开源项目 (DSpace) 进行开发。我没有对他们的 SVN 存储库的提交权限,所以我查看了源代码并一直使用 git 来管理我的版本控制。 在我的开发
有没有办法自动 merge (interdiff)2 个头分支和 1 个基分支之间的冲突? 我试图在补丁级别做这件事 版本A是我的基础 VersionB 是 VersionA 的分支 VersionB
我正在尝试申请 this修补到 MinGW 上的 GCC 以获取它 to compile GDC 2 ,但我不知道如何。 (我对 GCC 的内部结构还很陌生,甚至对一般的 *nix 工具也很陌生。)我
我对软件开发很陌生,所以这无疑是一个非常基本的问题。我得到了一个开源项目的 mercurial repo。我复制了它并做了一些工作。 promise 。工作更多,然后进行了第二次提交。所以我的树看起来
我想对这个错误 ( http://code.djangoproject.com/ticket/13095 ) 应用补丁,但我以前从未做过,也不知道从哪里开始。谁能给我指点教程? 最佳答案 在 Linu
我前段时间使用 p4 diff 生成了一个补丁。命令。 然而,现在我想应用它,我意识到没有办法在 Perforce 中应用补丁。 由于我没有使用 -du选项,补丁是那种晦涩难懂的 perforce 格
我可以使用 NSIS 的 Vpatch 生成从一个版本到另一个版本的补丁文件。假设我有 mydll.dll 版本 1,我有一个补丁可以将它更新到版本 2。然后我又有了一个新版本,因此我生成了另一个补丁
我有一个补丁,用 hg export 42 制作在另一个存储库中,修改文件 asd/fgh/foo/bar.c asd/fgh/foo/fish.h boo/hoo.txt 我需要将此补丁导入具有如下
我们有一个相当大的库,我们需要定期将其导入(然后修补)到我们的代码库中。 SVN Book 似乎推荐了一个“vendor branch”方案,我们保留了“vendor drops”的补丁版本。这会起作
我正在家里用 tensorflow 玩卷积神经网络(顺便说一句,我已经完成了 udacity 深度学习类(class),所以我有理论基础)。 运行卷积时,patch 的大小会产生什么影响?当图像变大/
我是一名优秀的程序员,十分优秀!