繁体   English   中英

Label Studio:访问任务记录中指定的文件

[英]Label Studio: Access file specified in task record

我正在尝试为 Label Studio 实施预标记器。 文档(例如https://labelstud.io/guide/ml_create.html#Example-inference-call )在这里不是很有帮助。 我在本地导入了图片,需要从一个任务记录中读取出来传给我的model。当我打印一个任务记录时,它是这样的:

{
  "id": 7,
  "data": {
    "image": "/data/upload/1/cfcf4486-0cdd1413486f7d923e6eff475c43809f.jpeg"
  },
  "meta": {},
  "created_at": "2022-12-29T00:49:34.141715Z",
  "updated_at": "2022-12-29T00:49:34.141720Z",
  "is_labeled": false,
  "overlap": 1,
  "inner_id": 7,
  "total_annotations": 0,
  "cancelled_annotations": 0,
  "total_predictions": 0,
  "comment_count": 0,
  "unresolved_comment_count": 0,
  "last_comment_updated_at": null,
  "project": 1,
  "updated_by": null,
  "file_upload": 7,
  "comment_authors": [],
  "annotations": [],
  "predictions": []
}

我目前的贴标机实现是这样的:

class MyModel(LabelStudioMLBase):
    def __init__(self, **kwargs):
        super(MyModel, self).__init__(**kwargs)
        self.model = ...
        self.query_fn = ...

    def make_result_record(self, path: Path):
        # Reference: https://labelstud.io/tutorials/sklearn-text-classifier.html

        mask = self.query_fn(path)
        image = Image.open(path)
        result = [
            {
                "original_width": image.width,
                "original_height": image.height,
                "image_rotation": 0,
                "value": {"format": "rle", "rle": [mask], "brushlabels": ["crack"]},
                "id": uuid(),
                "from_name": "tag",
                "to_name": "image",
                "type": "brushlabels",
                "origin": "inference",
            }
        ]
        return {"result": result, "score": 1.0}

    def predict(self, tasks, **kwargs):
        predictions = []
        for task in tasks:
            logger.info("task:")
            logger.info("\n" + json.dumps(task, indent=2))
            result = self.make_result_record(Path(task["data"]["image"]))
            predictions.append(result)
        return predictions

那么/data/upload/1/cfcf4486-0cdd1413486f7d923e6eff475c43809f.jpeg在哪里? 我想 Label Studio 是在一些存储空间中启动的。 我如何访问它? (还有为什么文档不讲这个……)

这些是 label 工作室在您上传一些日期时创建的文件。

如果您尝试搜索文件名“cfcf4486-0cdd1413486f7d923e6eff475c43809f.jpeg”,您会在系统中找到它

或者,如果您在 docker 上运行它,您会在同一路径下找到它。

在我的 macOS 案例中,我在以下位置找到了 .jpg 文件:“/Users/user/Library/Application Support/label-studio/media/upload/1/1deaeb75-0f29e9df11dbc1cce55cb3529517dcd5.jpg”

我认为您不需要从任务中阅读它们。 如果您创建一个 ml-backend 并将其连接到您的 label-studio,您的 label.s 将为您创建并发送任务。

看看这个后端,例如: https://www.kaggle.com/code/yujiyamamoto/semi-auto-annotation-label-studio-and-tf2-od/notebook

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM