ONNX
crnn-pytorch / src /utils /model_info.py
lh283375's picture
split model info into training and patch
226ac60 unverified
Raw History Blame Contribute Delete
1.26 kB
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"],
)