Sync from GitHub via hub-sync
Browse files194 unmodified lines19519619719819819920020132 unmodified lines2342352362372372382392402412422432432442452462452462472482492502512522532542552561 unmodified line258259260254255261262263264265694 unmodified lines960961962963964965966967968969970971972194 unmodified lines@dataclassclass SourceItem: key: str # stable identifier per image (used for dedup/resume) image: Image.Image image: Optional[Image.Image] # None for an unreadable row (placeholder) extras: Dict[str, Any] # original row fields (only populated for dataset source)
32 unmodified lines total = len(ds)
def gen() -> Iterator[SourceItem]: skipped = 0 failed = 0 for i in range(total): try: row = ds[i] image = to_pil(row[image_column]) except (UnidentifiedImageError, OSError) as e: skipped += 1 # Still yield a placeholder so the output row stays aligned with # the source row (the dataset sink writes layouts positionally). failed += 1 logger.warning( f"Skipping unreadable image at row {i}: " f"{type(e).__name__}: {e}" 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}, ) continue yield SourceItem(1 unmodified line image=image, extras={}, # original schema is preserved by the sink via the dataset ref ) if skipped: logger.info(f"Skipped {skipped} unreadable image(s) total") if failed: logger.info(f"{failed} unreadable image(s) written as empty layouts")
return gen(), total, ds
694 unmodified lines if item.key in completed: skipped += 1 continue if 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 += 1 processed += 1 continue try: arr = pil_to_array(item.image) results = model.predict(pp-doclayout.py+21-7