Eric Tröbs 4 lat temu
rodzic
commit
1bea200535

+ 25 - 0
pycs/pipeline/Fit.py

@@ -0,0 +1,25 @@
+from pycs.pipeline.Job import Job
+
+
+class Fit(Job):
+    def __init__(self, project_id: str, data: dict):
+        super().__init__(project_id, data)
+
+        self.result = []
+        for identifier in data['predictionResults']:
+            if data['predictionResults'][identifier]['origin'] != 'user':
+                continue
+
+            copy = data['predictionResults'][identifier].copy()
+            del copy['id']
+            del copy['origin']
+
+            # TODO remove and add in webui endpoint
+            if 'x' not in copy:
+                copy['type'] = 'labeled-image'
+            elif 'label' in copy:
+                copy['type'] = 'labeled-bounding-box'
+            else:
+                copy['type'] = 'bounding-box'
+
+            self.result.append(copy)

+ 4 - 13
pycs/pipeline/Job.py

@@ -1,19 +1,10 @@
-from os import path, getcwd
+from os import path
 from uuid import uuid1
 
 
 class Job:
-    def __init__(self, type: str, project_id: str, data: dict):
+    def __init__(self, project_id: str, data: dict):
         self.id = uuid1()
-        self.type = type
-        self.object_id = data['id']
-        self.object_relative_path = path.join('projects',
-                                              project_id,
-                                              'data',
-                                              data['id'] + data['extension'])
-        self.object_full_path = path.join(getcwd(),
-                                          'projects',
-                                          project_id,
-                                          'data',
-                                          data['id'] + data['extension'])
+        self.type = data['type']
+        self.path = path.join('projects', project_id, 'data', data['id'] + data['extension'])
         self.size = data['size']

+ 36 - 3
pycs/pipeline/Pipeline.py

@@ -1,4 +1,6 @@
-from pycs.pipeline import Result
+from typing import List
+
+from pycs.pipeline.Fit import Fit
 from pycs.pipeline.Job import Job
 
 
@@ -21,7 +23,7 @@ class Pipeline:
         """
         raise NotImplementedError
 
-    def execute(self, job: Job) -> Result:
+    def execute(self, job: Job) -> List[dict]:
         """
         receive a job, execute it and return the predicted result
 
@@ -31,5 +33,36 @@ class Pipeline:
         raise NotImplementedError
 
     # TODO documentation
-    def fit(self, data):
+    def fit(self, fit: List[Fit]):
         raise NotImplementedError
+
+    # TODO documentation
+    @staticmethod
+    def create_labeled_image_result(label):
+        return {
+            'type': 'labeled-image',
+            'label': label
+        }
+
+    # TODO documentation
+    @staticmethod
+    def create_bounding_box_result(x, y, w, h):
+        return {
+            'type': 'bounding-box',
+            'x': x,
+            'y': y,
+            'w': w,
+            'h': h
+        }
+
+    # TODO documentation
+    @staticmethod
+    def create_labeled_bounding_box_result(x, y, w, h, label):
+        return {
+            'type': 'labeled-bounding-box',
+            'x': x,
+            'y': y,
+            'w': w,
+            'h': h,
+            'label': label
+        }

+ 6 - 41
pycs/pipeline/PipelineManager.py

@@ -2,6 +2,7 @@ from os import path
 
 from eventlet import tpool
 
+from pycs.pipeline.Fit import Fit
 from pycs.pipeline.Job import Job
 
 
@@ -24,58 +25,22 @@ class PipelineManager:
     def run(self, media_file):
         # create job list
         # TODO update job progress
-        job = Job('detect-faces', self.project['id'], media_file)
+        job = Job(self.project['id'], media_file)
         result = tpool.execute(lambda p, j: p.execute(j), self.pipeline, job)
 
         # remove existing pipeline predictions from media_fle
         media_file.remove_pipeline_results()
 
         # add new predictions
-        for prediction in result.predictions:
+        for prediction in result:
             media_file.add_result(prediction, origin='pipeline')
 
     def fit(self):
         print('PipelineManager', 'fit')
-
         data = []
-        for identifier in self.project['data']:
-            obj = self.project['data'][identifier]
-            media = {
-                'type': obj['type'],
-                'name': obj['name'],
-                'extension': obj['extension'],
-                'size': obj['size'],
-                'path': path.join('projects', self.project['id'], 'data', identifier + obj['extension']),
-                'predictionResults': []
-            }
-
-            for prediction_identifier in obj['predictionResults']:
-                prediction = obj['predictionResults'][prediction_identifier]
-                if prediction['origin'] != 'user':
-                    continue
-
-                if 'x' not in prediction:
-                    o = {
-                        'type': 'labeled-image',
-                        'label': prediction['label']
-                    }
-                else:
-                    o = {
-                        'type': 'bounding-box',
-                        'x': prediction['x'],
-                        'y': prediction['y'],
-                        'w': prediction['w'],
-                        'h': prediction['h']
-                    }
 
-                    if 'label' in prediction:
-                        o['type'] = 'labeled-bounding-box'
-                        o['label'] = prediction['label']
-                    if 'frame' in prediction:
-                        o['frame'] = prediction['frame']
-
-                media['predictionResults'].append(o)
-
-            data.append(media)
+        for identifier in self.project['data']:
+            fit = Fit(self.project['id'], self.project['data'][identifier])
+            data.append(fit)
 
         self.pipeline.fit(data)

+ 0 - 7
pycs/pipeline/Result.py

@@ -1,7 +0,0 @@
-from pycs.pipeline.Job import Job
-
-
-class Result:
-    def __init__(self, job: Job, predictions: list):
-        self.job = job
-        self.predictions = predictions

+ 1 - 1
webui/src/components/media/annotated-image.vue

@@ -22,7 +22,7 @@
                      @play="videoPlay" @jump="videoJump"/>
     </template>
 
-    <!-- <div style="position: absolute; top: 0.5rem; left: 0.5rem">{{ video }}</div> -->
+    <!-- <div style="position: absolute; top: 0.5rem; left: 0.5rem">{{ data }}</div> -->
 
     <annotation-box v-if="current"
                     :image="image"