开始使用免费开始使用

图像分类

在本练习中,您将继续使用之前的 flickr 数据集,其中包含 30,000 张图像及其对应的标题。现在,您将使用预训练模型对图像进行分类。

Photo of 2 people, 1 is playing the guitar

示例图像(image)和 pipeline 模块(pipeline)已加载。

本练习是课程的一部分

使用 Hugging Face 的多模态模型

查看课程

练习说明

  • 使用 google/mobilenet_v2_1.0_224 预训练模型加载 image-classification pipeline。
  • 使用该 pipeline 预测示例图像的类别。
  • 打印第一个(概率最高的)label

交互式实操练习

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

# Load the image-classification pipeline
pipe = ____

# Use the pipeline to predict the class of the sample image
pred = ____

# Print the first (highest probability) label
print("Predicted class:", ____)
编辑并运行代码