使用 Pipeline 生成图像描述
在本练习中,您将再次使用 flickr 数据集。该数据集包含 30,000 张图像及其对应的描述。现在,您将使用 pipeline(而不是 auto 类)为下图生成描述。

数据集(dataset)已按以下结构加载:
Dataset({
features: ['image', 'caption', 'sentids', 'split', 'img_id', 'filename'],
num_rows: 10
})
pipeline 模块(pipeline)已加载。
本练习是课程的一部分
使用 Hugging Face 的多模态模型
练习说明
- 使用
Salesforce/blip-image-captioning-base预训练模型加载image-to-textpipeline。 - 使用该 pipeline 为索引为
3的图像生成描述。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Load the image-to-text pipeline
pipe = pipeline(task="____", model="____")
# Use the pipeline to generate a caption with the image of datapoint 3
pred = ____(dataset[3]["____"])
print(pred)