예제 #1
0
 def __init__(self, pe, dbm):
     self._dbm = dbm  #type: lost.db.access.DBMan
     self._lostconfig = dbm.lostconfig
     self._pipe_element = pe
     self._pipe = self._dbm.get_pipe(pipe_id=self._pipe_element.pipe_id)
     self._pipe_man = pipe_model.PipeEngine(self._dbm, self._pipe)
     self._inp = inout.Input(self)
     self._outp = inout.Output(self)
     self._fm = file_man.FileMan(self._lostconfig)
     self._pipe_info = PipeInfo(self._pipe, dbm)
예제 #2
0
파일: service.py 프로젝트: kengggg/lost
    def __init__(self, db_man, pipe_id):
        self.db_man = db_man
        self.result_links = list()
        self.visual_outputs = list()
        self.data_exports = list()
        self.datasources = list()
        self.loops = list()
        self.two_d_annotations = list()
        self.image_annotations = list()
        self.results = list()
        self.required_label_leaves = list()
        self.choosen_anno_tasks = list()
        self.anno_tasks = list()
        self.pipe = self.db_man.get_pipe(pipe_id=pipe_id)
        self.pipe_elements = self.db_man.get_pipe_elements(pipe_id=pipe_id)
        self.file_man = file_man.FileMan(db_man.lostconfig)

        # Stop pipeline - so cron won't touch it.
        self.pipe.state = state.Pipe.DELETED 
        db_man.save_obj(self.pipe)

        for pe in self.pipe_elements:
            anno_task = self.db_man.get_anno_task(pipe_element_id=pe.idx)
            if anno_task:
                self.anno_tasks.append(anno_task)
            for result_link in self.db_man.get_resultlinks_pe_n(pe_n_id=pe.idx):
                if result_link not in self.result_links:
                    self.result_links.append(result_link)
                if result_link.result not in self.results:
                    if result_link.result:
                        self.results.append(result_link.result)
            loop = self.db_man.get_loop(pipe_element_id=pe.idx)
            if loop:
                self.loops.append(loop)
            datasource = self.db_man.get_datasource(pipe_element_id=pe.idx)
            if datasource:
                self.datasources.append(datasource)
        for anno_task in self.anno_tasks:
            
            for ch_anno_task in self.db_man.get_choosen_annotask(anno_task_id=anno_task.idx):
                self.choosen_anno_tasks.append(ch_anno_task)
            
            for leaf in self.db_man.get_all_required_label_leaves(anno_task_id=anno_task.idx):
                self.required_label_leaves.append(leaf)

            for image_annotation in self.db_man.get_image_annotations(anno_task_id=anno_task.idx):
                self.image_annotations.append(image_annotation)
                for two_d_anno in self.db_man.get_two_d_annotations(img_anno_id=image_annotation.idx):
                    self.two_d_annotations.append(two_d_anno)
        for result in self.results:
            for data_export in self.db_man.get_data_exports(result_id=result.idx):
                self.data_exports.append(data_export)
            for visual_output in self.db_man.get_visual_outputs(result_id=result.idx):
              self.visual_outputs.append(visual_output)
예제 #3
0
파일: initlost.py 프로젝트: yc10086/lost
def main():
    lostconfig = config.LOSTConfig()
    project_root = join(lostconfig.project_path, "data")
    if not os.path.exists(project_root):
        os.makedirs(project_root)
    fman = file_man.FileMan(lostconfig)
    fman.create_project_folders()
    # Create Tables
    dbm = access.DBMan(lostconfig)
    dbm.create_database()
    create_first_user(dbm)
    dbm.close_session()
예제 #4
0
 def _get_lds_fm(self, df, fm_cache=dict(), fm=None):
     if 'img_fs_name' in df:
         fs_name = df['img_fs_name'].values[0]
         if not fs_name:
             if fm is not None:
                 return fm
             fs_name = 'lost_data'
     else:
         if fm is not None:
             return fm
         fs_name = 'lost_data'
     if fs_name in fm_cache:
         return fm_cache[fs_name]
     else:
         fs_db = self._script._dbm.get_fs(name=fs_name)
         # fs = DummyFileMan(fs_db)
         fm = file_man.FileMan(fs_db=fs_db)
         fm_cache[fs_name] = fm
         return fm
예제 #5
0
 def _add_annos(self,
                pe,
                img_path,
                img_labels=None,
                img_sim_class=None,
                annos=[],
                anno_types=[],
                anno_labels=[],
                anno_sim_classes=[],
                frame_n=None,
                video_path=None,
                anno_task_id=None,
                fs=None,
                img_meta=None,
                anno_meta=None):
     '''Add annos in list style to an image.
     
     Args:
         pe (PipeElement): The connected PipeElement where annotation should be provided for.
         img_path (str): Path to the image where annotations are added for.
         img_labels (list of int or str): Labels that will be assigned to the image. The label should
             represented by a label_leaf_id or label_name.
         img_sim_class (int): A culster id that will be used to cluster this image
             in the MIA annotation tool.
         annos (list of list): A list of
             POINTs: [x,y]
             BBOXes: [x,y,w,h]
             LINEs or POLYGONs: [[x,y], [x,y], ...]
         anno_types (list of str): Can be 'point', 'bbox', 'line', 'polygon'
         anno_labels (list of int): Labels for the twod annos. 
             Each label in the list is represented by a label_leaf_id.
             (see also :class:`model.LabelLeaf`).
         anno_sim_classes (list of ints): List of arbitrary cluster ids 
             that are used to cluster annotations in the MIA annotation tool.
         frame_n (int): If *img_path* belongs to a video *frame_n* indicates
             the framenumber.
         video_path (str): If *img_path* belongs to a video this is the path to
             this video.
         anno_task_id (int): Id of the assigned annotation task.
         fs (obj): The filesystem where image is located. 
             User lost standard filesystem if no filesystem was given.
             You can get this Filesystem object from a DataSource-Element by calling
             get_fs method. 
         img_meta (dict): Dictionary with meta information that should be added to the
             image annotation. Each meta key will be added as column during annotation export. 
             the dict-value will be row content.
         anno_meta (list of dict): List of dictionaries with meta information that 
             should be added to a specific annotation. Each meta key will be 
             added as column during annotation export. The dict-value will be row content.
     '''
     if img_sim_class is None:
         img_sim_class = 1
     if video_path is not None:
         video_path = self._script.get_rel_path(video_path)
     if fs is None:
         fs_db = self._script._dbm.get_fs(name='lost_data')
         fs = DummyFileMan(fs_db)
     fm = file_man.FileMan(fs_db=fs.lost_fs)
     rel_img_path = fm.make_path_relative(img_path)
     img_anno = model.ImageAnno(
         anno_task_id=anno_task_id,
         img_path=rel_img_path,
         abs_path=os.path.join(fm.root_path, rel_img_path),
         state=state.Anno.UNLOCKED,
         result_id=self._result_map[pe.idx],
         iteration=self._script._pipe_element.iteration,
         frame_n=frame_n,
         video_path=video_path,
         sim_class=img_sim_class,
         fs_id=fs.lost_fs.idx)
     if img_meta is not None:
         img_anno.meta = json.dumps(img_meta, default=_json_default)
     self._script._dbm.add(img_anno)
     if img_labels is not None:
         self._update_labels(img_labels, img_anno)
     if len(annos) != len(anno_types):
         raise ValueError(
             '*anno_types* and *annos* need to be of same size!')
     for i, vec in enumerate(annos):
         anno = model.TwoDAnno(
             iteration=self._script._pipe_element.iteration,
             anno_task_id=anno_task_id,
             state=state.Anno.UNLOCKED)
         if anno_meta is not None:
             if len(annos) != len(anno_meta):
                 raise ValueError(
                     '*anno_meta* and *annos* need to be of same size!')
             anno.meta = json.dumps(anno_meta[i], default=_json_default)
         if anno_types[i] == 'point':
             anno.point = vec
         elif anno_types[i] == 'bbox':
             anno.bbox = vec
         elif anno_types[i] == 'line':
             anno.line = vec
         elif anno_types[i] == 'polygon':
             anno.polygon = vec
         if anno_labels:
             if len(anno_labels) != len(annos):
                 raise ValueError(
                     '*anno_labels* and *annos* need to be of same size!')
             label_leaf_ids = anno_labels[i]
             self._update_labels(label_leaf_ids, anno)
         if anno_sim_classes:
             if len(anno_sim_classes) != len(annos):
                 raise ValueError(
                     '*anno_sim_classes* and *annos* need to have same size!'
                 )
             anno.sim_class = anno_sim_classes[i]
         else:
             anno.sim_class = 1
         img_anno.twod_annos.append(anno)