Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
refactor: remove albumentations dependency and update image processing logic
myhloli935287d4c92c
diff --git a/mineru/backend/hybrid/hybrid_analyze.py b/mineru/backend/hybrid/hybrid_analyze.pyindex aaa2f248..32363507 100644--- a/mineru/backend/hybrid/hybrid_analyze.py+++ b/mineru/backend/hybrid/hybrid_analyze.py@@ -45,7 +45,6 @@ from mineru.utils.pdfium_guard import ()os.environ['PYTORCH_ENABLE_MPS_FALLBACK'] = '1' # 让mps可以fallback-os.environ['NO_ALBUMENTATIONS_UPDATE'] = '1' # 禁止albumentations检查更新LAYOUT_BASE_BATCH_SIZE = 1MFR_BASE_BATCH_SIZE = 16diff --git a/mineru/backend/pipeline/pipeline_analyze.py b/mineru/backend/pipeline/pipeline_analyze.pyindex aa309145..03a36d05 100644--- a/mineru/backend/pipeline/pipeline_analyze.py+++ b/mineru/backend/pipeline/pipeline_analyze.py@@ -28,7 +28,6 @@ from ...utils.pdfium_guard import (os.environ['PYTORCH_ENABLE_MPS_FALLBACK'] = '1' # 让mps可以fallback-os.environ['NO_ALBUMENTATIONS_UPDATE'] = '1' # 禁止albumentations检查更新class ModelSingleton:_instance = Nonediff --git a/mineru/model/mfr/unimernet/unimernet_hf/unimer_swin/image_processing_unimer_swin.py b/mineru/model/mfr/unimernet/unimernet_hf/unimer_swin/image_processing_unimer_swin.pyindex d343ee86..e737d6b3 100644--- a/mineru/model/mfr/unimernet/unimernet_hf/unimer_swin/image_processing_unimer_swin.py+++ b/mineru/model/mfr/unimernet/unimernet_hf/unimer_swin/image_processing_unimer_swin.py@@ -3,8 +3,7 @@ from PIL import Image, ImageOpsfrom transformers.image_processing_utils import BaseImageProcessorimport numpy as npimport cv2-import albumentations as alb-from albumentations.pytorch import ToTensorV2+import torchfrom torchvision.transforms.functional import resize@@ -16,19 +15,25 @@ class UnimerSwinImageProcessor(BaseImageProcessor):):self.input_size = [int(_) for _ in image_size]assert len(self.input_size) == 2-- self.transform = alb.Compose(- [- alb.ToGray(),- alb.Normalize((0.7931, 0.7931, 0.7931), (0.1738, 0.1738, 0.1738)),- # alb.Sharpen()- ToTensorV2(),- ]- )def __call__(self, item):image = self.prepare_input(item)- return self.transform(image=image)['image'][:1]+ return self.to_normalized_gray_tensor(image)++ @staticmethod+ def to_normalized_gray_tensor(image: np.ndarray) -> torch.Tensor:+ """将图像确定性转灰度、按 UniMERNet 参数归一化,并转为单通道 tensor。"""+ if image.ndim == 2:+ gray = image+ elif image.ndim == 3 and image.shape[2] == 1:+ gray = image[:, :, 0]+ elif image.ndim == 3 and image.shape[2] == 3:+ gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)+ else:+ raise ValueError(f"Unsupported image shape for UnimerSwinImageProcessor: {image.shape}")++ normalized = (gray.astype(np.float32) - 0.7931 * 255.0) / (0.1738 * 255.0)+ return torch.from_numpy(normalized[None, :, :])@staticmethoddef crop_margin(img: Image.Image) -> Image.Image:diff --git a/pyproject.toml b/pyproject.tomlindex e1448c67..b0e81f45 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -101,7 +101,6 @@ pipeline = ["torchvision","transformers>=4.57.3,<5.0.0","onnxruntime>1.17.0",- "albumentations>=2.0.8,<3",]gradio = ["gradio>=5.49.1,!=6.0.0,!=6.0.1,!=6.0.2,!=6.1.0,!=6.2.0,!=6.3.0,!=6.4.0,!=6.5.0,!=6.5.1,!=6.6.0,!=6.7.0,<6.9.0",