栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

了解tf.extract_image_patches从图像中提取补丁

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

了解tf.extract_image_patches从图像中提取补丁

该方法的工作原理如下:

  • ksizes
    用于确定每个面片的尺寸,即每个面片应包含多少像素。
  • strides
    表示原始图像中一个色块的开始与下一个连续色块的开始之间的间隙长度。
  • rates
    是一个数字,从本质上讲,我们的补丁应
    rates
    以原始图像中每个像素连续出现的像素跳了。(以下示例有助于说明这一点。)
  • padding
    是“ VALID”(有效),意味着每个色块必须完全包含在图像中;或者是“ SAME”,这意味着允许色块不完整(其余像素将用零填充)。

以下是一些示例代码,带有输出以帮助演示其工作方式:

import tensorflow as tfn = 10# images is a 1 x 10 x 10 x 1 array that contains the numbers 1 through 100 in orderimages = [[[[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(), 'nn'  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(), 'nn'  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(), 'nn'  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
有。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/404555.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号