Ejemplo n.º 1
0
    def save(self, vo: LabelVO):
        label = LabelEntity.create(name=vo.name,
                                   color=vo.color,
                                   dataset=vo.dataset)
        vo.id = label.get_id()

        return vo
Ejemplo n.º 2
0
    def fetch_all(self, entity_id: int):
        anns = AnnotationEntity.alias()
        lbl = LabelEntity.alias()
        query = (
            anns.select(
                anns.id.alias("annot_id"),
                anns.entry.alias("annot_entry"),
                anns.kind.alias("annot_kind"),
                anns.points.alias("annot_points"),
                lbl.id.alias("label_id"),
                lbl.name.alias("label_name"),
                lbl.color.alias("label_color")
            )
                .join(lbl, on=(anns.label == lbl.id), join_type="LEFT")
                .where(anns.entry == entity_id)
        )
        cursor = query.dicts().execute()
        result = []
        for row in cursor:
            ann_vo = AnnotaVO()
            ann_vo.id = row["annot_id"]
            ann_vo.entry = row["annot_entry"]
            ann_vo.kind = row["annot_kind"]
            ann_vo.points = row["annot_points"]
            ann_vo.label = None
            if row["label_id"]:
                label = LabelVO()
                label.id = row["label_id"]
                label.name = row["label_name"]
                label.color = row["label_color"]
                ann_vo.label = label
            result.append(ann_vo)

        return result
Ejemplo n.º 3
0
 def get_label(self, entity_id: int):
     dse = DatasetEntryEntity.alias()
     lbl = LabelEntity.alias()
     query = (dse.select(lbl.name).join(
         lbl, on=(dse.label == lbl.id)).where(dse.id == entity_id))
     result = list(query.dicts().execute())
     return result[0]["name"] if len(result) > 0 else None
Ejemplo n.º 4
0
 def fetch_all(self, ds_id):
     cursor = LabelEntity.select().where(LabelEntity.dataset == ds_id).dicts().execute()
     result = []
     for ds in list(cursor):
         vo = LabelVO()
         result.append(vo)
         for k, v in ds.items():
             setattr(vo, k, v)
     return result
Ejemplo n.º 5
0
 def fetch_entries_for_classification(self, ds_id):
     en: DatasetEntryEntity = DatasetEntryEntity.alias("en")
     lbl: LabelEntity = LabelEntity.alias("lbl")
     query = (en.select(en.file_path,
                        lbl.name).join(lbl,
                                       JOIN.INNER,
                                       on=en.label == lbl.id).where(
                                           en.dataset == ds_id
                                           and en.label.is_null(False)))
     cursor = query.dicts().execute()
     return list(cursor)
Ejemplo n.º 6
0
    def fetch_labels(self, dataset_id: int = None):
        e = DatasetEntryEntity.alias("e")
        l = LabelEntity.alias("l")
        query = (e.select(
            e.file_path.alias("image"), l.name.alias("label")).join(
                l, on=(e.label == l.id)).where((e.dataset_id == dataset_id)
                                               & (e.label.is_null(False))))
        cursor = query.dicts().execute()
        result = []
        for row in cursor:
            result.append(row)

        return result
Ejemplo n.º 7
0
 def find_by_name(self, ds_id, label_name):
     query = (
         LabelEntity.select().where((LabelEntity.dataset == ds_id)
                                    & (LabelEntity.name == label_name)))
     # print(query)
     cursor = query.dicts().execute()
     result = list(cursor)
     vo = LabelVO()
     if len(result) > 0:
         row = result[0]
         for k, v in row.items():
             setattr(vo, k, v)
         return vo
     return None
Ejemplo n.º 8
0
    def fetch_all_by_dataset(self, dataset_id: int = None):
        a = AnnotationEntity.alias("a")
        i = DatasetEntryEntity.alias("i")
        l = LabelEntity.alias("l")

        query = (a.select(
            i.file_path.alias("image"), a.kind.alias("annot_kind"),
            a.points.alias("annot_points"), l.name.alias("label_name"),
            l.color.alias("label_color")).join(i, on=(a.entry == i.id)).join(
                l, on=(a.label == l.id),
                join_type="LEFT").where(i.dataset == dataset_id))
        cursor = query.dicts().execute()
        result = []
        for row in cursor:
            result.append(row)

        return result
Ejemplo n.º 9
0
    def fetch_all_by_dataset(self, dataset_id: int = None):
        ann = AnnotationEntity.alias("a")
        ds_entry = DatasetEntryEntity.alias("i")
        lbl = LabelEntity.alias("l")
        query = (ann.select(ds_entry.file_path.alias("image"),
                            ann.kind.alias("annot_kind"),
                            ann.points.alias("annot_points"),
                            lbl.name.alias("label_name"),
                            lbl.color.alias("label_color")).join(
                                ds_entry, on=(ann.entry == ds_entry.id)).join(
                                    lbl,
                                    on=(ann.label == lbl.id),
                                    join_type=JOIN.LEFT_OUTER).where(
                                        ds_entry.dataset == dataset_id))
        cursor = query.dicts().execute()
        result = []
        for row in cursor:
            result.append(row)

        return result
Ejemplo n.º 10
0
 def delete(self, id: int):
     result = LabelEntity.delete_by_id(id)
     DatasetEntryEntity.update(label=None).where(DatasetEntryEntity.label == id).execute()
     return result