Skip to main content

A library for working with IAM-OnDB database

Project description


iam-ondb-parser is a small python library created to simplify working with The IAM On-Line Handwriting Database (IAM-OnDB). It consists of a set of iterators providing convenient access to strokes, images, transcription text, meta-data, and other information.

The library can be used to:

  • generate training examples
  • explore the database
  • extract data from the database


  • Python 3
  • a local copy of The IAM-OnDB dataset

Downloading the dataset

Register an account on the website that hosts the IAM-OnDB:

Open a terminal, create a folder and change your current working directory to that folder:

mkdir iam_ondb
cd iam_ondb

Download all of the dataset files. You will be prompted to enter your password per each download (replace <user_name> with a user name that you registered with):

curl -u <user_name> -o original-xml-part.tar.gz
curl -u <user_name> -o writers.xml
curl -u <user_name> -o lineStrokes-all.tar.gz
curl -u <user_name> -o lineImages-all.tar.gz
curl -u <user_name> -o original-xml-all.tar.gz
curl -u <user_name> -o ascii-all.tar.gz

Or download files using the web browser from here:

Uncompress gzipped archives:

mkdir -p original-xml-part && tar -zxvf original-xml-part.tar.gz -C original-xml-part
mkdir -p lineStrokes-all && tar -zxvf lineStrokes-all.tar.gz -C lineStrokes-all
mkdir -p lineImages-all && tar -zxvf lineImages-all.tar.gz -C lineImages-all 
mkdir -p original-xml-all && tar -zxvf original-xml-all.tar.gz -C original-xml-all 
mkdir -p ascii-all && tar -zxvf ascii-all.tar.gz -C ascii-all

At the end the layout of the directory that contains the dataset should look as follows:













Without virtualenv (not recommended)

pip install iam-ondb-parser

Using virtualenv

Determine the location of the Python 3 executable. On Linux:

which python3

Create a new virtual environment (make sure to use python with version at least 3.5):

virtualenv --python=<path/to/python3/executable> venv

Activate the environment on Linux:

. venv/bin/activate

Activate the environment in the command prompt on Windows:


Finally, install the library from PyPI:

pip install iam-ondb-parser

Install manually by cloning the repository

Clone the repository

git clone
cd iam-ondb-parser

Install dependencies:

pip install -r requirements.txt

Quick start

Create an instance of the IAMonDB class by providing a path to the location of IAM-OnDB data set:

from iam_ondb import IAMonDB, bounded_iterator
path_to_db = 'iam_ondb'
db = IAMonDB(path_to_db)


Iterate over training examples in a for loop and exit it after just 1 iteration:

for stroke_set, image, line in db:
    print('transcription line: {}'.format(line))

You can also use the iterator directly:

it = db.__iter__()
stroke_set, image, line = next(it)
stroke_set, image, line = next(it)
stroke_set, image, line = next(it)

The dataset is quite big, so instead of iterating over all examples, you might want to only look at 500 examples. This can be done easily with bounded_iterator wrapper function.

This snippet will iterate over only 5 examples, for each of them it will show an image and print out the line of the transcription text:

for stroke_set, image, line in bounded_iterator(db, stop_index=5):
    input('Press any key to get to next example')

Iterate over lines of transcription text:

for line in bounded_iterator(db.get_text_lines(), 10):

Similarly, you can iterate over transcriptions (transcription objects contain additional meta-information):

for transcription in bounded_iterator(db.get_transcriptions(), stop_index=5):
    print(transcription.text + '\n')

Similarly, iterate over images:

for image in bounded_iterator(db.get_images(), stop_index=5):

There are also methods returning ids of different objects.

Get all writer ids:

ids = list(db.get_writer_ids())

Get first 10 ids of images:

ids = list(bounded_iterator(db.get_image_ids(), 10))

Get first 10 ids of stroke sets:

ids = list(bounded_iterator(db.get_stroke_set_ids(), 10))

Get first 10 ids of lines:

ids = list(bounded_iterator(db.get_text_line_ids(), 10))

Random access

Besides iterating over a set of objects, you can get a particular object by its id.

Get an image:


Get a stroke set:


Get a line:


Get information about a writer:


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for iam-ondb-parser, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size iam_ondb_parser-0.1.1-py3-none-any.whl (12.8 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size iam-ondb-parser-0.1.1.tar.gz (11.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page