コード例 #1
0
    def __init__(self, config, dbConnector, fileServer, options,
                 defaultOptions):
        super(GenericTFModel, self).__init__(config, dbConnector, fileServer,
                                             options)

        # parse the options and compare with the provided defaults
        self.options = check_args(self.options, defaultOptions)

        # retrieve executables
        try:
            self.model_class = get_class_executable(
                self.options['model']['class'])
        except:
            self.model_class = None
        try:
            self.criterion_class = get_class_executable(
                self.options['train']['criterion']['class'])
        except:
            self.criterion_class = None
        try:
            self.optim_class = get_class_executable(
                self.options['train']['optim']['class'])
        except:
            self.optim_class = SGD
        try:
            self.dataset_class = get_class_executable(
                self.options['dataset']['class'])
        except:
            self.dataset_class = None
コード例 #2
0
    def get_dynamic_project_settings(self, project):
        queryStr = 'SELECT ui_settings FROM aide_admin.project WHERE shortname = %s;'
        result = self.dbConnector.execute(queryStr, (project,), 1)
        result = json.loads(result[0]['ui_settings'])

        # complete styles with defaults where necessary (may be required for project that got upgraded from v1)
        result = helpers.check_args(result, self.defaultStyles)

        return result
コード例 #3
0
    def getProjectInfo(self, project, parameters=None):

        # parse parameters (if provided) and compare with mutable entries
        allParams = set([
            'name',
            'description',
            'ispublic',
            'secret_token',
            'demomode',
            'interface_enabled',
            'ui_settings',
            'segmentation_ignore_unlabeled',
            'ai_model_enabled',
            'ai_model_library',
            'ai_model_settings',
            'ai_alcriterion_library',
            'ai_alcriterion_settings',
            'numimages_autotrain',
            'minnumannoperimage',
            'maxnumimages_train',
            'watch_folder_enabled',
            'watch_folder_remove_missing_enabled'
        ])
        if parameters is not None and parameters != '*':
            if isinstance(parameters, str):
                parameters = [parameters.lower()]
            else:
                parameters = [p.lower() for p in parameters]
            set(parameters).intersection_update(allParams)
        else:
            parameters = allParams
        parameters = list(parameters)
        sqlParameters = ','.join(parameters)

        queryStr = sql.SQL('''
        SELECT {} FROM aide_admin.project
        WHERE shortname = %s;
        ''').format(
            sql.SQL(sqlParameters)
        )
        result = self.dbConnector.execute(queryStr, (project,), 1)
        result = result[0]

        # assemble response
        response = {}
        for param in parameters:
            value = result[param]
            if param == 'ui_settings':
                value = json.loads(value)

                # auto-complete with defaults where missing
                value = check_args(value, self.defaultUIsettings)
            response[param] = value

        return response
コード例 #4
0
    def __init__(self, project, config, dbConnector, fileServer, options):
        super(RetinaNet_ois, self).__init__(project, config, dbConnector,
                                            fileServer, options)

        # add contrib options
        defaultContribOptions = {
            'baseFolder_unlabeled':
            '/datadrive/hfaerialblobs/_images/',  # local folder to search for non-added images
            'load_raw_images': True,  # whether to take RAW files into account
            'inference_max_num_unlabeled': 64,
            'export_empty_patches': False,
            'stride': 0.65  # relative stride factor
        }
        if not 'contrib' in self.options:
            self.options['contrib'] = defaultContribOptions
        else:
            self.options['contrib'] = check_args(self.options['contrib'],
                                                 defaultContribOptions)

        if not self.options['contrib']['baseFolder_unlabeled'].endswith(
                os.sep):
            self.options['contrib']['baseFolder_unlabeled'] += os.sep

        # parameters
        self.batchSize = self.options['inference']['dataLoader']['kwargs'][
            'batch_size']
        self.maxNumUnlabeled = self.options['contrib'][
            'inference_max_num_unlabeled']
        self.patchSize = tuple(self.options['general']['image_size'])
        self.stride = self.options['contrib']['stride']
        self.encoder = encoder.DataEncoder(minIoU_pos=0.5,
                                           maxIoU_neg=0.4)  #TODO: implement

        self.windowCropper = windowCropping.WindowCropper(
            patchSize=self.patchSize,
            exportEmptyPatches=False,
            cropMode='windowCropping',
            searchStride=(
                10,
                10,
            ),
            minBBoxArea=64,
            minBBoxAreaFrac=0.25  #TODO
        )

        self.baseFolder_unlabeled = self.options['contrib'][
            'baseFolder_unlabeled']
        self.loadRaw = self.options['contrib']['load_raw_images']
コード例 #5
0
    def __init__(self, config, dbConnector, fileServer, options):
        super(BoundingBoxFilter, self).__init__(config, dbConnector,
                                                fileServer, options)

        # parse properties
        defaultOptions = {
            'box_rule':
            'average',  # how to generate the resulting bounding box from overlapping ones. One of {'average', 'intersection', 'union'}
            'min_iou':
            0.75,  # minimum IoU between overlapping bboxes to employ filtering
            'class_agnostic':
            False,  # if True, only overlapping boxes with the same class will be subject to filtering
            'class_assignment':
            'mode',  # how to assign class label of overlapping boxes. One of {'mode', 'random'}
            'keep_unsure':
            True  # if True, "unsure" bounding boxes will directly be appended without modification to output
        }
        self.options = check_args(options, defaultOptions)
コード例 #6
0
    def __init__(self,
                 project,
                 config,
                 dbConnector,
                 fileServer,
                 options,
                 defaultOptions=None):
        super(GenericPyTorchModel_Legacy,
              self).__init__(project, config, dbConnector, fileServer, options)

        # parse the options and compare with the provided defaults (if provided)
        if defaultOptions is not None:
            self.options = check_args(self.options, defaultOptions)
        else:
            self.options = options

        # retrieve executables
        try:
            self.model_class = get_class_executable(
                self.options['model']['class'])
        except:
            self.model_class = None
        try:
            self.criterion_class = get_class_executable(
                self.options['train']['criterion']['class'])
        except:
            self.criterion_class = None
        try:
            self.optim_class = get_class_executable(
                self.options['train']['optim']['class'])
        except:
            self.optim_class = SGD
        try:
            self.dataset_class = get_class_executable(
                self.options['dataset']['class'])
        except:
            self.dataset_class = None
コード例 #7
0
    try:
        # check if custom default styles are provided
        defaultStyles = json.load(open('config/default_ui_settings.json', 'r'))
    except:
        # resort to built-in styles
        defaultStyles = json.load(
            open(
                'modules/ProjectAdministration/static/json/default_ui_settings.json',
                'r'))
    try:
        with open(v1Config.getProperty('LabelUI', 'styles_file'), 'r') as f:
            styles = json.load(f)
            styles = styles['styles']

            # compare with defaults
            styles = helpers.check_args(styles, defaultStyles)
    except:
        # fallback to defaults
        styles = defaultStyles
    try:
        with open(
                v1Config.getProperty(
                    'Project',
                    'welcome_message_file',
                    type=str,
                    fallback=
                    'modules/LabelUI/static/templates/welcome_message.html'),
                'r') as f:
            welcomeMessage = f.readlines()
    except:
        welcomeMessage = ''
コード例 #8
0
    def updateProjectSettings(self, project, projectSettings):
        '''
            TODO
        '''

        # check UI settings first
        if 'ui_settings' in projectSettings:
            if isinstance(projectSettings['ui_settings'], str):
                projectSettings['ui_settings'] = json.loads(
                    projectSettings['ui_settings'])
            fieldNames = [('welcomeMessage', str), ('numImagesPerBatch', int),
                          ('minImageWidth', int), ('numImageColumns_max', int),
                          ('defaultImage_w', int), ('defaultImage_h', int),
                          ('styles', dict), ('enableEmptyClass', bool),
                          ('showPredictions', bool),
                          ('showPredictions_minConf', float),
                          ('carryOverPredictions', bool),
                          ('carryOverRule', str),
                          ('carryOverPredictions_minConf', float),
                          ('defaultBoxSize_w', int), ('defaultBoxSize_h', int),
                          ('minBoxSize_w', int), ('minBoxSize_h', int)]
            uiSettings_new, uiSettingsKeys_new = parse_parameters(
                projectSettings['ui_settings'],
                fieldNames,
                absent_ok=True,
                escape=True)  #TODO: escape

            # adopt current settings and replace values accordingly
            uiSettings = self.dbConnector.execute(
                '''SELECT ui_settings
                    FROM aide_admin.project
                    WHERE shortname = %s;            
                ''', (project, ), 1)
            uiSettings = json.loads(uiSettings[0]['ui_settings'])
            for kIdx in range(len(uiSettingsKeys_new)):
                if isinstance(uiSettings[uiSettingsKeys_new[kIdx]], dict):
                    ProjectConfigMiddleware._recursive_update(
                        uiSettings[uiSettingsKeys_new[kIdx]],
                        uiSettings_new[kIdx])
                else:
                    uiSettings[uiSettingsKeys_new[kIdx]] = uiSettings_new[kIdx]

            # auto-complete with defaults where missing
            uiSettings = check_args(uiSettings, self.defaultUIsettings)

            projectSettings['ui_settings'] = json.dumps(uiSettings)

        # parse remaining parameters
        fieldNames = [('description', str), ('isPublic', bool),
                      ('secret_token', str), ('demoMode', bool),
                      ('ui_settings', str), ('interface_enabled', bool),
                      ('watch_folder_enabled', bool),
                      ('watch_folder_remove_missing_enabled', bool)]

        vals, params = parse_parameters(projectSettings,
                                        fieldNames,
                                        absent_ok=True,
                                        escape=False)
        vals.append(project)

        # commit to DB
        queryStr = sql.SQL('''UPDATE aide_admin.project
            SET
            {}
            WHERE shortname = %s;
            ''').format(
            sql.SQL(',').join(
                [sql.SQL('{} = %s'.format(item)) for item in params]))

        self.dbConnector.execute(queryStr, tuple(vals), None)

        return True