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

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

我正在尝试为 Label Studio 实现一个预标记器。文档(例如 https://labelstud.io/guide/ml_create.html#Example-inference-call)在这里不是很有帮助。我已在本地导入图像,需要从任务记录中读取它们以将它们传递到我的模型。当我打印任务记录时,它看起来像这样:

{
  "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 是在某个存储空间内旋转的。我如何访问这个? (而且为什么文档里没有讲这个……)

python machine-learning data-annotations label-studio
2个回答
0
投票

这些是您上传一些日期时创建的 fils label studio。

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

或者如果你在 docker 上运行它,你会发现它位于相同的路径下。

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

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

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


0
投票

假设您在本地主机上,它应该是:

http://localhost:8080/data/upload/1/cfcf4486-0cdd1413486f7d923e6eff475c43809f.jpeg

下一个问题可能是:如何从预测/拟合调用中确定 LabelStudios IP 地址?这至少是我目前所坚持的。

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