从重叠的图像块重建图像

问题描述 投票:0回答:1

我已经使用tf.extract_image_patches()来获取图像中的重叠贴片张量,如this链接中所述。上述链接中的答案建议使用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(最近一次调用最后一次)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除了errors.InvalidArgumentError为错误:

D:\ AnacondaIDE \ lib \ contextlib.py在退出(自我,类型,值,追溯)87尝试:---> 88 next(self.gen)89除了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:尺寸大小必须可被70200000整除,但对于'Reshape_22'(op:'Reshape')是271957500,输入形状为:[4029,150,150,3],[4]并且输入张量计算为部分形状:input1 = [?,3900,6000,3]。

在处理上述异常期间,发生了另一个异常:

ValueError Traceback(最近一次调用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 2617“”“2618 result = _op_def_lib.apply_op(”Reshape“,tensor = tensor,shape =形状, - > 2619 name = name)2620返回结果2621

apply:op中的D:\ AnacondaIDE \ lib \ site-packages \ tensorflow \ python \ framework \ op_def_library.py(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如果形状为无:1913引发RuntimeError(

call_with_requiring(op)中的D:\ AnacondaIDE \ lib \ site-packages \ tensorflow \ python \ framework \ _acs.py 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

调用call_cpp_shape_fn中的D:\ AnacondaIDE \ lib \ site-packages \ tensorflow \ python \ framework \ common_shapes.py(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 is is isinstance( res,dict):597#处理_call_cpp_shape_fn_impl调用unknown_shape(op)的情况。

_call_cpp_shape_fn_impl中的D:\ AnacondaIDE \ lib \ site-packages \ tensorflow \ python \ framework \ common_shapes.py(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:尺寸大小必须可被70200000整除,但对于具有输入形状的'Reshape_22'(op:'Reshape')是271957500:[4029,150,150,3],[4]并且输入张量计算为部分形状:input1 = [?,3900,6000,3]。

我知道这是由于不兼容的尺寸造成的错误,但它应该是这样的,对吗?请帮我解决这个问题。

python-3.x machine-learning tensorflow computer-vision
1个回答
0
投票

我想问题是,在你发布的链接中,作者使用stridesksizes的相同值,而你使用的strides等于ksizes的一半。这就是为什么尺寸不匹配的原因,你应该在粘合它们之前编写减小补丁大小的逻辑(例如通过选择每个补丁的中心方块)。

© www.soinside.com 2019 - 2024. All rights reserved.