Python 在tensorflow中使用while操作时陷入无限循环
为了在tensorflow中并行裁剪一批图像,我使用了以下代码行:Python 在tensorflow中使用while操作时陷入无限循环,python,tensorflow,Python,Tensorflow,为了在tensorflow中并行裁剪一批图像,我使用了以下代码行: def cropImage(ind,input,output,d): input_t=input.read(ind) return ind+1,input,output.write(ind,tf.random_crop(input_t,d)),d def image_crop(t,batchsize ,dims): c= lambda _ind,_1,_2,_3: control_flow_ops.mat
def cropImage(ind,input,output,d):
input_t=input.read(ind)
return ind+1,input,output.write(ind,tf.random_crop(input_t,d)),d
def image_crop(t,batchsize ,dims):
c= lambda _ind,_1,_2,_3: control_flow_ops.math_ops.less(_ind, batchsize)
ind = tf.Variable(0,'iter')
output_ta = tensor_array_ops.TensorArray(
dtype='float32', size=batchsize,
tensor_array_name="dynamic_crop_output")
input_ta = tensor_array_ops.TensorArray(
dtype='float32', size=batchsize,
tensor_array_name="dynamic_crop_intput")
input_ta.unpack(t)
_1,_2,output,_3=control_flow_ops.While(c,cropImage,[ind,input_ta,output_ta,tf.constant(dims,name='dims')])
o = output.pack()
o.set_shape( [None] + list(dims))
return o
我的问题是:如果我不将指令
o.set\u shape([None]+list(dims))
放入一个似乎是无限循环的程序中,为什么?在最新版本的TensorFlow中仍然会出现这个问题?由于o.set\u shape()
只影响返回值,我怀疑问题出在调用image\u crop()
的某些代码中,因此您也可以共享其中的一些代码吗?我不再有这些代码了。很抱歉。在最新版本的TensorFlow中是否仍存在此问题?由于o.set\u shape()
只影响返回值,我怀疑问题出在调用image\u crop()
的某些代码中,因此您也可以共享其中的一些代码吗?我不再有这些代码了。对不起。