Vik Paruchuri
commited on
Commit
·
88f20eb
1
Parent(s):
0408259
Fix some conversion issues
Browse files- README.md +3 -1
- convert.py +3 -3
- install/apt-requirements.txt +1 -0
- marker/settings.py +5 -3
README.md
CHANGED
|
@@ -47,16 +47,18 @@ First, clone the repo:
|
|
| 47 |
## Linux
|
| 48 |
|
| 49 |
- Install system requirements
|
| 50 |
-
- `cat install/apt-requirements.txt | xargs sudo apt-get install -y`
|
| 51 |
- Optional: Install tesseract 5 by following [these instructions](https://notesalexp.org/tesseract-ocr/html/) or running `install/tesseract_5_install.sh`.
|
| 52 |
- Install ghostscript > 9.55 by following [these instructions](https://ghostscript.readthedocs.io/en/latest/Install.html) or running `install/ghostscript_install.sh`.
|
|
|
|
| 53 |
- Set the tesseract data folder path
|
| 54 |
- Find the tesseract data folder `tessdata` with `find / -name tessdata`. Make sure to use the one corresponding to the right tesseract version if you have multiple!
|
| 55 |
- Create a `local.env` file in the root `marker` folder with `TESSDATA_PREFIX=/path/to/tessdata` inside it
|
| 56 |
- Install python requirements
|
| 57 |
- `poetry install`
|
| 58 |
- `poetry shell` to activate your poetry venv
|
|
|
|
| 59 |
- GPU only: run `pip install torch` to install other torch dependencies.
|
|
|
|
| 60 |
|
| 61 |
## Mac
|
| 62 |
|
|
|
|
| 47 |
## Linux
|
| 48 |
|
| 49 |
- Install system requirements
|
|
|
|
| 50 |
- Optional: Install tesseract 5 by following [these instructions](https://notesalexp.org/tesseract-ocr/html/) or running `install/tesseract_5_install.sh`.
|
| 51 |
- Install ghostscript > 9.55 by following [these instructions](https://ghostscript.readthedocs.io/en/latest/Install.html) or running `install/ghostscript_install.sh`.
|
| 52 |
+
- Install other requirements with `cat install/apt-requirements.txt | xargs sudo apt-get install -y`
|
| 53 |
- Set the tesseract data folder path
|
| 54 |
- Find the tesseract data folder `tessdata` with `find / -name tessdata`. Make sure to use the one corresponding to the right tesseract version if you have multiple!
|
| 55 |
- Create a `local.env` file in the root `marker` folder with `TESSDATA_PREFIX=/path/to/tessdata` inside it
|
| 56 |
- Install python requirements
|
| 57 |
- `poetry install`
|
| 58 |
- `poetry shell` to activate your poetry venv
|
| 59 |
+
- Update pytorch as needed since poetry doesn't play nicely with it
|
| 60 |
- GPU only: run `pip install torch` to install other torch dependencies.
|
| 61 |
+
- CPU only: Uninstall torch, then follow the [CPU install](https://pytorch.org/) instructions.
|
| 62 |
|
| 63 |
## Mac
|
| 64 |
|
convert.py
CHANGED
|
@@ -92,14 +92,14 @@ if __name__ == "__main__":
|
|
| 92 |
storage=settings.RAY_CACHE_PATH,
|
| 93 |
_temp_dir=settings.RAY_CACHE_PATH,
|
| 94 |
dashboard_host=settings.RAY_DASHBOARD_HOST,
|
| 95 |
-
log_to_driver=
|
| 96 |
)
|
| 97 |
|
| 98 |
model_lst = load_all_models()
|
| 99 |
-
model_refs =
|
| 100 |
|
| 101 |
# Dynamically set GPU allocation per task based on GPU ram
|
| 102 |
-
gpu_frac = settings.
|
| 103 |
|
| 104 |
print(f"Converting {len(files_to_convert)} pdfs in chunk {args.chunk_idx + 1}/{args.num_chunks} with {total_processes} processes, and storing in {out_folder}")
|
| 105 |
futures = [
|
|
|
|
| 92 |
storage=settings.RAY_CACHE_PATH,
|
| 93 |
_temp_dir=settings.RAY_CACHE_PATH,
|
| 94 |
dashboard_host=settings.RAY_DASHBOARD_HOST,
|
| 95 |
+
log_to_driver=settings.DEBUG
|
| 96 |
)
|
| 97 |
|
| 98 |
model_lst = load_all_models()
|
| 99 |
+
model_refs = ray.put(model_lst)
|
| 100 |
|
| 101 |
# Dynamically set GPU allocation per task based on GPU ram
|
| 102 |
+
gpu_frac = settings.VRAM_PER_TASK / settings.INFERENCE_RAM if settings.CUDA else 0
|
| 103 |
|
| 104 |
print(f"Converting {len(files_to_convert)} pdfs in chunk {args.chunk_idx + 1}/{args.num_chunks} with {total_processes} processes, and storing in {out_folder}")
|
| 105 |
futures = [
|
install/apt-requirements.txt
CHANGED
|
@@ -2,6 +2,7 @@ tesseract-ocr
|
|
| 2 |
libtesseract-dev
|
| 3 |
libmagic1
|
| 4 |
ocrmypdf
|
|
|
|
| 5 |
tesseract-ocr-deu
|
| 6 |
tesseract-ocr-por
|
| 7 |
tesseract-ocr-spa
|
|
|
|
| 2 |
libtesseract-dev
|
| 3 |
libmagic1
|
| 4 |
ocrmypdf
|
| 5 |
+
tesseract-ocr-eng
|
| 6 |
tesseract-ocr-deu
|
| 7 |
tesseract-ocr-por
|
| 8 |
tesseract-ocr-spa
|
marker/settings.py
CHANGED
|
@@ -12,6 +12,9 @@ class Settings(BaseSettings):
|
|
| 12 |
TORCH_DEVICE: str = "cpu"
|
| 13 |
INFERENCE_RAM: int = 40 # How much VRAM each GPU has (in GB).
|
| 14 |
VRAM_PER_TASK: float = 2.5 # How much VRAM to allocate per task (in GB)
|
|
|
|
|
|
|
|
|
|
| 15 |
SUPPORTED_FILETYPES: Dict = {
|
| 16 |
"application/pdf": "pdf",
|
| 17 |
"application/epub+zip": "epub",
|
|
@@ -19,7 +22,6 @@ class Settings(BaseSettings):
|
|
| 19 |
"application/vnd.ms-xpsdocument": "xps",
|
| 20 |
"application/x-fictionbook+xml": "fb2"
|
| 21 |
}
|
| 22 |
-
DEFAULT_LANG: str = "English" # Default language we assume files to be in, should be one of the keys in TESSERACT_LANGUAGES
|
| 23 |
|
| 24 |
# PyMuPDF
|
| 25 |
TEXT_FLAGS: int = pymupdf.TEXTFLAGS_DICT & ~pymupdf.TEXT_PRESERVE_LIGATURES & ~pymupdf.TEXT_PRESERVE_IMAGES
|
|
@@ -48,7 +50,7 @@ class Settings(BaseSettings):
|
|
| 48 |
OCR_ALL_PAGES: bool = False # Run OCR on every page even if text can be extracted
|
| 49 |
OCR_PARALLEL_WORKERS: int = 4 # How many CPU workers to use for OCR
|
| 50 |
|
| 51 |
-
# Nougat
|
| 52 |
NOUGAT_MODEL_MAX: int = 512 # Max inference length for nougat
|
| 53 |
NOUGAT_TOKEN_BUFFER: int = 256 # Number of tokens to buffer above max for nougat
|
| 54 |
NOUGAT_HALLUCINATION_WORDS: List[str] = ["[MISSING_PAGE_POST]", "## References\n", "**Figure Captions**\n", "Footnote",
|
|
@@ -57,7 +59,7 @@ class Settings(BaseSettings):
|
|
| 57 |
NOUGAT_MODEL_NAME: str = "0.1.0-small" # Name of the model to use
|
| 58 |
NOUGAT_BATCH_SIZE: int = 4 if TORCH_DEVICE == "cuda" else 1 # Batch size for nougat, don't batch on cpu
|
| 59 |
|
| 60 |
-
# Layout
|
| 61 |
BAD_SPAN_TYPES: List[str] = ["Caption", "Footnote", "Page-footer", "Page-header", "Picture"]
|
| 62 |
LAYOUT_MODEL_MAX: int = 512
|
| 63 |
LAYOUT_CHUNK_OVERLAP: int = 64
|
|
|
|
| 12 |
TORCH_DEVICE: str = "cpu"
|
| 13 |
INFERENCE_RAM: int = 40 # How much VRAM each GPU has (in GB).
|
| 14 |
VRAM_PER_TASK: float = 2.5 # How much VRAM to allocate per task (in GB)
|
| 15 |
+
DEBUG: bool = False # Enable debug logging
|
| 16 |
+
DEFAULT_LANG: str = "English" # Default language we assume files to be in, should be one of the keys in TESSERACT_LANGUAGES
|
| 17 |
+
|
| 18 |
SUPPORTED_FILETYPES: Dict = {
|
| 19 |
"application/pdf": "pdf",
|
| 20 |
"application/epub+zip": "epub",
|
|
|
|
| 22 |
"application/vnd.ms-xpsdocument": "xps",
|
| 23 |
"application/x-fictionbook+xml": "fb2"
|
| 24 |
}
|
|
|
|
| 25 |
|
| 26 |
# PyMuPDF
|
| 27 |
TEXT_FLAGS: int = pymupdf.TEXTFLAGS_DICT & ~pymupdf.TEXT_PRESERVE_LIGATURES & ~pymupdf.TEXT_PRESERVE_IMAGES
|
|
|
|
| 50 |
OCR_ALL_PAGES: bool = False # Run OCR on every page even if text can be extracted
|
| 51 |
OCR_PARALLEL_WORKERS: int = 4 # How many CPU workers to use for OCR
|
| 52 |
|
| 53 |
+
# Nougat model
|
| 54 |
NOUGAT_MODEL_MAX: int = 512 # Max inference length for nougat
|
| 55 |
NOUGAT_TOKEN_BUFFER: int = 256 # Number of tokens to buffer above max for nougat
|
| 56 |
NOUGAT_HALLUCINATION_WORDS: List[str] = ["[MISSING_PAGE_POST]", "## References\n", "**Figure Captions**\n", "Footnote",
|
|
|
|
| 59 |
NOUGAT_MODEL_NAME: str = "0.1.0-small" # Name of the model to use
|
| 60 |
NOUGAT_BATCH_SIZE: int = 4 if TORCH_DEVICE == "cuda" else 1 # Batch size for nougat, don't batch on cpu
|
| 61 |
|
| 62 |
+
# Layout model
|
| 63 |
BAD_SPAN_TYPES: List[str] = ["Caption", "Footnote", "Page-footer", "Page-header", "Picture"]
|
| 64 |
LAYOUT_MODEL_MAX: int = 512
|
| 65 |
LAYOUT_CHUNK_OVERLAP: int = 64
|