将3D图像张量流张量划分为较小的3D TF张量(图像块)

时间:2020-04-26 07:36:52

标签: python opencv tensorflow keras

我想从tf张量中提取特定大小的补丁。我的主要张量是形状: TensorShape([1, 6000, 6000, 3])。我想提取一些具有以下形状的张量:[1,416,416,3]。如果由于主张量的大小而不可能,如何提取形状为[1,400,400,3]的张量?

我尝试过tf.image.extract_patches:

size = [1, 416, 416, 3]
padding = [1, 1, 1, 1]
tf.image.extract_patches(
    images=image, sizes=size, strides=size,
    rates=[1, 1, 1, 1], padding='VALID').shape

但是我得到了错误:

---------------------------------------------------------------------------
UnimplementedError                        Traceback (most recent call last)
<ipython-input-17-2b717a449daf> in <module>()
      3 tf.image.extract_patches(
      4     images=image, sizes=size, strides=size,
----> 5     rates=[1, 1, 1, 1], padding='VALID').shape

3 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/array_ops.py in extract_image_patches_v2(images, sizes, strides, rates, padding, name)
   5306   """
   5307   return gen_array_ops.extract_image_patches(images, sizes, strides, rates,
-> 5308                                              padding, name)
   5309 
   5310 

/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/gen_array_ops.py in extract_image_patches(images, ksizes, strides, rates, padding, name)
   2342         pass  # Add nodes to the TensorFlow graph.
   2343     except _core._NotOkStatusException as e:
-> 2344       _ops.raise_from_not_ok_status(e, name)
   2345   # Add nodes to the TensorFlow graph.
   2346   if not isinstance(ksizes, (list, tuple)):

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py in raise_from_not_ok_status(e, name)
   6651   message = e.message + (" name: " + name if name is not None else "")
   6652   # pylint: disable=protected-access
-> 6653   six.raise_from(core._status_to_exception(e.code, message), None)
   6654   # pylint: enable=protected-access
   6655 

/usr/local/lib/python3.6/dist-packages/six.py in raise_from(value, from_value)

UnimplementedError: Only support ksizes across space. [Op:ExtractImagePatches]

对于具有[1,400,400,3]形状的张量,结果是相同的。 请注意,如果需要,我可以将主张量与[6000,6000,3]一起使用。我已经使用cv读取了图像,但是也可以使用PIL.Image读取图像。

我已经尝试过这个link,但没有得到答案。

0 个答案:

没有答案