| 22 | import zmq |
| 23 | |
| 24 | def load_resized_image(img_file:str|io.BytesIO, max_line_res: Optional[int] = None): |
| 25 | origin_img = Image.open(img_file).convert("RGB") |
| 26 | w,h = origin_img.size |
| 27 | if max_line_res is not None: |
| 28 | if h > max_line_res: |
| 29 | w = int(w * max_line_res / h) |
| 30 | h = max_line_res |
| 31 | if w > max_line_res: |
| 32 | h = int(h * max_line_res / w) |
| 33 | w = max_line_res |
| 34 | img = origin_img.resize((w,h),resample=Image.Resampling.LANCZOS) |
| 35 | else: |
| 36 | img = origin_img |
| 37 | |
| 38 | return img,origin_img |
| 39 | |
| 40 | class GUIRFTDataset(Dataset): |
| 41 | def __init__(self, jsonl_file_path: str, max_line_res: int|None = None, *args, **kwargs): |