如何正确配置label-studio以使用redis作为数据源(在docker中)

问题描述 投票:0回答:1

我正在尝试为数据科学项目设置一个 Docker 堆栈,并且我想使用 Redis 来让服务交换数据。

我遵循了label studio提供的文档,但缺少很多细节,我的实现不起作用。

具体来说:label studio 能够将 redis 注册为数据源,但不能注册为数据目标,并且作为源,它不会检索我的任务数据。

我尝试过的

我的 Docker 撰写文件

我删除了所有与 label-studio 无关的服务,并且有一个用于变量的 .env 文件。
postgres 部分工作正常,但我将其保留在示例中,因为它是 redis 配置的一部分。

services:
  postgres:
    image: postgres:16-alpine
    container_name: postgres
    ports:
      - ${POSTGRES_PORT}:5432
    environment:
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - PGDATA=/var/lib/postgresql/data/pgdata
      - POSTGRES_PORT=${POSTGRES_PORT}
    healthcheck:
      test: ["CMD-SHELL", "pg_isready", "-d", "postgres"]
      interval: 10s
      timeout: 10s
      retries: 120
    volumes:
      - pgdata:/var/lib/postgresql/data:Z

  redis:
    image: redis:5-alpine
    container_name: redis
    ports:
      - 6379:6379
    volumes:
      - redisdata:/data
    healthcheck:
      test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
      interval: 10s
      timeout: 10s
      retries: 120
    command: [ "redis-server",
               "--save", "60", "1",
               "--loglevel", "debug",
               "--requirepass", "${REDIS_PASSWORD}"]

  label-studio:
    image: heartexlabs/label-studio:latest
    container_name: label-studio
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    ports:
      - 8081:8080
    environment:
      - DJANGO_DB=default
      - POSTGRE_HOST=postgres
      - POSTGRE_PORT=${POSTGRE_PORT}
      - POSTGRE_NAME=${POSTGRE_NAME}
      - POSTGRE_USER=${POSTGRE_USER}
      - POSTGRE_PASSWORD=${POSTGRE_PASSWORD}
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - REDIS_LOCATION=redis:6379
      - REDIS_DB=0
      - REDIS_PASSWORD=${REDIS_PASSWORD}
    volumes:
      - lsdata:/label-studio/data
    command: ["label-studio",
              "--log-level", "DEBUG"]

volumes:
  pgdata:
    driver: local
  redisdata:
    driver: local
  lsdata:
    driver: local

Redis

Redis 运行,并且有任务数据,我测试了以下格式

labelstudio:ls-task-1 '{"text":"some text"}'
labelstudio:ls-task-2 '{"id":0, "data": {"texte": "some text"}} 


ls-task-1 '{"text":"some text"}'
ls-task-2 '{"id":0, "data": {"texte": "some text"}} 

标签工作室

标签接口配置

<View>
  <Text name="text" value="$text"/>
  <View style="box-shadow: 2px 2px 5px #999; padding: 20px; margin-top: 2em; border-radius: 5px;">
    <Header value="Some themes"/>
    <Choices name="theme" toName="text" choice="multiple" showInLine="true">
      <Choice value="somevalue">Some Choice</Choice>
      <Choice value="othervalue">Other Choice/Choice>
    </Choices>
  </View>
</View>
<!-- {
  "data": {"text": "Some Text"}
} -->

云存储配置

存储类型:Redis
路径:labelstudio
密码:
主持人:redis
端口:6379

它是如何失败的

作为数据源

我在日志中看到标签工作室连接到redis,但它总是显示0个任务

标签工作室日志

[2024-07-11 08:46:24,606] [urllib3.connectionpool::_make_request::474] [DEBUG] https://o227124.ingest.sentry.io:443 "POST /api/5820521/envelope/ HTTP/1.1" 200 2
[2024-07-11 08:46:43,954] [io_storages.base_models::sync::454] [INFO] Start syncing storage RedisImportStorage object (1)
[2024-07-11 08:46:43,964] [projects.models::_update_tasks_states::422] [INFO] Starting _update_tasks_states with params: Project risque-juridique (id=1) maximum_annotations 1 and percentage 100
[2024-07-11 08:46:43,971] [urllib3.connectionpool::_new_conn::1019] [DEBUG] Starting new HTTPS connection (1): tele.labelstud.io:443
[2024-07-11 08:46:43,971] [django.server::log_message::161] [INFO] "POST /api/storages/redis/1/sync HTTP/1.1" 200 618
[2024-07-11 08:46:43,971] [django.server::log_message::161] [INFO] "POST /api/storages/redis/1/sync HTTP/1.1" 200 618
[2024-07-11 08:46:44,454] [urllib3.connectionpool::_make_request::474] [DEBUG] https://tele.labelstud.io:443 "POST / HTTP/1.1" 200 0
[2024-07-11 08:47:24,609] [urllib3.connectionpool::_make_request::474] [DEBUG] https://o227124.ingest.sentry.io:443 "POST /api/5820521/envelope/ HTTP/1.1" 200 2

redis 日志

11 Jul 2024 08:46:43.953 - Accepted 192.168.48.6:42558
11 Jul 2024 08:46:43.954 - Client closed connection
11 Jul 2024 08:46:43.963 - Accepted 192.168.48.6:42564
11 Jul 2024 08:46:43.964 - Client closed connection
11 Jul 2024 08:46:45.526 - Accepted 127.0.0.1:57774
11 Jul 2024 08:46:45.526 - Client closed connection

作为数据目标

Label工作室表演

Runtime error
Validation error

    validate_connection is not implemented

Version: 1.12.1
标签工作室日志
[2024-07-11 08:51:29,742] [core.utils.common::custom_exception_handler::89] [ERROR] c9a7909a-c865-4f8a-813b-3a4e7918d9a5 [ErrorDetail(string='validate_connection is not implemented', code='invalid')]
Traceback (most recent call last):
  File "/label-studio/label_studio/io_storages/api.py", line 82, in perform_create
    instance.validate_connection()
  File "/label-studio/label_studio/io_storages/base_models.py", line 218, in validate_connection
    raise NotImplementedError('validate_connection is not implemented')
NotImplementedError: validate_connection is not implemented

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/django/utils/decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/rest_framework/generics.py", line 242, in post
    return self.create(request, *args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/rest_framework/mixins.py", line 19, in create
    self.perform_create(serializer)
  File "/label-studio/label_studio/io_storages/api.py", line 84, in perform_create
    raise ValidationError(exc)
rest_framework.exceptions.ValidationError: [ErrorDetail(string='validate_connection is not implemented', code='invalid')]
[2024-07-11 08:51:29,748] [django.request::log_response::224] [WARNING] Bad Request: /api/storages/export/redis
[2024-07-11 08:51:29,748] [django.request::log_response::224] [WARNING] Bad Request: /api/storages/export/redis
[2024-07-11 08:51:29,748] [urllib3.connectionpool::_new_conn::1019] [DEBUG] Starting new HTTPS connection (1): tele.labelstud.io:443
[2024-07-11 08:51:29,749] [django.server::log_message::161] [WARNING] "POST /api/storages/export/redis?project=1 HTTP/1.1" 400 210
[2024-07-11 08:51:29,749] [django.server::log_message::161] [WARNING] "POST /api/storages/export/redis?project=1 HTTP/1.1" 400 210
docker redis label-studio
1个回答
0
投票

看起来,开发人员还没有编写验证功能。或者他们可能故意在函数中引发异常。但没有任何评论或解释。如果可以,请按照 Label Studio 代码存储库中的以下路径进行操作,并查看您的版本是否存在函数定义。如果没有,您可以尝试删除异常引发,或者进行存根定义并查看

redis
是否已连接(即作为数据源导入/导出)。

但我认为存根该方法是行不通的,因为在

model
类中,他们也留下了一堆没有定义的其他函数。

您可以尝试抑制类方法中引发的所有异常,但我认为这不会起作用。我自己没有尝试将

redis
作为数据 I/O 源,所以我不确定您将如何实现 方法定义

抛出异常的文件位于以下路径:

  • {Label Studio root}/label_studio/io_storages/base_models.py

这是第

217
行的代码,我指的是: enter image description here

PS:我正在写答案,因为我必须提供图像作为支持文档。而且解释真的太长了,必须分成多个评论。

© www.soinside.com 2019 - 2024. All rights reserved.