gpt4 book ai didi

tensorflow - 如何在序列特征上应用 tf.map_fn?收到错误 : TensorArray dtype is string but Op is trying to write dtype uint8

转载 作者:行者123 更新时间:2023-12-03 11:24:04 25 4
gpt4 key购买 nike

我正在编写一个将视频映射到文本的序列到序列模型。我在 SequenceExample proto 的序列特征中将视频帧编码为 JPEG 字符串。在构建我的输入管道时,我正在执行以下操作以获取解码后的 jpeg 数组:

encoded_video, caption = parse_sequence_example(
serialized_sequence_example,
video_feature="video/frames",
caption_feature="video/caption_ids")
decoded_video = tf.map_fn(lambda x: tf.image.decode_jpeg(x, channels=3), encoded_video)

但是,我收到以下错误:
InvalidArgumentError (see above for traceback): TensorArray dtype is string but Op is trying to write dtype uint8.

我的目标是申请 image = tf.image.convert_image_dtype(image, dtype=tf.float32)解码后得到uint8的像素值在[0,255]之间 float 在[0,1]之间。

我尝试了以下几点:
decoded_video = tf.map_fn(lambda x: tf.image.decode_jpeg(x, channels=3), encoded_video, dtype=tf.uint8)
converted_video = tf.map_fn(lambda x: tf.image.convert_image_dtype(x, dtype=tf.float32), decoded_video)

但是,我仍然遇到相同的错误。任何人都知道可能会出什么问题?提前致谢。

最佳答案

没关系。只需在以下行中显式添加 tf.float32 dtype:

converted_video = tf.map_fn(lambda x: tf.image.convert_image_dtype(x, dtype=tf.float32), decoded_video, dtype=tf.float32)

关于tensorflow - 如何在序列特征上应用 tf.map_fn?收到错误 : TensorArray dtype is string but Op is trying to write dtype uint8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43057635/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com