【发布时间】:2017-10-03 11:58:16
【问题描述】:
我有一个代码可以训练对象坐标以进行对象检测。 我使用了 CNN 网络,输出层是回归层(称为 bound_box_output),它返回图像中对象的 (x0,y0, height, width)。在这一层之后,我尝试在损失步骤之前直接保存图像。
i = 0
image_decoded = tf.image.decode_jpeg(tf.read_file('3.jpg'), channels=3)
cropped = tf.image.crop_to_bounding_box(image = image_decoded,
offset_height = tf.cast(bound_box_output[i,0], tf.int32),
offset_width = tf.cast(bound_box_output[i,1], tf.int32),
target_height = tf.cast(bound_box_output[i,2], tf.int32),
target_width = tf.cast(bound_box_output[i,3], tf.int32))
enc = tf.image.encode_jpeg(cropped)
fname = tf.constant('4.jpeg')
fwrite = tf.write_file(fname, enc)
在 tf.train.SessionRunHook 我运行它
def begin(self):
self._step = -1
self._start_time = time.time()
def before_run(self, run_context):
self._step += 1
return tf.train.SessionRunArgs(loss)
def after_run(self, run_context, run_values):
if self._step % LOG_FREQUENCY == 0:
current_time = time.time()
duration = current_time - self._start_time
self._start_time = current_time
loss_value = run_values.results
examples_per_sec = LOG_FREQUENCY * BATCH_SIZE / duration
sec_per_batch = float(duration / LOG_FREQUENCY)
format_str = ('%s: step %d, loss = %.2f (%.1f examples/sec; %.3f '
'sec/batch)')
print (format_str % (datetime.now(), self._step, loss_value,
examples_per_sec, sec_per_batch))
if self._step == MAX_STEPS-1:
loss_value = run_values.results
print("The final value of loss is:: ")
print(loss_value)
print(fwrite)
tf.train.SessionRunArgs(fwrite)
问题是它没有将“4.jpeg”图像保存在特定文件夹中
注意:我使用 tensorflow 1.1.3 和 python3.5
【问题讨论】:
-
程序是否打印了最后的打印语句(“损失的最终值是::”等)?
-
是的,这是训练的最后一步
-
好的,很高兴知道这一点。代码似乎是正确的,所以我不确定出了什么问题。您是否尝试过明确说明输出文件的路径? (例如,将
/tmp/4.jpeg用作fname。只是为了确保文件编写器实际上正在保存某些内容。 -
是的,我这样做了,但没有保存图像
标签: python-3.x tensorflow conv-neural-network