Example #1
0
def get_voc_label_tree(dbm):
    tree = LabelTree(dbm)
    df = pd.read_csv('/code/backend/lost/pyapi/examples/label_trees/pascal_voc2012.csv')
    root = tree.import_df(df)
    if root is None:
        name = df[df['parent_leaf_id'].isnull()]['name'].values[0]
        tree = LabelTree(dbm, name=name)
    return tree
Example #2
0
    def test_import_df(self, tree_plus_childs):
        df = tree_plus_childs.to_df()
        df2 = df.copy()
        root_idx = df2[df2['parent_leaf_id'].isnull()].index.values[0]
        no_root_idx = df2[~df2['parent_leaf_id'].isnull()].index
        df2.loc[root_idx, 'name'] = 'second tree'
        df2.loc[root_idx, 'idx'] = 0
        df2.loc[no_root_idx, 'parent_leaf_id'] = 0

        dbm = DBMan(config.LOSTConfig())
        tree2 = LabelTree(dbm)
        root_leaf = tree2.import_df(df2)
        if root_leaf is None:
            raise Exception(
                'A label tree with name "{}" already exists. Clean your Test Database!'
                .format(df2.loc[root_idx, 'name']))
        for key, val in tree2.tree.items():
            print(val.to_df()[['idx', 'name', 'external_id',
                               'parent_leaf_id']])
        for ll in tree2.root.label_leaves:
            assert ll.name == CHILD_COW_NAME or ll.name == CHILD_HORSE_NAME
        tree2.delete_tree()
Example #3
0
#!/usr/bin/env python3

import argparse
from lost.db import model, access
from lost.logic import config
from lost.logic.label import LabelTree
import logging
import os
import pandas as pd

logging.basicConfig(level=logging.INFO, format='(%(levelname)s): %(message)s')

if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description='Import a label tree into this lost instance')
    parser.add_argument('csv_file',
                        nargs='?',
                        action='store',
                        help='Path to the label tree in csv style.')
    # parser.add_argument('group_name', nargs='?', action='store',
    #                     help='Name of group that pipeline should be visible for.')
    args = parser.parse_args()

    lostconfig = config.LOSTConfig()
    dbm = access.DBMan(lostconfig)
    tree = LabelTree(dbm, logger=logging)
    df = pd.read_csv(args.csv_file)
    if tree.import_df(df) is None:
        logging.warning('LabelTree already present in database! {}'.format(
            args.csv_file))
    dbm.close_session()