[英]Using np.tile to tile 10 images of each image in a batch of images
Take the array: arr = [0, 1, 2]
取数组: arr = [0, 1, 2]
np.tile(arr,[10,1])
array([[0, 1, 2],
[0, 1, 2],
[0, 1, 2],
[0, 1, 2],
[0, 1, 2],
[0, 1, 2],
[0, 1, 2],
[0, 1, 2],
[0, 1, 2],
[0, 1, 2]])
>>> np.tile(arr,[10,2])
array([[0, 1, 2, 0, 1, 2],
[0, 1, 2, 0, 1, 2],
[0, 1, 2, 0, 1, 2],
[0, 1, 2, 0, 1, 2],
[0, 1, 2, 0, 1, 2],
[0, 1, 2, 0, 1, 2],
[0, 1, 2, 0, 1, 2],
[0, 1, 2, 0, 1, 2],
[0, 1, 2, 0, 1, 2],
[0, 1, 2, 0, 1, 2]])
Similar to this, I want to use the tile function to create 10 copies of an image batch of size 10x227x227x3 (the batch already has 10 images)) For each image I want to create a tile. 与此类似,我想使用图块功能为大小为10x227x227x3的图像批处理创建10个副本(该批处理已经具有10张图像)。 So I should get 100x227x227x3 所以我应该得到100x227x227x3
However when I do this M=10): 但是,当我这样做时,M = 10):
images = np.tile(img_batch, [M, 1])
I get 10x227x2270x3 instead, images = np.tile(img_batch, [M]) doesn't work either and brings a value of size 10x227x227x30 我得到的是10x227x2270x3,图像= np.tile(img_batch,[M])也不起作用,并带来了大小为10x227x227x30的值
I can't get around my head on how to get the tiles I need. 我无法理解如何获得所需的瓷砖。 Any recommendations are welcome. 欢迎任何建议。
Your img_batch
has 4 dimensions. 您的img_batch
具有4维。 Make the reps of size 4: 制作代表大小为4的代表 :
np.tile(img_batch, [M, 1, 1, 1])
Otherwise, it will be equivalent to np.tile(img_batch, [1, 1, M, 1]
in your first case according to the docs : 否则,根据文档 ,在第一种情况下,它等效于np.tile(img_batch, [1, 1, M, 1]
:
If A.ndim > d, reps is promoted to A.ndim by pre-pending 1's to it. 如果A.ndim> d,则通过在其前面加1来将代表提升为A.ndim。 Thus for an A of shape (2, 3, 4, 5), a reps of (2, 2) is treated as (1, 1, 2, 2). 因此,对于形状为(2、3、4、5)的A,将(2、2)的重复视为(1、1、2、2)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.