Sync from GitHub via hub-sync
Browse files194 unmodified lines19519619719819920020132 unmodified lines2342352362372382392402412422432442452462472482491 unmodified line251252253254255256257258694 unmodified lines953954955956957958194 unmodified lines@dataclassclass SourceItem:key: str # stable identifier per image (used for dedup/resume)image: Image.Imageextras: Dict[str, Any] # original row fields (only populated for dataset source)32 unmodified linestotal = len(ds)def gen() -> Iterator[SourceItem]:skipped = 0for i in range(total):try:row = ds[i]image = to_pil(row[image_column])except (UnidentifiedImageError, OSError) as e:skipped += 1logger.warning(f"Skipping unreadable image at row {i}: "f"{type(e).__name__}: {e}")continueyield SourceItem(1 unmodified lineimage=image,extras={}, # original schema is preserved by the sink via the dataset ref)if skipped:logger.info(f"Skipped {skipped} unreadable image(s) total")return gen(), total, ds694 unmodified linesif item.key in completed:skipped += 1continuetry:arr = pil_to_array(item.image)results = model.predict(194 unmodified lines19519619719819920020132 unmodified lines2342352362372382392402412422432442452462472482492502512522532542552561 unmodified line258259260261262263264265694 unmodified lines960961962963964965966967968969970971972194 unmodified lines@dataclassclass SourceItem:key: str # stable identifier per image (used for dedup/resume)image: Optional[Image.Image] # None for an unreadable row (placeholder)extras: Dict[str, Any] # original row fields (only populated for dataset source)32 unmodified linestotal = len(ds)def gen() -> Iterator[SourceItem]:failed = 0for i in range(total):try:row = ds[i]image = to_pil(row[image_column])except (UnidentifiedImageError, OSError) as e:# Still yield a placeholder so the output row stays aligned with# the source row (the dataset sink writes layouts positionally).failed += 1logger.warning(f"Unreadable image at row {i}: "f"{type(e).__name__}: {e} — writing empty layout")yield SourceItem(key=f"row-{i:08d}",image=None,extras={"failed": True},)continueyield SourceItem(1 unmodified lineimage=image,extras={}, # original schema is preserved by the sink via the dataset ref)if failed:logger.info(f"{failed} unreadable image(s) written as empty layouts")return gen(), total, ds694 unmodified linesif item.key in completed:skipped += 1continueif item.extras.get("failed") or item.image is None:# Unreadable source image — write an empty layout in position so the# output stays row-aligned with the source dataset.sink.write(item.key, [], {})errors += 1processed += 1continuetry:arr = pil_to_array(item.image)results = model.predict(
pp-doclayout.py+21-7