将自定义函数映射到Tesorflow数据集时出错

时间:2019-10-26 15:02:25

标签: python tensorflow tensorflow-datasets

我想将此函数映射到数据集:

def prep_data(data):
    FilePath = data[0].numpy()
    image_bytes = tf.io.read_file(FilePath)
    image = tf.io.decode_jpeg(image_bytes)

    A = data[1].numpy().decode()
    B = data[2].numpy().decode()

    a = "some_function on A" if "condition" else np.nan
    b = "some_function on B" if "condition" else np.nan 

    return image, ("A", "B"), (a, b)

transformed_dataset = raw_dataset.map(prep_data, 1)

但是,我得到一个错误:

AttributeError: in converted code:

    <ipython-input-257-705f09e50e89>:2 prep_data  *
        FilePath = data[0].numpy()

    AttributeError: 'Tensor' object has no attribute 'numpy'

但是当我从数据集中调用张量并运行函数时,它就可以正常工作:

for i in raw_dataset.take(1):
    print(prep_data(i))

我没有得到什么?

0 个答案:

没有答案