|
@@ -19,8 +19,8 @@ class PipelineManager:
|
|
self.pipeline = cl(project['model']['path'], project['model'])
|
|
self.pipeline = cl(project['model']['path'], project['model'])
|
|
|
|
|
|
def close(self):
|
|
def close(self):
|
|
- self.pipeline.close()
|
|
|
|
print('PipelineManager', 'close')
|
|
print('PipelineManager', 'close')
|
|
|
|
+ self.pipeline.close()
|
|
|
|
|
|
def run(self, media_file):
|
|
def run(self, media_file):
|
|
# create job list
|
|
# create job list
|
|
@@ -35,68 +35,49 @@ class PipelineManager:
|
|
for prediction in result.predictions:
|
|
for prediction in result.predictions:
|
|
media_file.add_result(prediction, origin='pipeline')
|
|
media_file.add_result(prediction, origin='pipeline')
|
|
|
|
|
|
- '''
|
|
|
|
- def __load_pipeline(self, pipeline_identifier):
|
|
|
|
- model_distribution = self.project.parent.parent['models'][pipeline_identifier]
|
|
|
|
-
|
|
|
|
- if model_distribution['mode'] == 'tf1':
|
|
|
|
- model_root = path.join(getcwd(), 'models', model_distribution['name'])
|
|
|
|
-
|
|
|
|
- #pipeline = TF1Pipeline()
|
|
|
|
- #pipeline.load(model_root, model_distribution['pipeline'])
|
|
|
|
-
|
|
|
|
- #return pipeline
|
|
|
|
- '''
|
|
|
|
-
|
|
|
|
- '''
|
|
|
|
- def __update(self, data):
|
|
|
|
- # get current project path
|
|
|
|
- opened_projects = list(filter(lambda x: x['status'] == 'open', data))
|
|
|
|
- if len(opened_projects) == 0:
|
|
|
|
- return
|
|
|
|
-
|
|
|
|
- current_project = opened_projects[0]
|
|
|
|
-
|
|
|
|
- # find images to predict
|
|
|
|
- if 'data' not in current_project.keys() or len(current_project['data']) == 0:
|
|
|
|
- return
|
|
|
|
-
|
|
|
|
- # load pipeline
|
|
|
|
- pipeline = tpool.execute(self.__load_pipeline, current_project['pipeline']['model-distribution'])
|
|
|
|
-
|
|
|
|
- # create job list
|
|
|
|
- for d in current_project['data']:
|
|
|
|
- print('keys:', d.keys())
|
|
|
|
- if 'result' not in d.keys():
|
|
|
|
- # TODO update job progress
|
|
|
|
- job = Job('detect-faces', current_project['id'], d)
|
|
|
|
- result = tpool.execute(lambda p, j: p.execute(j), pipeline, job)
|
|
|
|
- d['result'] = result.predictions
|
|
|
|
-
|
|
|
|
- # close pipeline
|
|
|
|
- pipeline.close()
|
|
|
|
- '''
|
|
|
|
-
|
|
|
|
- '''
|
|
|
|
- def __update(self, data):
|
|
|
|
- for current_project in data:
|
|
|
|
- print('>>>>>>>>>>')
|
|
|
|
- # find images to predict
|
|
|
|
- if 'data' not in current_project.keys() or len(current_project['data']) == 0:
|
|
|
|
- return
|
|
|
|
-
|
|
|
|
- # load pipeline
|
|
|
|
- pipeline = tpool.execute(self.__load_pipeline, current_project['pipeline']['model-distribution'])
|
|
|
|
-
|
|
|
|
- # create job list
|
|
|
|
- for d in current_project['data']:
|
|
|
|
- print('keys:', d.keys())
|
|
|
|
- if 'result' not in d.keys():
|
|
|
|
- # TODO update job progress
|
|
|
|
- job = Job('detect-faces', current_project['id'], d)
|
|
|
|
- result = tpool.execute(lambda p, j: p.execute(j), pipeline, job)
|
|
|
|
- d['result'] = result.predictions
|
|
|
|
-
|
|
|
|
- # close pipeline
|
|
|
|
- pipeline.close()
|
|
|
|
- '''
|
|
|
|
|
|
+ def fit(self):
|
|
|
|
+ print('PipelineManager', 'fit')
|
|
|
|
+
|
|
|
|
+ data = []
|
|
|
|
+ for identifier in self.project['data']:
|
|
|
|
+ obj = self.project['data'][identifier]
|
|
|
|
+ media = {
|
|
|
|
+ '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:
|
|
|
|
+ media['predictionResults'].append({
|
|
|
|
+ 'type': 'labeled-image',
|
|
|
|
+ 'label': prediction['label']
|
|
|
|
+ })
|
|
|
|
+ else:
|
|
|
|
+ if 'label' in prediction:
|
|
|
|
+ media['predictionResults'].append({
|
|
|
|
+ 'type': 'labeled-bounding-box',
|
|
|
|
+ 'x': prediction['x'],
|
|
|
|
+ 'y': prediction['y'],
|
|
|
|
+ 'w': prediction['w'],
|
|
|
|
+ 'h': prediction['h'],
|
|
|
|
+ 'label': prediction['label']
|
|
|
|
+ })
|
|
|
|
+ else:
|
|
|
|
+ media['predictionResults'].append({
|
|
|
|
+ 'type': 'bounding-box',
|
|
|
|
+ 'x': prediction['x'],
|
|
|
|
+ 'y': prediction['y'],
|
|
|
|
+ 'w': prediction['w'],
|
|
|
|
+ 'h': prediction['h']
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ data.append(media)
|
|
|
|
+
|
|
|
|
+ self.pipeline.fit(data)
|