遇到的问题
label-studio工具在标注某条数据完成后,切换到别的数据,再次切换到该条数据修改标注,修改后标注数据多了一条;或标注数据submit后,刷新当前标注数据的页面,重新update,update后,标注数据会多出一条。如下图所示:
image.png
或者是文本框有默认值而我在删除该默认值后保存,刷新页面后该文本框还是有原来的默认值。如下图所示:
image.png
问题出现的原因
排查到是由于在配置Labeling Interface时,给TextArea
配置了value
属性导致的。
image.png
image.png
解决办法
设置value属性的原因
之所以给TextArea
组件设置value
属性,是因为在进行标注之前,已经有一批模型预测出来的结果了,我方的需求是在已有预测结果上进行标注:修改预测错误的数据。我方想要的效果是:标注时文本输入框已有预测出来的默认值,省去挨个输入、复制粘贴的繁琐。所以给TextArea
设置了默认值。
解决步骤
1.Labeling Interface配置中去掉给TextArea
设置的value
属性
2.利用label-studio提供的sdk,将预测的结果作为一次标注导入到项目中
"""
原始json数据+默认标注=》导入json
"""
from label_studio_sdk import Client
import json
project_id = 4 # 你要导入的project的id参数
url = 'http://localhost:8080' # label-studio服务地址
api_key = '' # label-studio中你的账号Access Token(可在/user/account查到)
label_studio_client = Client(url=url, api_key=api_key)
data_json_path = r'./data/数据.json'
with open(data_json_path, 'r', encoding='utf-8') as f:
data_info = json.load(f)
column_list = [
['obj1_name', 'table_column_1_1'],
['obj1_age', 'table_column_1_2'],
['obj2_name', 'table_column_2_1'],
['obj2_age', 'table_column_2_2']
]
tasks = []
for data_item in data_info:
result = []
for column in column_list:
result_item = {
'value': {
'text': [data_item[column[0]]],
},
"from_name": column[1],
"to_name": "introduction",
"type": "textarea",
"origin": "manual"
}
result.append(result_item)
task = {
'data': data_item,
'annotations': [{'result': result}]
}
tasks.append(task)
project = label_studio_client.get_project(project_id)
response = project.import_tasks(tasks)
print(response)
最终效果
image.png
文中涉及到的配置信息数据
数据.json
[
{
"introduction": "这是一个文本介绍, 请按照以下格式提取出出场人物的姓名,年龄数据。 '11岁的李红离开了这所学校,12岁的Alice陷入了失落之中'",
"obj1_name": "李红",
"obj1_age": "11",
"obj2_name": "Alice",
"obj2_age": "12"
},
{
"introduction": "这是一个文本介绍, 请按照以下格式提取出出场人物的姓名,年龄数据。 '13岁的王明离开了这所学校,14岁的Bob陷入了失落之中'",
"obj1_name": "王明",
"obj1_age": "13",
"obj2_name": "Bob",
"obj2_age": "14"
}
]
Labeling Interface
<View>
<Text name="introduction" value="$introduction"></Text>
<Header value="对象1"></Header>
<Text name="obj1_name" value="对象1的名称"></Text>
<TextArea name="table_column_1_1" editable="true" toName="introduction" maxSubmissions="1"></TextArea>
<Text name="obj1_age" value="对象1的年龄"></Text>
<TextArea name="table_column_1_2" editable="true" toName="introduction" maxSubmissions="1"></TextArea>
<Header value="对象2" className="obj-title"></Header>
<Text name="obj2_name" value="对象2的名称"></Text>
<TextArea name="table_column_2_1" editable="true" toName="introduction" maxSubmissions="1"></TextArea>
<Text name="obj2_age" value="对象2的年龄"></Text>
<TextArea name="table_column_2_2" editable="true" toName="introduction" maxSubmissions="1"></TextArea>
</View>