Skip to main content

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

Project description

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.1

  • Fix a bug that occurs 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.

Project details


Download files

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

Source Distribution

document-classifier-0.1.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

document_classifier-0.1.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file document-classifier-0.1.1.tar.gz.

File metadata

  • Download URL: document-classifier-0.1.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.12 CPython/3.6.5 Windows/10

File hashes

Hashes for document-classifier-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7c2889dba345c80de72e116d6799cfa875b5325a446654153183a91bf7250542
MD5 e6caaf04e20ccd00ea0acaa40e35295d
BLAKE2b-256 674f3b5ffedbbb68f391344c756b156be83cc9adab9b9a85ddb5a1be4bc4875c

See more details on using hashes here.

File details

Details for the file document_classifier-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for document_classifier-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ece629f44883bc26878a277dbf2b7cb953a21b36482c71894402f4c35400d049
MD5 eb8d3bdbd14e4bc69d9f89772bfc87ca
BLAKE2b-256 47ef68df59c4d849c2c749a259ce1cbf41e0793e8f1ac6a742dcec57d4fe213f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page