File size: 1,264 Bytes
4282997 226ac60 4282997 226ac60 4282997 226ac60 4282997 226ac60 4282997 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | import dataclasses
from datetime import datetime, timezone
@dataclasses.dataclass
class TrainingInfo:
"""Training artifacts, stored under the "training" key of model_info.json."""
image_width: int
image_height: int
labels: list[str]
built_time: datetime
blank_token: str
pad_token: str
@property
def built_timestamp(self) -> int:
return int(self.built_time.astimezone(timezone.utc).timestamp())
def asdict(self):
return {
"image_width": self.image_width,
"image_height": self.image_height,
"labels": self.labels.copy(),
"built_timestamp": self.built_timestamp,
"blank_token": self.blank_token,
"pad_token": self.pad_token,
}
@classmethod
def from_dict(cls, model_info_dict: dict):
return cls(
image_width=model_info_dict["image_width"],
image_height=model_info_dict["image_height"],
labels=model_info_dict["labels"].copy(),
built_time=datetime.fromtimestamp(
model_info_dict["built_timestamp"], timezone.utc
),
blank_token=model_info_dict["blank_token"],
pad_token=model_info_dict["pad_token"],
)
|