'str'对象没有属性'shape'

问题描述 投票:0回答:1

尝试使用 Keras 的图像字幕代码示例

在“矢量化文本数据”上,它给了我一个错误,请记住,我只是尝试编译代码示例,我还没有进行任何修改。 https://keras.io/examples/vision/image_captioning/

关于“文本数据矢量化”

vectorization = TextVectorization(
    max_tokens=VOCAB_SIZE,
    output_mode="int",
    output_sequence_length=SEQ_LENGHT,
    standardize=custom_standardization,
)
vectorization.adapt(text_data)       ------> Problem here

这是我开始“text_data”列表的地方:

def load_captions_data( TEXT_PATH ):
    """Loads captions (text) data and maps them to corresponding images.

    Args:
        filename: Path to the text file containing caption data.

    Returns:
        caption_mapping: Dictionary mapping image names and the corresponding captions
        text_data: List containing all the available captions
    """
    with open( TEXT_PATH ) as caption_file:
        caption_data = caption_file.readlines()
        caption_mapping = {}
        text_data = []                  ------------>HERE
        images_to_skip = set()

这是调用 text_data[] 的地方(您可以在代码示例[上面的链接]中看到所有代码):

if img_name.endswith("jpg") and img_name not in images_to_skip:
                caption = "<start> " + caption.strip() + " <end>"
                text_data.append(caption)
        return caption_mapping, text_data
captions_mapping, text_data = load_captions_data("Flickr8k.token.txt")

这是错误: 发生异常:AttributeError “str”对象没有属性“shape” 文件“C:\MyFilePath”,第141行,在第141行是矢量化代码,这是这个问题的第一个 矢量化.adapt(text_data) 属性错误:“str”对象没有属性“shape”

我尝试将信息放入列表中,例如:

text_data.append("A Beautiful Sunset")
text_data.append("Another caption...")

仍然是同样的错误。

提前致谢。

python keras deep-learning
1个回答
0
投票

我解决了这个问题,我通过正常的python代码将input_string小写,因为tensorflow函数不起作用,所以这就是问题,我通过使用tensorflow函数将input_string小写来解决它

© www.soinside.com 2019 - 2024. All rights reserved.