Skip to content
Tutorials3 min read

使用 Potato 进行图像分类

学习如何设置带有缩略图预览、缩放控制和多标签支持的图像分类任务。

Potato Team·

使用 Potato 进行图像分类

图像分类是计算机视觉的基石。无论你是在构建产品分类系统、内容审核流程还是医学影像分类器,Potato 都提供了高效图像标注所需的工具。

你将学到

  • 设置图像标注任务
  • 单标签和多标签分类
  • 层级分类结构
  • 图像任务的质量控制

基本图像分类

让我们从一个简单的单标签分类任务开始。

配置

yaml
annotation_task_name: "Product Image Classification"
 
# Image data
data_files:
  - data/products.json
 
item_properties:
  id_key: product_id
  text_key: image_url
 
# Classification labels
annotation_schemes:
  - annotation_type: image_annotation
    name: category
    description: "What type of product is shown?"
    labels:
      - Electronics
      - Clothing
      - Home & Garden
      - Sports & Outdoors
      - Books & Media
      - Other
    keyboard_shortcuts:
      Electronics: "1"
      Clothing: "2"
      "Home & Garden": "3"
      "Sports & Outdoors": "4"
      "Books & Media": "5"
      Other: "6"

数据格式

创建 data/products.json

json
{"product_id": "P001", "image_url": "/images/products/laptop.jpg"}
{"product_id": "P002", "image_url": "/images/products/tshirt.jpg"}
{"product_id": "P003", "image_url": "/images/products/garden_tools.jpg"}
{"product_id": "P004", "image_url": "https://example.com/images/basketball.jpg"}

图像可以是本地路径或 URL。

多标签分类

对于属于多个类别的图像:

yaml
annotation_schemes:
  - annotation_type: multiselect
    name: attributes
    description: "Select all attributes that apply to this image"
    labels:
      - Contains people
      - Outdoor scene
      - Indoor scene
      - Contains text
      - Product photo
      - Lifestyle photo
      - Close-up shot
      - Wide angle
    min_selections: 1
    max_selections: 5

层级分类

对于复杂的分类体系,使用嵌套标签:

yaml
annotation_schemes:
  - annotation_type: radio
    name: main_category
    description: "Primary category"
    labels:
      - Apparel
      - Electronics
      - Home
 
  - annotation_type: radio
    name: subcategory
    description: "Subcategory"
    conditional:
      depends_on: main_category
      options:
        Apparel:
          - Tops
          - Bottoms
          - Footwear
          - Accessories
        Electronics:
          - Phones
          - Computers
          - Audio
          - Cameras
        Home:
          - Furniture
          - Decor
          - Kitchen
          - Bedding

图像质量评估

在分类旁添加质量检查:

yaml
annotation_schemes:
  - annotation_type: radio
    name: category
    description: "Product category"
    labels: [Electronics, Clothing, Home, Other]
 
  - annotation_type: radio
    name: image_quality
    description: "Is this image suitable for the product catalog?"
    labels:
      - name: Approved
        description: "Clear, well-lit, product is visible"
      - name: Needs review
        description: "Minor issues but potentially usable"
      - name: Rejected
        description: "Poor quality, wrong product, or inappropriate"
 
  - annotation_type: multiselect
    name: quality_issues
    description: "If not approved, what issues are present?"
    labels:
      - Blurry or out of focus
      - Poor lighting
      - Wrong product shown
      - Watermark or text overlay
      - Inappropriate content
      - Multiple products in frame
    conditional:
      depends_on: image_quality
      show_when: ["Needs review", "Rejected"]

高级图像设置

对于高级图像显示自定义,在标注方案中配置 image_annotation 类型,并根据需要使用 CSS 或自定义样式。

完整示例

以下是一个生产就绪的配置:

yaml
annotation_task_name: "E-commerce Image Classification"
 
data_files:
  - data/images.json
 
item_properties:
  id_key: sku
  text_key: image_path
 
annotation_schemes:
  - annotation_type: image_annotation
    name: primary_category
    description: "Select the main product category"
    labels:
      - Electronics
      - Clothing & Accessories
      - Home & Living
      - Beauty & Personal Care
      - Sports & Fitness
      - Toys & Games
      - Other
    required: true
    keyboard_shortcuts:
      Electronics: "1"
      "Clothing & Accessories": "2"
      "Home & Living": "3"
      "Beauty & Personal Care": "4"
      "Sports & Fitness": "5"
      "Toys & Games": "6"
      Other: "7"
 
  - annotation_type: multiselect
    name: image_attributes
    description: "Select all that apply"
    labels:
      - White background
      - Lifestyle shot
      - Multiple angles
      - Model wearing/using
      - Size reference included
      - Brand visible
    required: false
 
  - annotation_type: radio
    name: listing_ready
    description: "Is this image ready for product listing?"
    labels:
      - Yes - Ready to publish
      - No - Needs editing
      - No - Reshoot required
    required: true
 
annotation_guidelines:
  title: "Image Classification Guidelines"
  content: |
    ## Category Selection
    Choose the most specific category that fits the product.
 
    ## Image Quality
    - "Ready to publish": Clear, professional, meets standards
    - "Needs editing": Good photo but needs cropping/color correction
    - "Reshoot required": Fundamentally unsuitable

图像标注技巧

  1. 一致的显示器设置:确保标注者使用校准过的显示器
  2. 清晰的类别定义:在指南中包含示例图片
  3. 处理边缘案例:记录如何处理模糊图像
  4. 定期校准:团队一起审查样本

下一步


完整的图像标注文档请参阅 /docs/features/image-annotation