davanstrien HF Staff Claude commited on
Commit
6042172
·
1 Parent(s): a77e763

Update LightOnOCR target resolution to 1540px

Browse files

Based on feedback from LightOn authors (

@staghado
), update default
image resolution from 1288px to 1540px to match training settings.

Changes:
- Default target_size: 1288px → 1540px
- Updated docstrings: trained at 200 DPI (not 300 DPI)
- Updated help text to note this matches training

The model was trained with max resolution of 1540px and 200 DPI,
so using these settings should provide optimal quality.

Reference: https://x.com/staghado/status/1849518069623726119

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. lighton-ocr.py +7 -7
lighton-ocr.py CHANGED
@@ -81,11 +81,11 @@ def check_cuda_availability():
81
  logger.info(f"CUDA is available. GPU: {torch.cuda.get_device_name(0)}")
82
 
83
 
84
- def resize_image_to_target(image: Image.Image, target_size: int = 1288) -> Image.Image:
85
  """
86
  Resize image so longest dimension is target_size while maintaining aspect ratio.
87
 
88
- LightOnOCR is optimized for 1280-1300px longest dimension at 300 DPI.
89
  """
90
  width, height = image.size
91
 
@@ -107,12 +107,12 @@ def resize_image_to_target(image: Image.Image, target_size: int = 1288) -> Image
107
  def make_ocr_message(
108
  image: Union[Image.Image, Dict[str, Any], str],
109
  resize: bool = True,
110
- target_size: int = 1288,
111
  ) -> List[Dict]:
112
  """
113
  Create chat message for OCR processing.
114
 
115
- LightOnOCR expects images at 1280-1300px longest dimension for optimal results.
116
  """
117
  # Convert to PIL Image if needed
118
  if isinstance(image, Image.Image):
@@ -280,7 +280,7 @@ def main(
280
  temperature: float = 0.2,
281
  top_p: float = 0.9,
282
  gpu_memory_utilization: float = 0.8,
283
- target_size: int = 1288,
284
  no_resize: bool = False,
285
  hf_token: str = None,
286
  split: str = "train",
@@ -577,8 +577,8 @@ Examples:
577
  parser.add_argument(
578
  "--target-size",
579
  type=int,
580
- default=1288,
581
- help="Target size for longest image dimension in pixels (default: 1288)",
582
  )
583
  parser.add_argument(
584
  "--no-resize",
 
81
  logger.info(f"CUDA is available. GPU: {torch.cuda.get_device_name(0)}")
82
 
83
 
84
+ def resize_image_to_target(image: Image.Image, target_size: int = 1540) -> Image.Image:
85
  """
86
  Resize image so longest dimension is target_size while maintaining aspect ratio.
87
 
88
+ LightOnOCR was trained with images at 1540px max resolution and 200 DPI.
89
  """
90
  width, height = image.size
91
 
 
107
  def make_ocr_message(
108
  image: Union[Image.Image, Dict[str, Any], str],
109
  resize: bool = True,
110
+ target_size: int = 1540,
111
  ) -> List[Dict]:
112
  """
113
  Create chat message for OCR processing.
114
 
115
+ LightOnOCR was trained with 1540px max resolution at 200 DPI for optimal results.
116
  """
117
  # Convert to PIL Image if needed
118
  if isinstance(image, Image.Image):
 
280
  temperature: float = 0.2,
281
  top_p: float = 0.9,
282
  gpu_memory_utilization: float = 0.8,
283
+ target_size: int = 1540,
284
  no_resize: bool = False,
285
  hf_token: str = None,
286
  split: str = "train",
 
577
  parser.add_argument(
578
  "--target-size",
579
  type=int,
580
+ default=1540,
581
+ help="Target size for longest image dimension in pixels (default: 1540, matching training)",
582
  )
583
  parser.add_argument(
584
  "--no-resize",