前端参考文档
Label Studio前端(LSF)包含多种用户界面选项和回调函数,您可以在使用自定义标注后端实现前端时,或定制Label Studio界面时使用。
注意
自 Label Studio 1.11.0 版本起,Label Studio 前端已不再作为独立库维护,也不再提供单独的发行版本。如需了解如何在 Label Studio 中使用前端库,请参阅 README 文件。
LabelStud 1.0.0版本更新内容
警告
LSF 版本 1.0.0 与早期版本的 Label Studio 不兼容。
如果您使用自定义后端的LSF,必须按以下方式修改所使用的API回调:
0.9.1及更早版本中的回调 | 1.0.0版本中重命名的回调 |
---|---|
提交完成时 | 提交标注时 |
onUpdateCompletion | onUpdateAnnotation |
onDeleteCompletion | onDeleteAnnotation |
如果您依赖Label Studio已完成任务的特定格式,Label Studio的标注格式也已更新。
实现Label Studio前端界面
var labelStudio = new LabelStudio("editor", options);
初始化Label Studio实例版本1.0.0时,识别以下选项。
选项
配置
默认值: null
数据类型: string
基于XML的标注界面配置。此配置依赖于任务的data
字段。
更多信息请参阅Customizable Tags。
接口
默认值: null
数据类型: array
要显示的UI元素集合。可用界面:
panel
- 为当前任务启用导航面板,包含以下按钮:撤销、重做和重置。update
- 提交后显示更新当前任务的按钮。submit
- 显示一个按钮用于提交或更新当前标注。skip
- 显示一个按钮以跳过当前任务。controls
- 启用控制面板(包含submit
、update
、skip
按钮)。infobar
- 信息显示按钮。topbar
- 一个标注界面,列出Label Studio用户界面中的顶层项目。instruction
- 一个用于instructions的按钮。side-column
- 在Label Studio用户界面的左侧或右侧显示一个侧边栏。annotations:history
- 显示标注历史记录的按钮。annotations:tabs
- 显示标注标签页的按钮。annotations:menu
- 显示标注菜单的按钮。annotations:current
- 当前标注的显示按钮。annotations:add-new
- 显示添加新标注的按钮。annotations:delete
- 显示删除当前标注的按钮。annotations:view-all
- 显示查看所有标注的按钮。predictions:tabs
- 显示预测标签页。predictions:menu
- 显示预测菜单。auto-annotation
- 显示自动标注。edit-history
- 显示编辑历史。
消息
默认值: null
数据类型: object
消息传递用于不同的操作
{
DONE: "Done!",
NO_COMP_LEFT: "No more annotations",
NO_NEXT_TASK: "No more data available for labeling",
NO_ACCESS: "You don't have access to this task"
}
DONE
- 任务提交到服务器后显示NO_COMP_LEFT
- 如果没有更多标注时显示NO_NEXT_TASK
- 没有下一个任务可加载NO_ACCESS
- 无法访问提供的任务
描述
默认值: No description
数据类型: string
当前任务的描述。
任务
任务数据
默认值: null
数据类型: object
{
id: 1,
load: false
},
data: {
text: "Labeling text..."
},
annotations: [],
predictions: [],
}
id
数据类型: integer
默认值: null
数据
标注
数据类型: array
标注数组。更多信息请参阅标注文档。
预测结果
数据类型: array
预测结果数组。结构与标注结果或注释类似。更多信息请参阅标注文档和预测标签导入指南。
用户
用户数据
数据类型: object
{
"pk": 1,
"firstName": "Stanley",
"lastName": "Kubrick"
}
pk
数据类型: number
firstName
数据类型: string
lastName
数据类型: string
事件系统
LSF内置了一个事件系统,允许您监听事件并触发自定义操作。在Label Studio实例初始化后,您可以随时订阅或取消订阅事件。
使用事件
订阅事件
const callback = () => {
console.log("Event triggered");
};
labelStudio.on("event", callback);
取消订阅事件
const callback = () => {
console.log("Event triggered");
};
labelStudio.off("event", callback);
备注
要能够取消订阅事件,您必须将相同的回调函数引用传递给off
方法。
可用事件
顶层事件
此事件组包含顶级事件。这些事件与LSF的任何内部实体无关。
labelStudioLoad
Label Studio 实例已加载。
警告
该事件在插件中不起作用。
事件处理程序参数
参数 | 类型 | 描述 |
---|---|---|
labelStudio |
Object |
Instance of Label Studio |
storageInitialized
内部存储已初始化。
警告
该事件在插件中不起作用。
事件处理程序参数
参数 | 类型 | 描述 |
---|---|---|
labelStudio |
Object |
Instance of Label Studio |
任务事件
此事件组包含与任务相关的事件。
skipTask
用户点击了“跳过”按钮。
事件处理程序参数
参数 | 类型 | 描述 |
---|---|---|
labelStudio |
Object |
Instance of Label Studio |
payload |
Object |
Additional data sent during the skip action |
unskipTask
用户点击了“取消跳过”按钮。
参数 | 类型 | 描述 |
---|---|---|
labelStudio |
Object |
Instance of Label Studio |
nextTask
用户点击了“下一步”(右箭头)按钮。
参数 | 类型 | 描述 |
---|---|---|
labelStudio |
Object |
Instance of Label Studio |
taskId |
Number? |
ID of the next task in history |
annotationId |
Number? |
ID of the annotation to select within the task |
prevTask
用户点击了“上一页”(左箭头)按钮。
参数 | 类型 | 描述 |
---|---|---|
labelStudio |
Object |
Instance of Label Studio |
taskId |
Number? |
ID of the previous task in history |
annotationId |
Number? |
ID of the annotation to select within the task |
submitDraft
草稿已发送至服务器。
参数 | 类型 | 描述 |
---|---|---|
labelStudio |
Object |
Instance of Label Studio |
annotation |
Object |
Current annotation |
params |
Object? |
Extra params sent with the draft |
标注事件
该事件组包含与标注相关的事件。
beforeSaveAnnotation
标注内容将通过submit
或update
操作保存为结果。
如果该事件返回false
,将阻止保存标注。
参数 | 类型 | 描述 |
---|---|---|
labelStudio |
Object |
Instance of Label Studio |
annotation |
Object |
Current annotation |
payload |
Object |
Additional information |
payload.event |
string |
Indicates which event is about to be executed (submitAnnotation , updateAnnotation , etc.) |
submitAnnotation
标注已提交。
参数 | 类型 | 描述 |
---|---|---|
labelStudio |
Object |
Instance of Label Studio |
annotation |
Object |
Current annotation |
updateAnnotation
标注已更新。
参数 | 类型 | 描述 |
---|---|---|
labelStudio |
Object |
Instance of Label Studio |
annotation |
Object |
Current annotation |
selectAnnotation
已选择标注。
参数 | 类型 | 描述 |
---|---|---|
annotation |
Object |
Current annotation |
previousAnnotation |
Object |
Previous annotation |
payload |
Object? |
Additional information |
payload.fromViewAll |
boolean |
true if ViewAll has just been switched off |
deleteAnnotation
标注已被删除。
参数 | 类型 | 描述 |
---|---|---|
labelStudio |
Object |
Instance of Label Studio |
annotation |
Object |
Current annotation |
groundTruth
标注被设为基准真值(已点击星形按钮)。
参数 | 类型 | 描述 |
---|---|---|
store |
Object |
Instance of Label Studio |
labelStudio |
Object |
Instance of Label Studio |
params |
Object |
|
params.isDirty |
Boolean |
true if annotation was changed |
params.entity |
Object |
Current annotation |
selectHistory
已选择标注历史中的步骤。
参数 | 类型 | 描述 |
---|---|---|
labelStudio |
Object |
Instance of Label Studio |
annotation |
Object |
Current annotation |
historyItem |
Object |
Current history item |
区域事件
该事件组包含与区域相关的事件。区域是在分割任务(如图像分割、音频分割等)中使用的特殊实体。
entityCreate
区域已创建。
参数 | 类型 | 描述 |
---|---|---|
region |
Object |
Newly created region |
entityDelete
区域已删除。
参数 | 类型 | 描述 |
---|---|---|
region |
Object |
Newly created region |
Callbacks (deprecated)
回调函数可用于根据用户与界面的交互执行操作。例如,label-studio服务器使用回调函数与API进行通信。在初始化实例时,请将它们与其他选项一起传递。
onSubmitAnnotation
数据类型: function
当按下submit
按钮时调用。ls
是label studio实例,annotation
是当前标注的值。
示例
onSubmitAnnotation: function(ls, annotation) {
console.log(annotation)
}
onUpdateAnnotation
数据类型: function
当按下update
按钮时调用。ls
是label studio实例,annotation
是当前标注的值。
示例
onUpdateAnnotation: function(ls, annotation) {
console.log(result)
}
onDeleteAnnotation
数据类型: function
当按下delete
按钮时调用。ls
是label studio实例,annotation
是当前标注的值。
示例
onDeleteAnnotation: function(ls, annotation) {
console.log(result)
}
onEntityCreate
数据类型: function
当新区域被标注时调用,例如创建了一个新的边界框。region
是所创建的对象。
示例
onEntityCreate: function(region) {
console.log(region)
}
onEntityDelete
数据类型: function
当现有区域被删除时调用。region
是对象本身。
示例
onEntityDelete: function(region) {
console.log(region)
}
onSkipTask
数据类型: function
当按下skip
按钮时调用。ls
是label studio实例。
示例
onSkipTask: function(ls) {
console.log(result)
}
onLabelStudioLoad
数据类型: function
当Label Studio完全加载并准备好进行标注时调用。ls
是label studio实例
示例
onLabelStudioLoad: function(ls) {
console.log(result)
}