Beispiel #1
0
    def feature_params(self, ch_name):
        fgroups = defaultdict(dict)

        for group, features in FEATURE_MAP.iteritems():
            if self.settings.get(SECTION_NAME_FEATURE_EXTRACTION,
                                 self._resolve_name(ch_name, group)):

                for feature, params in features.iteritems():

                    if params is not None:
                        for pname, value in params.iteritems():
                            # special case, same parameters for haralick features
                            if feature.startswith("haralick"):
                                option = "%s_%s" %(self._resolve_name(ch_name, pname), "haralick")
                            else:
                                option = "%s_%s" %(self._resolve_name(ch_name, pname), feature)

                            option = self.settings("FeatureExtraction", option)

                            if isinstance(value, (list, tuple)) and \
                               isinstance(option, basestring):
                                fgroups[feature][pname] = eval(option)
                            else:
                                fgroups[feature][pname] = option

                    else:
                        fgroups[feature] = params # = None

        return fgroups
Beispiel #2
0
    def feature_params(self, ch_name):

        # XXX unify list and dict
        f_categories = list()
        f_cat_params = dict()

        # unfortunateley some classes expect empty list and dict
        if not self.settings.get(SECTION_NAME_PROCESSING,
                             self._resolve_name(ch_name,
                                                'featureextraction')):
            return f_categories, f_cat_params

        for category, feature in FEATURE_MAP.iteritems():
            if self.settings.get(SECTION_NAME_FEATURE_EXTRACTION,
                                 self._resolve_name(ch_name, category)):
                
                f_categories += feature

                if category in DEFAULT_FEATURE_PARAMS:
                    f_cat_params[category] = {}
                    for option in DEFAULT_FEATURE_PARAMS[category]:
                        option_key = self._resolve_name(ch_name, '%s_%s' % (option, category.split('_')[-1]))
                        f_cat_params[category][option] = DEFAULT_FEATURE_PARAMS[category][option]

                        if self.settings.has_option(SECTION_NAME_FEATURE_EXTRACTION, option_key):
                            str_opt = self.settings.get(SECTION_NAME_FEATURE_EXTRACTION, option_key)
                            
                            default_type = type(DEFAULT_FEATURE_PARAMS[category][option])

                            if type(str_opt) != types.StringType:
                                f_cat_params[category][option] = str_opt
                            elif len(str_opt) > 0:
                                if default_type is types.StringType :
                                    # in this case the default type is a string.
                                    f_cat_params[category][option] = str_opt
                                else:
                                    f_cat_params[category][option] = eval(str_opt) #tuple([int(x) for x in str_opt.split(',')])

                            found_type = type(f_cat_params[category][option])
                            if found_type != default_type:
                                if default_type in [types.ListType, types.TupleType]:
                                    f_cat_params[category][option] = [f_cat_params[category][option]]                                                                  
                                    
        #print 'f_categories'
        #print f_categories
        #print 'f_cat_params'
        #print f_cat_params
        
        return f_categories, f_cat_params
Beispiel #3
0
    def feature_params(self, ch_name):

        # XXX unify list and dict
        f_categories = list()
        f_cat_params = dict()

        # unfortunateley some classes expect empty list and dict
        if not self.settings.get(
                SECTION_NAME_PROCESSING,
                self._resolve_name(ch_name, 'featureextraction')):
            return f_categories, f_cat_params

        for category, feature in FEATURE_MAP.iteritems():
            if self.settings.get(SECTION_NAME_FEATURE_EXTRACTION,
                                 self._resolve_name(ch_name, category)):

                f_categories += feature

                if category in DEFAULT_FEATURE_PARAMS:
                    f_cat_params[category] = {}
                    for option in DEFAULT_FEATURE_PARAMS[category]:
                        option_key = self._resolve_name(
                            ch_name,
                            '%s_%s' % (option, category.split('_')[-1]))
                        f_cat_params[category][
                            option] = DEFAULT_FEATURE_PARAMS[category][option]

                        if self.settings.has_option(
                                SECTION_NAME_FEATURE_EXTRACTION, option_key):
                            str_opt = self.settings.get(
                                SECTION_NAME_FEATURE_EXTRACTION, option_key)

                            default_type = type(
                                DEFAULT_FEATURE_PARAMS[category][option])

                            if type(str_opt) != types.StringType:
                                f_cat_params[category][option] = str_opt
                            elif len(str_opt) > 0:
                                if default_type is types.StringType:
                                    # in this case the default type is a string.
                                    f_cat_params[category][option] = str_opt
                                else:
                                    f_cat_params[category][option] = eval(
                                        str_opt
                                    )  #tuple([int(x) for x in str_opt.split(',')])

                            found_type = type(f_cat_params[category][option])
                            if found_type != default_type:
                                if default_type in [
                                        types.ListType, types.TupleType
                                ]:
                                    f_cat_params[category][option] = [
                                        f_cat_params[category][option]
                                    ]

        #print 'f_categories'
        #print f_categories
        #print 'f_cat_params'
        #print f_cat_params

        return f_categories, f_cat_params