Ejemplo n.º 1
0
 def _get_serialized_data(self, annotation):
     if get_bool_env('FUTURE_SAVE_TASK_TO_STORAGE', default=False):
         # export task with annotations
         return ExportDataSerializer(annotation.task).data
     else:
         from io_storages.serializers import StorageAnnotationSerializer
         # deprecated functionality - save only annotation
         return StorageAnnotationSerializer(annotation).data
Ejemplo n.º 2
0
 def _get_serialized_data(self, annotation):
     if get_bool_env('FUTURE_SAVE_TASK_TO_STORAGE', default=False):
         # export task with annotations
         return ExportDataSerializer(annotation.task).data
     else:
         serializer_class = load_func(settings.STORAGE_ANNOTATION_SERIALIZER)
         # deprecated functionality - save only annotation
         return serializer_class(annotation).data
Ejemplo n.º 3
0
    def train(self, project, use_ground_truth=False):
        # get only tasks with annotations
        tasks = project.tasks.annotate(
            num_annotations=Count('annotations')).filter(num_annotations__gt=0)

        # create serialized tasks with annotations: {"data": {...}, "annotations": [{...}], "predictions": [{...}]}
        tasks_ser = ExportDataSerializer(tasks, many=True).data
        logger.debug(
            f'{len(tasks_ser)} tasks with annotations are sent to ML backend for training.'
        )
        request = {
            'annotations': tasks_ser,
            'project': self._create_project_uid(project),
            'label_config': project.label_config,
            'params': {
                'login': project.task_data_login,
                'password': project.task_data_password
            }
        }
        return self._request('train', request, verbose=False)
Ejemplo n.º 4
0
 def train(self, project, use_ground_truth=False):
     # TODO Replace AnonymousUser with real user from request
     user = AnonymousUser()
     # Identify if feature flag is turned on
     if flag_set(
             'ff_back_dev_1417_start_training_mlbackend_webhooks_250122_long',
             user):
         request = {
             'action':
             'PROJECT_UPDATED',
             'project':
             load_func(settings.WEBHOOK_SERIALIZERS['project'])(
                 instance=project).data
         }
         return self._request('webhook',
                              request,
                              verbose=False,
                              timeout=TIMEOUT_PREDICT)
     else:
         # get only tasks with annotations
         tasks = project.tasks.annotate(
             num_annotations=Count('annotations')).filter(
                 num_annotations__gt=0)
         # create serialized tasks with annotations: {"data": {...}, "annotations": [{...}], "predictions": [{...}]}
         tasks_ser = ExportDataSerializer(tasks, many=True).data
         logger.debug(
             f'{len(tasks_ser)} tasks with annotations are sent to ML backend for training.'
         )
         request = {
             'annotations': tasks_ser,
             'project': self._create_project_uid(project),
             'label_config': project.label_config,
             'params': {
                 'login': project.task_data_login,
                 'password': project.task_data_password
             }
         }
         return self._request('train',
                              request,
                              verbose=False,
                              timeout=TIMEOUT_PREDICT)