Exemple #1
0
    def reload(self):
        self.tasks = None
        self.derived_input_schema = []
        self.derived_output_schema = {
            'from_name_to_name_type': set(),
            'labels': defaultdict(set)
        }

        self._init()

        self.label_config_full = config_comments_free(
            open(self.config['label_config']).read())
        self.label_config_line = config_line_stripped(self.label_config_full)

        if self.analytics is None:
            self.analytics = Analytics(
                self.label_config_line,
                self.config.get('collect_analytics', True), self.name)
        else:
            self.analytics.update_info(
                self.label_config_line,
                self.config.get('collect_analytics', True), self.name)

        # configure project
        self.project_obj = ProjectObj(label_config=self.label_config_line,
                                      label_config_full=self.label_config_full)

        # configure machine learning backend
        if self.ml_backend is None:
            ml_backend_params = self.config.get('ml_backend')
            if ml_backend_params:
                ml_backend = MLBackend.from_params(ml_backend_params)
                self.project_obj.connect(ml_backend)

        self.converter = Converter(self.label_config_full)
Exemple #2
0
 def load_project_ml_backend(self):
     # configure project
     self.project_obj = ProjectObj(label_config=self.label_config_line, label_config_full=self.label_config_full)
     # configure machine learning backend
     ml_backend_params = self.config.get('ml_backend')
     if ml_backend_params:
         self.ml_backend = MLBackend.from_params(ml_backend_params)
         self.project_obj.connect(self.ml_backend)
Exemple #3
0
 def load_project_ml_backend(self):
     # configure project
     self.project_obj = ProjectObj(label_config=self.label_config_line,
                                   label_config_full=self.label_config_full)
     # configure machine learning backend
     ml_backend_params = self.config.get('ml_backend')
     if ml_backend_params:
         self.ml_backend = MLBackend.from_params(ml_backend_params)
         if not self.ml_backend.connected:
             raise ValueError('ML backend is not connected.')
Exemple #4
0
def reload_config(prompt_inputs=False, force=False):
    global c
    global label_config_line
    global analytics
    global ml_backend
    global project
    global config_path

    # Read config from config.json & input arguments
    c = json.load(open(config_path))
    c['port'] = input_args.port if input_args.port else c['port']
    c['label_config'] = input_args.label_config if input_args.label_config else c[
        'label_config']
    c['input_path'] = input_args.input_path if input_args.input_path else c[
        'input_path']
    c['output_dir'] = input_args.output_dir if input_args.output_dir else c[
        'output_dir']
    c['debug'] = input_args.debug if input_args.debug is not None else c[
        'debug']

    # If specified, prompt user in console about specific inputs
    if prompt_inputs:
        iprompt = LabelStudioConfigPrompt(c)
        c['input_data'] = iprompt.ask_input_path()
        c['output_dir'] = iprompt.ask_output_dir()
        c['label_config'] = iprompt.ask_label_config()

    # Initialize DBs
    db.re_init(c)

    label_config_full = config_comments_free(open(c['label_config']).read())
    label_config_line = config_line_stripped(label_config_full)
    if analytics is None:
        analytics = Analytics(label_config_line,
                              c.get('collect_analytics', True))
    else:
        analytics.update_info(label_config_line,
                              c.get('collect_analytics', True))
    # configure project
    if project is None or force:
        project = Project(label_config=label_config_line,
                          label_config_full=label_config_full)
    # configure machine learning backend
    if ml_backend is None or force:
        ml_backend_params = c.get('ml_backend')
        if ml_backend_params:
            ml_backend = MLBackend.from_params(ml_backend_params)
            project.connect(ml_backend)

    return True
Exemple #5
0
    def load_project_ml_backend(self):
        # configure project
        self.project_obj = ProjectObj(label_config=self.label_config_line,
                                      label_config_full=self.label_config_full)

        # configure multiple machine learning backends
        self.ml_backends = []
        ml_backends_params = self.config.get('ml_backends', [])
        for ml_backend_params in ml_backends_params:
            ml_backend = MLBackend.from_params(ml_backend_params)
            if not ml_backend.connected:
                raise ValueError('ML backend ' + str(ml_backend_params) +
                                 ' is not connected.')
            self.ml_backends.append(ml_backend)
Exemple #6
0
 def add_ml_backend(self, params, raise_on_error=True):
     ml_backend = MLBackend.from_params(params)
     if not ml_backend.connected and raise_on_error:
         raise ValueError('ML backend with URL: "' + str(params["url"]) +
                          '" is not connected.')
     self.ml_backends.append(ml_backend)