开始使用免费开始使用

自动化标题质量评估

您已经成功分类了这条连衣裙的图像,但原始描述到底有多准确?

Maa Fab wrap with a Trendy design dress with Vibrant color for an elegant touch of Fabric completely Soft and Comfortable wear with amazing design of Solid Boat ? Neck Flared Dress to make a perfect addition to your wardrobe collection.

现在,您将使用 CLIP 模型,通过 CLIP 分数对该描述的准确性做出定量判断。变量 description(标题)、image(图像)、ToTensor 类,以及来自 torchmetricsclip_score() 函数均已加载。

本练习是课程的一部分

使用 Hugging Face 的多模态模型

查看课程

练习说明

  • 将图像转换为 PyTorch 张量,像素强度范围为 0-255。
  • 使用 clip_score() 函数,基于 openai/clip-vit-base-patch32 模型,对比 image_tensordescription 来评估标题质量。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Convert the image to a PyTorch tensor
image_tensor = ____()(image)*____

# Use the clip_score function to assess the quality of the caption
score = ____(____, ____, "____")

print(f"CLIP score: {score}")
编辑并运行代码