尝试从图像中提取补丁并得到"未实现错误:仅支持跨空间的 ksize"



试图通过4个补丁分割我的图像时遇到以下错误:

UnimplementedError: Only support ksizes across space

iterator = tf.compat.v1.data.make_one_shot_iterator(parsed_dataset) 
image,label = iterator.get_next()
image_height = image.shape[0]
image_width = image.shape[1]
# Since the expected type is (batch,height,width,channels), i have tryied to expand my image that have
# dimensions: (800,344,3) to (1,800,344,3) but didn't solved the error.
#image = tf.expand_dims(image ,0)
images = list(image)
extracted_patches = tf.image.extract_patches(images=images,
sizes=[1,int(0.25*image_height),int(0.25*image_width),3],
strides=[1,int(0.25*image_height),int(0.25*image_width),3],
rates=[1,1,1,1],
padding="SAME")

追溯:

---------------------------------------------------------------------------
UnimplementedError                        Traceback (most recent call last)
<ipython-input-64-23c2aff4c306> in <module>()
17                                              strides=[1,int(0.25*image_height),int(0.25*image_width),3],
18                                              rates=[1,1,1,1],
---> 19                                              padding="SAME")
20 
21 
/Users/lucianoaraujo/anaconda2/lib/python2.7/site-packages/tensorflow_core/python/ops/array_ops.pyc in extract_image_patches_v2(images, sizes, strides, rates, padding, name)
4657   """
4658   return gen_array_ops.extract_image_patches(images, sizes, strides, rates,
-> 4659                                              padding, name)
4660 
4661 
/Users/lucianoaraujo/anaconda2/lib/python2.7/site-packages/tensorflow_core/python/ops/gen_array_ops.pyc in extract_image_patches(images, ksizes, strides, rates, padding, name)
2542       else:
2543         message = e.message
-> 2544       _six.raise_from(_core._status_to_exception(e.code, message), None)
2545   # Add nodes to the TensorFlow graph.
2546   if not isinstance(ksizes, (list, tuple)):
/Users/lucianoaraujo/anaconda2/lib/python2.7/site-packages/six.pyc in raise_from(value, from_value)
735 else:
736     def raise_from(value, from_value):
--> 737         raise value
738 
739 
UnimplementedError: Only support ksizes across space. [Op:ExtractImagePatches]

经过进一步的研究,我能够通过更改以下内容进行管理:

images = list(image)
extracted_patches = tf.image.extract_patches(images=images,
sizes=[1,int(0.25*image_height),int(0.25*image_width),3],
strides=[1,int(0.25*image_height),int(0.25*image_width),3],
rates=[1,1,1,1],
padding="SAME")

收件人:

image = tf.expand_dims(image ,0)
extracted_patches = tf.image.extract_patches(images=image,
sizes=[1,int(0.25*image_height),int(0.25*image_width),1],
strides=[1,int(0.25*image_height),int(0.25*image_width),1],
rates=[1,1,1,1],
padding="SAME")

然后整形以获得3个通道图像:

patches = tf.reshape(extracted_patches,[-1,int(0.25*image_height),int(0.25*image_width),3])

最新更新