Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x python-tf.write_文件在tensorflow中不起作用_Python 3.x_Tensorflow_Conv Neural Network - Fatal编程技术网

Python 3.x python-tf.write_文件在tensorflow中不起作用

Python 3.x python-tf.write_文件在tensorflow中不起作用,python-3.x,tensorflow,conv-neural-network,Python 3.x,Tensorflow,Conv Neural Network,我有一个训练目标坐标用于目标检测的代码。 我使用了CNN网络,输出层是回归层(称为绑定框\u输出),它为图像中的对象返回(x0,y0,高度,宽度)。在这一层之后,我尝试在丢失步骤之前直接保存图像 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,

我有一个训练目标坐标用于目标检测的代码。 我使用了CNN网络,输出层是回归层(称为绑定框\u输出),它为图像中的对象返回(x0,y0,高度,宽度)。在这一层之后,我尝试在丢失步骤之前直接保存图像

   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.3python3.5TLDR;将
tf.train.SessionRunArgs(fwrite)
替换为
run\u context.session.run(fwrite)

实际上不运行提供的操作。从呼叫中返回。他们的角色是为下一个
会话.run()调用添加参数

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)  # problematic line
您正试图在结束时运行
fwrite
操作。然而,它只是实例化对象

实现所需行为的一个选项是利用提供给的
run\u context
参数<代码>运行上下文
的类型为,该类型包含一个
会话
引用


run\u context.session.run(fwrite)
应该可以帮你解决这个问题。

程序打印了最后的打印语句了吗(“丢失的最终值是::”,等等)?是的,这是培训的最后一步,很高兴知道。代码似乎正确,所以我不确定出了什么问题。您是否尝试过显式声明输出文件的路径?(例如,使用
/tmp/4.jpeg
作为
fname
。只是为了确保文件编写器确实在保存某些内容。是的,我这样做了,但没有保存任何图像。)