diff --git a/learnware/market/easy2/checker.py b/learnware/market/easy2/checker.py index 2ab04f5..ca8c25f 100644 --- a/learnware/market/easy2/checker.py +++ b/learnware/market/easy2/checker.py @@ -62,7 +62,6 @@ class EasySemanticChecker(BaseChecker): class EasyStatisticalChecker(BaseChecker): - @staticmethod def _generate_random_text_list(num, text_type="en", min_len=10, max_len=1000): text_list = [] @@ -78,7 +77,7 @@ class EasyStatisticalChecker(BaseChecker): else: raise ValueError("Type should be en or zh") return text_list - + def __call__(self, learnware): semantic_spec = learnware.get_specification().get_semantic_spec() @@ -97,15 +96,17 @@ class EasyStatisticalChecker(BaseChecker): input_shape = learnware_model.input_shape ## WHY: why write this? - if semantic_spec["Data"]["Values"][0] == "Table" and input_shape != (int(semantic_spec["Input"]["Dimension"]),): - logger.warning("input shapes of model and semantic specifications are different") - return self.INVALID_LEARNWARE - + if semantic_spec["Data"]["Values"][0] == "Table" and input_shape != ( + int(semantic_spec["Input"]["Dimension"]), + ): + logger.warning("input shapes of model and semantic specifications are different") + return self.INVALID_LEARNWARE + spec_type = parse_specification_type(learnware.get_specification()) if spec_type is None: logger.warning(f"No valid specification is found in stat spec {stat_spec}") return self.INVALID_LEARNWARE - + if spec_type == "RKMETableSpecification": stat_spec = learnware.get_specification().get_stat_spec_by_name(spec_type) if stat_spec.get_z().shape[1:] != input_shape: @@ -136,7 +137,9 @@ class EasyStatisticalChecker(BaseChecker): return self.INVALID_LEARNWARE # Check output shape - if outputs[0].shape != learnware_model.output_shape or learnware_model.output_shape != int(semantic_spec["Output"]["Dimension"]): + if outputs[0].shape != learnware_model.output_shape or learnware_model.output_shape != int( + semantic_spec["Output"]["Dimension"] + ): logger.warning(f"The learnware [{learnware.id}] output dimention mismatch!") return self.INVALID_LEARNWARE diff --git a/learnware/market/easy2/searcher.py b/learnware/market/easy2/searcher.py index 4349869..4276e86 100644 --- a/learnware/market/easy2/searcher.py +++ b/learnware/market/easy2/searcher.py @@ -415,7 +415,9 @@ class EasyStatSearcher(BaseSearcher): return sorted_score_list[:idx], learnware_list[:idx] def _filter_by_rkme_spec_dimension( - self, learnware_list: List[Learnware], user_rkme: Union[RKMETableSpecification, RKMEImageSpecification, RKMETextSpecification] + self, + learnware_list: List[Learnware], + user_rkme: Union[RKMETableSpecification, RKMEImageSpecification, RKMETextSpecification], ) -> List[Learnware]: """Filter learnwares whose rkme dimension different from user_rkme @@ -520,7 +522,9 @@ class EasyStatSearcher(BaseSearcher): return mmd_dist, weight_min, mixture_list def _search_by_rkme_spec_single( - self, learnware_list: List[Learnware], user_rkme: Union[RKMETableSpecification, RKMEImageSpecification, RKMETextSpecification] + self, + learnware_list: List[Learnware], + user_rkme: Union[RKMETableSpecification, RKMEImageSpecification, RKMETextSpecification], ) -> Tuple[List[float], List[Learnware]]: """Calculate the distances between learnwares in the given learnware_list and user_rkme diff --git a/learnware/market/utils.py b/learnware/market/utils.py index f3d4e35..90cdab3 100644 --- a/learnware/market/utils.py +++ b/learnware/market/utils.py @@ -1,12 +1,13 @@ from ..specification import Specification from ..logger import get_module_logger -logger = get_module_logger('market_utils') +logger = get_module_logger("market_utils") + def parse_specification_type(stat_spec: Specification): stat_specs = stat_spec.stat_spec - spec_list =['RKMETableSpecification', 'RKMETextSpecification', 'RKMEImageSpecification'] + spec_list = ["RKMETableSpecification", "RKMETextSpecification", "RKMEImageSpecification"] for spec in spec_list: if spec in stat_specs: return spec - return None \ No newline at end of file + return None diff --git a/tests/test_workflow/test_workflow.py b/tests/test_workflow/test_workflow.py index 718f65c..fea00d9 100644 --- a/tests/test_workflow/test_workflow.py +++ b/tests/test_workflow/test_workflow.py @@ -97,7 +97,9 @@ class TestAllWorkflow(unittest.TestCase): semantic_spec["Name"]["Values"] = "learnware_%d" % (idx) semantic_spec["Description"]["Values"] = "test_learnware_number_%d" % (idx) semantic_spec["Input"] = {"Dimension": 64} - semantic_spec["Input"].update({f"{i}": f"The value in the digit image with row is {i // 8} and col is {i % 8}." for i in range(64)}) + semantic_spec["Input"].update( + {f"{i}": f"The value in the digit image with row is {i // 8} and col is {i % 8}." for i in range(64)} + ) semantic_spec["Output"] = {"Dimension": 1, "Description": {"0": "The label of the hand-written digit."}} easy_market.add_learnware(zip_path, semantic_spec)