Module brevettiai.model.metadata.metadata
Expand source code
import h5py
from pydantic import BaseModel, Field, parse_obj_as
from typing import Optional, Type
from brevettiai import Module
from brevettiai.io.h5_metadata import get_metadata as h5_metadata
class ModelMetadata(BaseModel):
    id: str = Field(description="unique id of model")
    run_id: str = Field(description="Specifier of which training run created the model")
    name: str = Field(description="Name of model")
    producer: str = Field(description="Name of producing code")
    host_name: Optional[str] = Field(default=None, description="URI to host where more information may be found")
    class Config:
        json_encoders = {
            Module: lambda x: x.get_config()
        }
def get_metadata(file: str, metadata_type: Type[ModelMetadata] = ModelMetadata):
    if isinstance(file, h5py.File):
        return parse_obj_as(metadata_type, h5_metadata(file))
    if file.endswith(".h5"):
        return parse_obj_as(metadata_type, h5_metadata(file))
    else:
        raise NotImplementedError(f"Getting metadata from '{file}' not implemented")
Functions
def get_metadata(file: str, metadata_type: Type[ModelMetadata] = brevettiai.model.metadata.metadata.ModelMetadata)- 
Expand source code
def get_metadata(file: str, metadata_type: Type[ModelMetadata] = ModelMetadata): if isinstance(file, h5py.File): return parse_obj_as(metadata_type, h5_metadata(file)) if file.endswith(".h5"): return parse_obj_as(metadata_type, h5_metadata(file)) else: raise NotImplementedError(f"Getting metadata from '{file}' not implemented") 
Classes
class ModelMetadata (**data: Any)- 
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Expand source code
class ModelMetadata(BaseModel): id: str = Field(description="unique id of model") run_id: str = Field(description="Specifier of which training run created the model") name: str = Field(description="Name of model") producer: str = Field(description="Name of producing code") host_name: Optional[str] = Field(default=None, description="URI to host where more information may be found") class Config: json_encoders = { Module: lambda x: x.get_config() }Ancestors
- pydantic.main.BaseModel
 - pydantic.utils.Representation
 
Subclasses
Class variables
var Configvar host_name : Optional[str]var id : strvar name : strvar producer : strvar run_id : str