--- datasets: - Riksarkivet/trolldomskommissionen_seg - Riksarkivet/svea_hovratt_seg - Riksarkivet/krigshovrattens_dombocker_seg - Riksarkivet/jonkopings_radhusratts_och_magistrat_seg - Riksarkivet/gota_hovratt_seg - Riksarkivet/frihetstidens_utskottshandlingar_seg - Riksarkivet/bergskollegium_relationer_och_skrivelser_seg - Riksarkivet/bergskollegium_advokatfiskalskontoret_seg tags: - instance segmentation - handwritten - htr - text lines library_name: htrflow --- # Yolov9-lines-within-regions-handwritten A yolov9 instance segmentation model for segmenting text-lines within text-regions. To be used after text-regions segmentation as part of an HTR-pipeline ## Model Details ### Model Description This model was developed for segmenting text-lines within text-regions in handwritten running-text documents. It wont work on full pages but only on cropped text-regions. It is meant to be implemented in an HTR-pipeline where one first segment text-regions, then text-lines within the regions, and then feed these text-lines to an HTR-model. - **Developed by:** The Swedish National Archives - **Model type:** yolov9 - **License:** [More Information Needed] ### Model Sources - **Repository:** [yolov9-lines_within_regions-1](https://huggingface.co/Riksarkivet/yolov9-lines-within-regions-1) - **Paper:** [YOLOv9: Learning What You Want to Learn Using Programmable Gradient Information](https://arxiv.org/abs/2402.13616) ## Uses ### Direct Use Segment text-lines within text-regions as part of an HTR-pipeline for handwritten running-text documents ### Downstream Use As part of an HTR-pipeline for transcribing entire pages of handwritten running-text documents. See [Swedish Lion Libre](https://huggingface.co/Riksarkivet/trocr-base-handwritten-hist-swe-2) for example usage with the [HTRflow package](https://github.com/AI-Riksarkivet/htrflow) ## How to Get Started with the Model ### How to Load and Use the YOLOv9 Instance Segmentation Model Below is the Python code to load and use the trained YOLOv9 instance segmentation model using the Ultralytics repo: ```python import torch from ultralytics import YOLO # Load the trained YOLOv9 model model = YOLO('path/to/your/model.pt') # Update with the correct path to your trained model # Load an image img = 'path/to/your/image.jpg' # Update with the path to the image you want to use # Perform instance segmentation results = model(img) # Display results results.show() # Show image with predicted masks # To get the raw predictions (bounding boxes, masks, etc.) for result in results: print(result.boxes) # Bounding boxes print(result.masks) # Segmentation masks ``` ### Usage with the HTRflow package See the model card for [Swedish Lion Libre](https://huggingface.co/Riksarkivet/trocr-base-handwritten-hist-swe-2) for example usage with the [HTRflow package](https://github.com/AI-Riksarkivet/htrflow), or refer to the documentation for [HTRflow](https://github.com/AI-Riksarkivet/htrflow) ## Training Details ### Training Data [Trolldomskommissionen](https://huggingface.co/datasets/Riksarkivet/trolldomskommissionen_seg) [Svea Hovrätt](https://huggingface.co/datasets/Riksarkivet/svea_hovratt_seg) [Krigshovrättens domböcker](https://huggingface.co/datasets/Riksarkivet/krigshovrattens_dombocker_seg) [Jönköpings rådhusrätt och magistrat](https://huggingface.co/datasets/Riksarkivet/jonkopings_radhusratts_och_magistrat_seg) [Göta hovrätt](https://huggingface.co/datasets/Riksarkivet/gota_hovratt_seg) [Frihetstidens utskottshandlingar](https://huggingface.co/datasets/Riksarkivet/frihetstidens_utskottshandlingar_seg) [Bergskollegium relationer och skrivelser](https://huggingface.co/datasets/Riksarkivet/bergskollegium_relationer_och_skrivelser_seg) [Bergskollegium advokatfiskalkontoret](https://huggingface.co/datasets/Riksarkivet/bergskollegium_advokatfiskalskontoret_seg) ### Training Procedure #### Training Hyperparameters See [training config](https://huggingface.co/Riksarkivet/yolov9-lines-within-regions/blob/main/args.yaml) at model repo ## Evaluation See [training results](https://huggingface.co/Riksarkivet/yolov9-lines-within-regions-1/blob/main/results.csv) #### Metrics Standard metrics for instance segmentation. Note that evaluation of segmentation as part of an HTR-pipeline should be measured by what effect it has on the following HTR, that is, CER and WER for the entire page. For implementation and evaluation of entire HTR-pipelines, please check out [HTRflow](https://github.com/AI-Riksarkivet/htrflow), the Swedish National Archive's open-source package for HTR and OCR projects. ### Model Architecture and Objective yolov9 #### Software [Ultralytics](https://github.com/ultralytics) ## Citation [YOLOv9: Learning What You Want to Learn Using Programmable Gradient Information](https://arxiv.org/abs/2402.13616)