コード例 #1
0
    def update_model_card_json(
            self, model_card: model_card_module.ModelCard) -> None:
        """Validates the model card and updates the JSON file in MCT assets.

    If model_card.schema_version is not provided, it will assign the latest
    schema version to the `model_card`, and validate it.

    Args:
      model_card: The updated model card that users want to write back.

    Raises:
       Error: when the given model_card is invalid w.r.t. the schema.
    """
        if not model_card.schema_version:
            sub_directories = [
                f for f in os.scandir(_SCHEMA_DIR) if f.is_dir()
            ]
            latest_schema_version = max(
                sub_directories,
                key=lambda f: semantic_version.Version(f.name[1:]))
            model_card.schema_version = latest_schema_version.name[1:]
        # Validate the updated model_card first.
        schema = self._find_model_card_schema(model_card.schema_version)
        jsonschema.validate(model_card.to_dict(), schema)
        # Write the updated JSON to the file.
        self._write_file(self._mcta_json_file, model_card.to_json())
コード例 #2
0
    def _validate_schema(self, model_card: ModelCard) -> None:
        """Validates the model_card against the json schema.

    Args:
      model_card: The model card data object.

    Raises:
       jsonschema.ValidationError: when the given model_card is
         invalid w.r.t. the schema.
    """
        path = model_card.schema_version if model_card.schema_version else '0.0.1'
        schema_file = os.path.join(_SCHEMA_DIR, 'v' + path, _SCHEMA_FILE)
        with open(schema_file) as json_file:
            schema = json.loads(json_file.read())
        jsonschema.validate(model_card.to_dict(), schema)
コード例 #3
0
    def update_model_card_json(self, model_card: ModelCard) -> None:
        """Validates the model card and updates the JSON file in MCT assets.

    If model_card.schema_version is not provided, it will assign the latest
    schema version to the `model_card`, and validate it.

    Args:
      model_card: The updated model card that users want to write back.

    Raises:
       Error: when the given model_card is invalid w.r.t. the schema.
    """
        if not model_card.schema_version:
            model_card.schema_version = validation.get_latest_schema_version()
        validation.validate_json_schema(model_card.to_dict(),
                                        model_card.schema_version)
        self._write_file(self._mcta_json_file, model_card.to_json())