fix(ml): tolerate truncated images in WD14 and SigLIP preprocess
PIL's strict load was raising OSError on images missing the trailing end-of-stream marker (e.g. '6 bytes not processed' on a JPEG without its FF D9 EOI), failing the entire ML task for an image the model could otherwise score fine. Set ImageFile.LOAD_TRUNCATED_IMAGES = True in both ML modules so a minutely-corrupt tail doesn't block tagging or embedding. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+5
-1
@@ -3,7 +3,11 @@ from __future__ import annotations
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from PIL import Image
|
from PIL import Image, ImageFile
|
||||||
|
|
||||||
|
# Mirror wd14.py: tolerate minutely-truncated source images so embedding
|
||||||
|
# doesn't fail on the same images WD14 successfully tagged.
|
||||||
|
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
||||||
|
|
||||||
# Defer torch/transformers imports to lazily-loaded functions to allow
|
# Defer torch/transformers imports to lazily-loaded functions to allow
|
||||||
# importing MODEL_VERSION in non-ML-worker contexts (e.g., web container
|
# importing MODEL_VERSION in non-ML-worker contexts (e.g., web container
|
||||||
|
|||||||
+7
-1
@@ -6,7 +6,13 @@ from typing import Iterable
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import onnxruntime as ort
|
import onnxruntime as ort
|
||||||
from PIL import Image
|
from PIL import Image, ImageFile
|
||||||
|
|
||||||
|
# Some images in the library are minutely truncated (e.g. 6 bytes short of
|
||||||
|
# the JPEG end-of-image marker). The model doesn't care about the last few
|
||||||
|
# pixels, but PIL's default strict load raises OSError. Tolerate them so a
|
||||||
|
# single corrupt tail doesn't block tagging the rest of the image.
|
||||||
|
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
||||||
|
|
||||||
MODEL_VERSION = os.environ.get('WD14_MODEL_VERSION', 'wd-eva02-large-tagger-v3')
|
MODEL_VERSION = os.environ.get('WD14_MODEL_VERSION', 'wd-eva02-large-tagger-v3')
|
||||||
_MODEL_DIR = os.environ.get('ML_MODEL_DIR', '/models')
|
_MODEL_DIR = os.environ.get('ML_MODEL_DIR', '/models')
|
||||||
|
|||||||
Reference in New Issue
Block a user