sample_distorted_bounding_box()至少需要2个参数(给定3个参数)

时间:2018-06-06 03:07:15

标签: python tensorflow

我运行了一个关于 tf.sample_distorted_bounding_box()的简单代码:

import tensorflow as tf
import os

file_content = tf.read_file('download.jpg')

image = tf.image.decode_jpeg(file_content)
image = tf.expand_dims(image, 0)

float_image = tf.image.convert_image_dtype(image, dtype=tf.float32)

example_img = tf.squeeze(float_image, 0)




begin, size, bbox_for_draw = tf.image.sample_distorted_bounding_box(
    tf.shape(example_img),
    min_object_covered=0.1,
    use_image_if_no_bounding_boxes = True)

但是我得到了错误:

 use_image_if_no_bounding_boxes = True)
TypeError: sample_distorted_bounding_box() takes at least 2 arguments (3 given)

我使用的是ubuntu16.04 TF1.5

1 个答案:

答案 0 :(得分:0)

tensorflow source code来自sample_distorted_bounding_box方法的签名

def sample_distorted_bounding_box(image_size,
                                  bounding_boxes,
                                  seed=None,
                                  seed2=None,
                                  min_object_covered=0.1,
                                  aspect_ratio_range=None,
                                  area_range=None,
                                  max_attempts=None,
                                  use_image_if_no_bounding_boxes=None,
                                  name=None):

此处image_sizebounding_boxes都是您在函数调用期间必须提供的位置参数。但是从你的代码中你只传递image_size。(即函数调用中缺少bounding_boxes)。这就是你得到TypeError的原因。

注意:如果您使用python3,您将获得以下TypeError(而不是问题中发布的TypeError),这本身就是自解释的

TypeError: sample_distorted_bounding_box() missing 1 required positional argument: 'bounding_boxes'
相关问题