I was trying to split my image through 4 patches when I came through the following error:
UnimplementedError: Only support ksizes across space
JavaScript
x
14
14
1
iterator = tf.compat.v1.data.make_one_shot_iterator(parsed_dataset)
2
image,label = iterator.get_next()
3
image_height = image.shape[0]
4
image_width = image.shape[1]
5
# Since the expected type is (batch,height,width,channels), i have tryied to expand my image that have
6
# dimensions: (800,344,3) to (1,800,344,3) but didn't solved the error.
7
#image = tf.expand_dims(image ,0)
8
images = list(image)
9
extracted_patches = tf.image.extract_patches(images=images,
10
sizes=[1,int(0.25*image_height),int(0.25*image_width),3],
11
strides=[1,int(0.25*image_height),int(0.25*image_width),3],
12
rates=[1,1,1,1],
13
padding="SAME")
14
Traceback:
JavaScript
1
32
32
1
---------------------------------------------------------------------------
2
UnimplementedError Traceback (most recent call last)
3
<ipython-input-64-23c2aff4c306> in <module>()
4
17 strides=[1,int(0.25*image_height),int(0.25*image_width),3],
5
18 rates=[1,1,1,1],
6
---> 19 padding="SAME")
7
20
8
21
9
10
/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)
11
4657 """
12
4658 return gen_array_ops.extract_image_patches(images, sizes, strides, rates,
13
-> 4659 padding, name)
14
4660
15
4661
16
17
/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)
18
2542 else:
19
2543 message = e.message
20
-> 2544 _six.raise_from(_core._status_to_exception(e.code, message), None)
21
2545 # Add nodes to the TensorFlow graph.
22
2546 if not isinstance(ksizes, (list, tuple)):
23
24
/Users/lucianoaraujo/anaconda2/lib/python2.7/site-packages/six.pyc in raise_from(value, from_value)
25
735 else:
26
736 def raise_from(value, from_value):
27
--> 737 raise value
28
738
29
739
30
31
UnimplementedError: Only support ksizes across space. [Op:ExtractImagePatches]
32
Advertisement
Answer
After further research I was able to manage by changing from:
JavaScript
1
7
1
images = list(image)
2
extracted_patches = tf.image.extract_patches(images=images,
3
sizes=[1,int(0.25*image_height),int(0.25*image_width),3],
4
strides=[1,int(0.25*image_height),int(0.25*image_width),3],
5
rates=[1,1,1,1],
6
padding="SAME")
7
To :
JavaScript
1
7
1
image = tf.expand_dims(image ,0)
2
extracted_patches = tf.image.extract_patches(images=image,
3
sizes=[1,int(0.25*image_height),int(0.25*image_width),1],
4
strides=[1,int(0.25*image_height),int(0.25*image_width),1],
5
rates=[1,1,1,1],
6
padding="SAME")
7
And then reshape to obtain 3 channel images:
JavaScript
1
2
1
patches = tf.reshape(extracted_patches,[-1,int(0.25*image_height),int(0.25*image_width),3])
2