Skip to main content

basic-document-classifier

A simple CNN for n-class classification of document images.

It doesn't take colour into account (it transforms to grayscale). For small numbers of classes (2 to 4) this model can achieve > 90% accuracy with as little as 10 to 30 training images per class. Training data can be provided in any image format supported by PIL.

Installation

pip install document-classifier or poetry add document-classifier

Usage

from document_classifier import CNN

# Create a classification model for 3 document classes.
classifier = CNN(class_number=3)

# Train the model based on images stored on the file system.
training_metrics = classifier.train(
    batch_size=8,
    epochs=40,
    train_data_path="./train_data",
    test_data_path="./test_data"
)
# "./train_data" and "./test_data" have to contain a subfolder for
# each document class, e.g. "./train_data/letter" or "./train_data/report".

# View training metrics like the validation accuracy on the test data.
print(training_metrics.history["val_acc"])

# Save the trained model to the file system.
classifier.save(model_path="./my_model")

# Load the model from the file system.
classifier = CNN.load(model_path="./my_model")

# Predict the class of some document image stored in the file system.
prediction = classifier.predict(image="./my_image.jpg")
# The image parameter also taks binary image data as a bytes object.

The prediction result is a 2-tuple containing the document class label as a string and the confidence score as a float.

Changes

0.1.2

  • Give every CNN instance its own isolated tensorflow graph and session

0.1.1

  • Fix a bug that occured when using multiple model instances at the same time

TODO

The model architecture is fixed for now and geared towards smaller numbers of classes and training images. I'm working on automatic scaling for the CNN.

Metadata

Release files for document-classifier 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for document-classifier 0.1.2
File Size Uploaded
document-classifier-0.1.2.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for document-classifier 0.1.2
File Interpreter ABI Platform
document_classifier-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.9 kB

Release files / document-classifier-0.1.2.tar.gz

Download URL document-classifier-0.1.2.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8ce1d133e0b5c08786d89d2faeace221f8e05c7daa7d60e7bf644695d8493fae
BLAKE2b-256 checksum
How to use checksums
d568df9f7529410061fe15eb6e7150b6ab7c955366c7bbfcd070c9c06b5271c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.12 CPython/3.6.5 Windows/10

Release files / document_classifier-0.1.2-py3-none-any.whl

Download URL document_classifier-0.1.2-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c08159b70d52a697dfdf711d07dc1038d468662db42f5e4d8b204695fc4385d
BLAKE2b-256 checksum
How to use checksums
0102987b9f5d70442023b41e7b931346baf024aeb904dfca4c21b1f88b8ca33f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.12 CPython/3.6.5 Windows/10

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page