Metadata-Version: 2.1
Name: document-classifier
Version: 0.1.0
Summary: A simple CNN for n-class classification of document images.
Home-page: https://github.com/sbischoff-ai/basic-document-classifier
License: MIT
Keywords: document,image,classification,deep,learning
Author: Silas Bischoff
Author-email: silas.bischoff@googlemail.com
Requires-Python: >=3.6,<4.0
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Intended Audience :: Legal Industry
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Image Recognition
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: keras (>=2.2,<3.0)
Requires-Dist: numpy (>=1.17,<2.0)
Requires-Dist: pillow (>=6.1,<7.0)
Requires-Dist: tensorflow-gpu (>=1.14,<2.0)
Project-URL: Repository, https://github.com/sbischoff-ai/basic-document-classifier
Description-Content-Type: text/markdown

# 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 images per class.

## Installation

```pip install document-classifier```
or
```poetry add document-classifier```

## Usage

```python
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.

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

