나는 this 링크에 설명 된대로 이미지에서 텐서 겹치는 패치 을 얻기 위해 tf.extract_image_patches()
을 사용했습니다. 언급 된 링크의 대답은 겹치는 패치에서 이미지를 재구성하기 위해 tf.space_to_depth()
을 사용할 것을 제안합니다. 그러나 문제는 이것이 내 경우에 바람직한 결과를 제공하지 않는다는 것과 연구를 통해 tf.space_to_depth()
이 겹치는 블록을 처리하지 않는다는 것을 알게되었다는 것입니다.겹쳐진 패치 이미지에서 이미지 재구성
import tensorflow as tf
import numpy as np
c = 3
height = 3900
width = 6000
ksizes = [1, 150, 150, 1]
strides = [1, 75, 75, 1]
image = #image of shape [1, height, width, 3]
patches = tf.extract_image_patches(image, ksizes = ksizes, strides= strides, [1, 1, 1, 1], 'VALID')
patches = tf.reshape(patches, [-1, 150, 150, 3])
reconstructed = tf.reshape(patches, [1, height, width, 3])
rec_new = tf.space_to_depth(reconstructed,75)
rec_new = tf.reshape(rec_new,[height,width,3])
이 나에게 오류 제공합니다 : 내 코드처럼 보이는 나는이 때문에 호환되지 않는 차원에 오류가 알고
InvalidArgumentError Traceback (most recent call last) D:\AnacondaIDE\lib\site-packages\tensorflow\python\framework\common_shapes.py in _call_cpp_shape_fn_impl(op, input_tensors_needed, input_tensors_as_shapes_needed, require_shape_fn) 653 graph_def_version, node_def_str, input_shapes, input_tensors, --> 654 input_tensors_as_shapes, status) 655 except errors.InvalidArgumentError as err:
D:\AnacondaIDE\lib\contextlib.py in exit(self, type, value, traceback) 87 try: ---> 88 next(self.gen) 89 except StopIteration:
D:\AnacondaIDE\lib\site-packages\tensorflow\python\framework\errors_impl.py in raise_exception_on_not_ok_status() 465 compat.as_text(pywrap_tensorflow.TF_Message(status)), --> 466 pywrap_tensorflow.TF_GetCode(status)) 467 finally:
InvalidArgumentError: Dimension size must be evenly divisible by 70200000 but is 271957500 for 'Reshape_22' (op: 'Reshape') with input shapes: [4029,150,150,3], [4] and with input tensors computed as partial shapes: input 1 = [?,3900,6000,3].
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last) in() ----> 1 reconstructed = tf.reshape(features, [-1, height, width, channel]) 2 rec_new = tf.space_to_depth(reconstructed,75) 3 rec_new = tf.reshape(rec_new,[h,h,c])
D:\AnacondaIDE\lib\site-packages\tensorflow\python\ops\gen_array_ops.py in reshape(tensor, shape, name) 2617 """ 2618 result = _op_def_lib.apply_op("Reshape", tensor=tensor, shape=shape, -> 2619 name=name) 2620 return result 2621
D:\AnacondaIDE\lib\site-packages\tensorflow\python\framework\op_def_library.py in apply_op(self, op_type_name, name, **keywords) 765 op = g.create_op(op_type_name, inputs, output_types, name=scope, 766 input_types=input_types, attrs=attr_protos, --> 767 op_def=op_def) 768 if output_structure: 769 outputs = op.outputs
D:\AnacondaIDE\lib\site-packages\tensorflow\python\framework\ops.py in create_op(self, op_type, inputs, dtypes, input_types, name, attrs, op_def, compute_shapes, compute_device) 2630
original_op=self._default_original_op, op_def=op_def) 2631 if compute_shapes: -> 2632 set_shapes_for_outputs(ret) 2633 self._add_op(ret) 2634
self._record_op_seen_by_control_dependencies(ret)D:\AnacondaIDE\lib\site-packages\tensorflow\python\framework\ops.py in set_shapes_for_outputs(op) 1909 shape_func = _call_cpp_shape_fn_and_require_op 1910 -> 1911 shapes = shape_func(op) 1912 if shapes is None: 1913 raise RuntimeError(
D:\AnacondaIDE\lib\site-packages\tensorflow\python\framework\ops.py in call_with_requiring(op) 1859 1860 def call_with_requiring(op): -> 1861 return call_cpp_shape_fn(op, require_shape_fn=True) 1862 1863 _call_cpp_shape_fn_and_require_op = call_with_requiring
D:\AnacondaIDE\lib\site-packages\tensorflow\python\framework\common_shapes.py in call_cpp_shape_fn(op, require_shape_fn) 593 res = _call_cpp_shape_fn_impl(op, input_tensors_needed, 594 input_tensors_as_shapes_needed, --> 595 require_shape_fn) 596 if not isinstance(res, dict): 597 # Handles the case where _call_cpp_shape_fn_impl calls unknown_shape(op).
D:\AnacondaIDE\lib\site-packages\tensorflow\python\framework\common_shapes.py in _call_cpp_shape_fn_impl(op, input_tensors_needed, input_tensors_as_shapes_needed, require_shape_fn) 657 missing_shape_fn = True 658 else: --> 659 raise ValueError(err.message) 660 661 if missing_shape_fn:
ValueError: Dimension size must be evenly divisible by 70200000 but is 271957500 for 'Reshape_22' (op: 'Reshape') with input shapes: [4029,150,150,3], [4] and with input tensors computed as partial shapes: input 1 = [?,3900,6000,3].
을하지만, 바로 그런 식으로해야 하는가? 이 문제를 해결하도록 도와주세요.
문서에서 'strides'는 패치 중심 간의 거리를 정의하고 'ksizes'는 필터의 크기이며 각 패치의 크기를 나타냅니다. 그렇게해서는 안되나요? –