使用 Potato 进行图像分类
在 Potato 中设置图像分类:用 instance_display 展示图像,用 radio 和 multiselect 方案收集标签,并加上质量检查。
大多数计算机视觉项目迟早都需要一堆标好的图像,而这些标注总得有人来做。无论是给产品照片分门别类、审核内容,还是给医学影像归类,Potato 负责界面,你只管标签。本教程涵盖几种常见配置:单标签和多标签分类、两级类目结构,以及让图像任务保持可靠的质量检查。
先把图像显示出来,再提问
在 Potato 里,分类和绘制是两件不同的事,把它们混为一谈是最常见的第一个错误。instance_display 负责把图片显示到屏幕上,annotation_schemes 负责提问。image_annotation 类型是用来在图像上画框和掩码的,分类任务完全用不到它。
annotation_task_name: "Product Image Classification"
task_dir: "."
data_files:
- data/products.json
item_properties:
id_key: product_id
text_key: image_url
instance_display:
fields:
- key: image_url
type: image
label: "Product image"
display_options:
max_width: 600
zoomable: true
annotation_schemes:
- annotation_type: radio
name: category
description: "What type of product is shown?"
labels:
- Electronics
- Clothing
- Home & Garden
- Sports & Outdoors
- Books & Media
- Other
sequential_key_binding: true
output_annotation_dir: annotation_output/
export_annotation_format: jsonlsequential_key_binding 把 1 到 6 这几个键分给六个标签。一个只需扫一眼、点一下的任务,速度基本就取决于键盘。
界面会在图像下方显示类别标签:
图像标注界面,显示一张产品图片以及分类标签和键盘快捷键
数据格式
创建 data/products.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。text_key 指向存放路径的那个字段,Potato 会把这个字段交给显示组件。
多标签分类
一张图像同时属于好几个类别时,用 multiselect:
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嵌套类目
Potato 没有给单选按钮提供嵌套标签类型,所以两级类目就是两个方案。每个方案都要有自己的 labels,而子类目列表必须覆盖所有父类目:
annotation_schemes:
- annotation_type: radio
name: main_category
description: "Primary category"
labels:
- Apparel
- Electronics
- Home
- annotation_type: radio
name: subcategory
description: "Subcategory within the primary category"
labels:
- Tops
- Bottoms
- Footwear
- Phones & Tablets
- Computers
- Audio
- Furniture
- Kitchen
- Decor如果第二个列表会变得很长,hierarchical_multiselect 能把它收进一个控件,省掉拆成两个方案。
与分类并行的质量检查
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
tooltip: "Clear, well-lit, product is visible"
- name: Needs review
tooltip: "Minor issues but potentially usable"
- name: Rejected
tooltip: "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针对单个标签的说明写在 tooltip 里,这是标签会读取的键。写成标签上的 description:,这段文字不会出现在标注者能看到的任何地方。
完整示例
annotation_task_name: "E-commerce Image Classification"
task_dir: "."
data_files:
- data/images.json
item_properties:
id_key: sku
text_key: image_path
instance_display:
fields:
- key: image_path
type: image
label: "Product image"
display_options:
max_width: 700
zoomable: true
annotation_schemes:
- annotation_type: radio
name: primary_category
description: "Select the main product category"
labels:
- Electronics
- Clothing & Accessories
- Home & Living
- Beauty & Personal Care
- Sports & Fitness
- Toys & Games
- Other
sequential_key_binding: true
- annotation_type: multiselect
name: image_attributes
description: "Select all that apply"
labels:
- White background
- Lifestyle shot
- Multiple angles
- Model wearing or using
- Size reference included
- Brand visible
label_requirement:
required: false
- annotation_type: radio
name: listing_ready
description: "Is this image ready for the product listing?"
labels:
- Ready to publish
- Needs editing
- Reshoot required
label_requirement:
required: true
annotation_instructions: |
## Image Classification Guidelines
### Category selection
Choose the most specific category that fits the product.
### Image quality
- Ready to publish: clear, professional, meets standards
- Needs editing: good photo that needs cropping or color correction
- Reshoot required: fundamentally unsuitable
output_annotation_dir: annotation_output/
export_annotation_format: jsonl图像标注的几点经验
不同显示器的颜色和亮度不一样,凡是这一点会影响判断的任务,都要确认标注者用的屏幕校准得还算靠谱。指南里放示例图片,别用文字去描述类别;一张图平息的争论比一整段话还多。把模糊图像该怎么处理写下来,因为模糊图像一定会出现。另外每隔一阵子让团队标同一批数据再做对比,标准漂移才能早点发现。
实现细节参见图像标注文档。
下一步
完整的图像标注文档参见图像标注。