指南 3个标注团队操作手册:提升标注速度与质量

启动Label Studio

安装Label Studio后,启动服务器即可开始使用。

label-studio start

默认情况下,Label Studio启动时会使用SQLite数据库来存储标注任务和注释。您可以通过Label Studio界面或API指定不同的数据源和目标存储位置来存放标注任务和注释。详情请参阅Database storage

启动Label Studio的命令行参数

您可以通过命令行界面指定机器学习后端和其他选项。运行label-studio --help查看所有可用选项,或参考以下表格。

Label Studio 提供了一些可用命令,用于获取信息或启动 Label Studio 服务器:

命令 描述
label-studio Start the Label Studio server.
label-studio -h label-studio --help Display available command line arguments.
label-studio init <project_name> <optional_arguments> Initialize a specific project in Label Studio.
label-studio start <project_name> --init <optional_arguments> Start the Label Studio server and initialize a specific project.
label-studio reset_password Reset the password for a specific Label Studio username. See Create user accounts for Label Studio.
label-studio shell Get access to a shell for Label Studio to manipulate data directly. See documentation for the Django shell-plus command.
label-studio version Show the version of Label Studio and then terminates.
label-studio user --username <email> Show the user info with token.

以下命令行参数是可选的,必须通过label-studio start 指定,或在设置托管Label Studio的环境时作为环境变量指定:

命令行参数 环境变量 默认值 描述
-b, --no-browser N/A False Do not automatically open a web browser when starting Label Studio.
-db --database LABEL_STUDIO_DATABASE label_studio.sqlite3 Specify the database file path for storing labeling tasks and annotations. See Database storage.
--data-dir LABEL_STUDIO_BASE_DATA_DIR OS-specific Directory to use to store all application-related data.
-d --debug N/A False Enable debug mode for troubleshooting Label Studio.
-c --config CONFIG_PATH default_config.json Deprecated, do not use. Specify the path to the server configuration for Label Studio.
-l --label-config LABEL_STUDIO_LABEL_CONFIG None Path to the label configuration file for a specific Label Studio project. See Set up your labeling project.
--ml-backends N/A None Command line argument is deprecated. Specify the URLs for one or more machine learning backends. See Set up machine learning with your labeling process.
--sampling N/A sequential Specify one of sequential or uniform to define the order for labeling tasks. See Set up task sampling for your project on this page.
--log-level N/A ERROR One of DEBUG, INFO, WARNING, or ERROR. Use to specify the logging level for the Label Studio server.
-p --port LABEL_STUDIO_PORT 8080 Specify the web server port for Label Studio. Defaults to 8080. See Run Label Studio on localhost with a different port on this page.
--host LABEL_STUDIO_HOST '' Specify the hostname to use to generate links for imported labeling tasks or static loading requirements. Leave empty to make all paths relative to the root domain. For example, specify "https://77.42.77.42:1234" or "http://ls.example.com/subdomain/". See Run Label Studio with an external domain name on this page.
--cert LABEL_STUDIO_CERT_FILE None Deprecated, do not use. Certificate file to use to access Label Studio over HTTPS. Must be in PEM format. See Run Label Studio with HTTPS on this page.
--key LABEL_STUDIO_KEY_FILE None Deprecated, do not use. Private key file for HTTPS connection. Must be in PEM format. See Run Label Studio with HTTPS on this page.
--initial-project-description LABEL_STUDIO_PROJECT_DESC '' Specify a project description for a Label Studio project. See Set up your labeling project.
--password LABEL_STUDIO_PASSWORD None Password to use for the default user. See Set up user accounts.
--username LABEL_STUDIO_USERNAME default_user@localhost Username to use for the default user. See Set up user accounts.
--user-token LABEL_STUDIO_USER_TOKEN Automatically generated. Authentication token for a user to use for the API. Must be set with a username, otherwise automatically generated. See Set up user accounts.
--agree-fix-sqlite N/A False Automatically agree to let Label Studio fix SQLite issues when using Python 3.6–3.8 on Windows operating systems.
--enable-legacy-api-token LABEL_STUDIO_ENABLE_LEGACY_API_TOKEN False Enable legacy API token authentication. Useful for running with a pre-existing token via --user-token.
N/A LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED False Allow Label Studio to access local file directories to import storage. See Run Label Studio on Docker and use local storage.
N/A LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT / Specify the root directory for Label Studio to use when accessing local file directories. See Run Label Studio on Docker and use local storage.

设置环境变量

如何设置环境变量取决于您部署Label Studio的操作系统和环境。

在*nix操作系统中,您可以通过命令行或环境设置文件来配置环境变量。例如:

export LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED=true

备注

如果您使用Docker,可以将所有环境变量写入.env文件。

在Windows系统上,您可以使用以下语法:

set LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED=true

要检查是否成功设置了环境变量,请在*nix操作系统上运行以下命令:

echo $LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED

或者在Windows操作系统上执行以下操作:

echo %LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED%

在本地主机上使用不同端口运行Label Studio

默认情况下,Label Studio运行在8080端口。如果该端口已被占用或您想指定其他端口,请使用以下命令启动Label Studio:

label-studio start --port <port>

例如,在端口9001上启动Label Studio:

label-studio start --port 9001

或者,设置以下环境变量:

LABEL_STUDIO_PORT = 9001

在Docker上使用不同端口运行Label Studio

要在Docker上运行Label Studio并使用非默认8080端口,请在启动Label Studio时指定端口参数。例如,要在Docker容器中启动Label Studio并通过9001端口访问,请运行以下命令:

docker run -it -p 9001:8080 -v $(pwd)/mydata:/label-studio/data heartexlabs/label-studio:latest label-studio

重要

由于这是一个非根容器,挂载的文件和目录必须具有UID 1001的适当权限。

或者,如果您正在使用Docker Compose,请更新您正在使用的docker-compose.yml文件,为用于代理连接到Label Studio的NGINX服务器暴露不同的端口。例如,docker-compose.yml文件的这部分内容将代理Label Studio的端口从80改为9001:

...
nginx:
    image: nginx:latest
    ports:
      - 9001:80
    depends_on:
      - app
...

在Docker上运行Label Studio并配置主机与子路径

要在Docker上通过主机和子路径运行Label Studio,只需将带有子路径的LABEL_STUDIO_HOST环境变量传递给docker/docker-compose:

LABEL_STUDIO_HOST=http://localhost:8080/foo docker-compose up -d

使用ngrok将本地Label Studio实例暴露到外部

有时,让运行在本地机器上的LabelStudio实例能够通过互联网访问会很有用。

一种实现方法是使用ngrok,这是一个反向代理工具,可以让您将实例暴露在互联网上。

  1. 安装 ngrok: 遵循官方 ngrok 指南
  2. 如果是首次运行ngrok,请先进行身份验证(令牌可从Ngrok控制面板获取):ngrok config add-authtoken <您的令牌>
  3. 启动 ngrok 并将其指向 Label Studio:ngrok http --host-header=rewrite 8080
  4. 复制ngrok显示的Forwarding转发URL。例如:https://xx-xx-xx-xx.eu.ngrok.io
  5. 在启动时将这个URL传递给Label Studio:
# python instance
LABEL_STUDIO_HOST=https://xx-xx-xx-xx.eu.ngrok.io label-studio start
# docker container
docker run -it -e LABEL_STUDIO_HOST=https://xx-xx-xx-xx.eu.ngrok.io -p 8080:8080 -v <yourvolume>:/label-studio/data heartexlabs/label-studio:latest

重要

由于这是一个非根容器,挂载的文件和目录必须具有UID 1001的适当权限。

# docker-compose
LABEL_STUDIO_HOST=https://xx-xx-xx-xx.eu.ngrok.io docker-compose up -d
  1. 在浏览器中打开ngrok URL,确保能看到你的实例
  2. 完成

在Docker上运行Label Studio并使用本地存储

要在Docker上运行Label Studio并引用持久化的本地存储目录,请在启动Label Studio时将这些目录挂载为卷,并指定所需的任何环境变量。

以下命令启动一个带有Label Studio最新镜像的Docker容器,端口为8080,并设置了一个环境变量使Label Studio能够访问本地文件。在此示例中,本地目录./myfiles被挂载到/label-studio/files位置。

docker run -it -p 8080:8080 -v $(pwd)/mydata:/label-studio/data \
--env LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED=true \ 
--env LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT=/label-studio/files \ 
-v $(pwd)/myfiles:/label-studio/files \
heartexlabs/label-studio:latest label-studio

重要

由于这是一个非根容器,挂载的文件和目录必须具有UID 1001的适当权限。

通过指定环境变量LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT=/label-studio/files,Label Studio仅扫描该目录以查找本地文件。强烈建议明确指定LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT路径,以确保从Docker容器到本地机器的卷访问安全。

将文件放置在指定的源目录中(本例中为./myfiles),并在设置本地存储时引用该目录。有关在Docker中使用卷挂载的更多信息,请参阅Docker卷文档

如果您使用Docker Compose,请在Docker Compose YAML文件中指定卷,并将相关环境变量添加到应用容器中。有关在Docker Compose中指定卷的更多信息,请参阅Docker Compose文件文档中的卷部分。

使用HTTPS运行Label Studio

要在浏览器中通过HTTPS运行Label Studio并访问其网页服务器,请使用NGINX或其他网页服务器为Label Studio配置HTTPS。

使用Heroku在云端运行Label Studio

要在云端使用Heroku运行Label Studio,请指定一个环境变量以便Label Studio加载。

LABEL_STUDIO_HOST

如果需要,您可以为Label Studio指定不同的主机名,但这不是必须的。

要在Heroku上运行Label Studio并使用PostgreSQL作为数据库存储,请指定作为Heroku环境变量DATABASE_URL一部分所需的PostgreSQL环境变量。例如,要指定托管在Amazon上的PostgreSQL数据库:

DATABASE_URL = postgres://username:password@hostname.compute.amazonaws.com:5432/dbname

然后您可以将PostgreSQL连接所需的环境变量指定为配置变量。请参阅Database storage

我们的Heroku清单默认使用了postgresql插件。 请注意存储容量是有限的。

请注意,由于文件系统是临时的,通过导入上传的所有数据在 dyno 替换后都会丢失。建议使用 S3 存储。

使用外部域名运行Label Studio

如果您希望多人协作完成一个项目,您可能需要使用外部域名运行Label Studio。

要实现这一点,请在启动Label Studio时使用host参数。这些参数能确保在导入资源文件(如图片、音频等)和生成标注任务时创建正确的URL。

有几种可能的方式可以通过外部域名运行Label Studio。

  • 将您通过--config选项指定的文件中的host参数替换掉。如果您没有使用--config,则编辑Label Studio包目录下的label_studio/utils/schema/default_config.json文件。
  • 启动Label Studio时指定参数:label-studio start --host http://your.domain.com/ls-root
  • 将参数指定为环境变量 HOST,特别是在设置 Docker 时:HOST=https://your.domain.com:7777

或者,您可以使用环境变量:

LABEL_STUDIO_HOST = https://subdomain.example.com:7777

您必须为域名指定协议:http://https://

如果外部主机有端口,请将端口指定为主机名的一部分。

为您的项目设置任务抽样

当你启动Label Studio时,可以控制特定项目中任务展示给标注人员的顺序。

例如,要创建一个为标注者提供顺序任务排序的项目:

label-studio start <project_name> --sampling sequential

下表列出了可用的采样选项:

选项 描述
sequential Default. Tasks are shown to annotators in ascending order by the id field.
uniform 任务以均等概率进行采样。
prediction-score-min 向标注者展示预测分数平均值最低的任务。要使用此选项,您必须在导入Label Studio的任务数据中包含预测数据。

您也可以通过API为特定项目设置采样。向/api/projects/端点发送PATCH请求,即可为指定项目设置采样。详情请参阅项目API参考文档

单个标注者也可以通过调整Label Studio界面中标注任务的筛选和排序来控制标注任务的顺序。详见设置标注项目