Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'mindee:main' into main
Browse files Browse the repository at this point in the history
felixdittrich92 authored Nov 15, 2021
2 parents 9099e95 + 2a4e2b4 commit 23eca0d
Showing 10 changed files with 118 additions and 6 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
<img src="https://github.com/mindee/doctr/releases/download/v0.3.1/Logo_doctr.gif" width="40%">
</p>

[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) ![Build Status](https://github.com/mindee/doctr/workflows/builds/badge.svg) [![codecov](https://codecov.io/gh/mindee/doctr/branch/main/graph/badge.svg?token=577MO567NM)](https://codecov.io/gh/mindee/doctr) [![CodeFactor](https://www.codefactor.io/repository/github/mindee/doctr/badge?s=bae07db86bb079ce9d6542315b8c6e70fa708a7e)](https://www.codefactor.io/repository/github/mindee/doctr) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/340a76749b634586a498e1c0ab998f08)](https://app.codacy.com/gh/mindee/doctr?utm_source=github.com&utm_medium=referral&utm_content=mindee/doctr&utm_campaign=Badge_Grade) [![Doc Status](https://github.com/mindee/doctr/workflows/doc-status/badge.svg)](https://mindee.github.io/doctr) [![Pypi](https://img.shields.io/badge/pypi-v0.4.0-blue.svg)](https://pypi.org/project/python-doctr/) [![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/mindee/doctr)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) ![Build Status](https://github.com/mindee/doctr/workflows/builds/badge.svg) [![codecov](https://codecov.io/gh/mindee/doctr/branch/main/graph/badge.svg?token=577MO567NM)](https://codecov.io/gh/mindee/doctr) [![CodeFactor](https://www.codefactor.io/repository/github/mindee/doctr/badge?s=bae07db86bb079ce9d6542315b8c6e70fa708a7e)](https://www.codefactor.io/repository/github/mindee/doctr) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/340a76749b634586a498e1c0ab998f08)](https://app.codacy.com/gh/mindee/doctr?utm_source=github.com&utm_medium=referral&utm_content=mindee/doctr&utm_campaign=Badge_Grade) [![Doc Status](https://github.com/mindee/doctr/workflows/doc-status/badge.svg)](https://mindee.github.io/doctr) [![Pypi](https://img.shields.io/badge/pypi-v0.4.0-blue.svg)](https://pypi.org/project/python-doctr/) [![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/mindee/doctr) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mindee/notebooks/blob/main/doctr/quicktour.ipynb)


**Optical Character Recognition made seamless & accessible to anyone, powered by TensorFlow 2 & PyTorch**
@@ -225,12 +225,14 @@ Your API should now be running locally on your port 8002. Access your automatica
```python

import requests
import io
with open('/path/to/your/doc.jpg', 'rb') as f:
data = f.read()
response = requests.post("http://localhost:8002/ocr", files={'file': io.BytesIO(data)}).json()
response = requests.post("http://localhost:8002/ocr", files={'file': data}).json()
```

### Example notebooks
Looking for more illustrations of docTR features? You might want to check the [Jupyter notebooks](https://github.com/mindee/doctr/tree/main/notebooks) designed to give you a broader overview.


## Citation

92 changes: 92 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Template for your OCR API using docTR

## Installation

You will only need to install [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) and [Docker](https://docs.docker.com/get-docker/). The container environment will be self-sufficient and install the remaining dependencies on its own.

## Usage

### Starting your web server

You will need to clone the repository first:
```shell
git clone https://github.com/mindee/doctr.git
```
then from the repo root folder, you can start your container:

```shell
PORT=8050 docker-compose up -d --build
```
Once completed, your [FastAPI](https://fastapi.tiangolo.com/) server should be running on port 8050 (feel free to change this in the previous command).

### Documentation and swagger

FastAPI comes with many advantages including speed and OpenAPI features. For instance, once your server is running, you can access the automatically built documentation and swagger in your browser at: http://localhost:8050/docs


### Using the routes

You will find detailed instructions in the live documentation when your server is up, but here are some examples to use your available API routes:

#### Text detection

Using the following image:
<img src="https://user-images.githubusercontent.com/76527547/117319856-fc35bf00-ae8b-11eb-9b51-ca5aba673466.jpg" width="50%" height="50%">

with this snippet:

```python
import requests
with open('/path/to/your/img.jpg', 'rb') as f:
data = f.read()
print(requests.post("http://localhost:8050/detection", files={'file': data}).json())
```

should yield
```
[{'box': [0.826171875, 0.185546875, 0.90234375, 0.201171875]},
{'box': [0.75390625, 0.185546875, 0.8173828125, 0.201171875]}]
```


#### Text recognition

Using the following image:
![recognition-sample](https://user-images.githubusercontent.com/76527547/117133599-c073fa00-ada4-11eb-831b-412de4d28341.jpeg)

with this snippet:

```python
import requests
with open('/path/to/your/img.jpg', 'rb') as f:
data = f.read()
print(requests.post("http://localhost:8050/recognition", files={'file': data}).json())
```

should yield
```
{'value': 'invite'}
```


#### End-to-end OCR

Using the following image:
<img src="https://user-images.githubusercontent.com/76527547/117319856-fc35bf00-ae8b-11eb-9b51-ca5aba673466.jpg" width="50%" height="50%">

with this snippet:

```python
import requests
with open('/path/to/your/img.jpg', 'rb') as f:
data = f.read()
print(requests.post("http://localhost:8050/ocr", files={'file': data}).json())
```

should yield
```
[{'box': [0.75390625, 0.185546875, 0.8173828125, 0.201171875],
'value': 'Hello'},
{'box': [0.826171875, 0.185546875, 0.90234375, 0.201171875],
'value': 'world!'}]
```
2 changes: 2 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -3,3 +3,5 @@ sphinx-rtd-theme==0.4.3
sphinxemoji>=0.1.8
sphinx-copybutton>=0.3.1
docutils<0.18
recommonmark>=0.7.1
sphinx-markdown-tables>=0.0.15
4 changes: 3 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -45,6 +45,8 @@
'sphinx.ext.autosectionlabel',
'sphinxemoji.sphinxemoji', # cf. https://sphinxemojicodes.readthedocs.io/en/stable/
'sphinx_copybutton',
'recommonmark',
'sphinx_markdown_tables',
]

napoleon_use_ivar = True
@@ -55,7 +57,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = [u'_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = [u'_build', 'Thumbs.db', '.DS_Store', 'notebooks/*.rst']


# The name of the Pygments (syntax highlighting) style to use.
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ Main Features
:hidden:

installing
notebooks


Model zoo
1 change: 1 addition & 0 deletions docs/source/notebooks.md
2 changes: 1 addition & 1 deletion doctr/models/recognition/sar/pytorch.py
Original file line number Diff line number Diff line change
@@ -98,7 +98,7 @@ def forward(

# initialize states (each of shape (N, rnn_units))
hx = [None, None]
# Initialize with the index of virtual START symbol (placed after <eos>)
# Initialize with the index of virtual START symbol (placed after <eos> so that the one-hot is only zeros)
symbol = torch.zeros((features.shape[0], self.vocab_size + 1), device=features.device, dtype=features.dtype)
logits_list = []
for t in range(self.max_length + 1): # keep 1 step for <eos>
2 changes: 1 addition & 1 deletion doctr/models/recognition/sar/tensorflow.py
Original file line number Diff line number Diff line change
@@ -132,7 +132,7 @@ def call(
# run first step of lstm
# holistic: shape (N, rnn_units)
_, states = self.lstm_decoder(holistic, states, **kwargs)
# Initialize with the index of virtual START symbol (placed after <eos>)
# Initialize with the index of virtual START symbol (placed after <eos> so that the one-hot is only zeros)
symbol = tf.fill(features.shape[0], self.vocab_size + 1)
logits_list = []
if kwargs.get('training') and gt is None:
8 changes: 8 additions & 0 deletions notebooks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# docTR Notebooks

Here are some notebooks compiled for users to better leverage the library capabilities:

| Notebook | Description | |
|:----------|:-------------|------:|
| [Quicktour](https://github.com/mindee/notebooks/blob/main/doctr/quicktour.ipynb) | A presentation of the main features of docTR | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mindee/notebooks/blob/main/doctr/quicktour.ipynb) |

4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -74,6 +74,8 @@
"sphinxemoji>=0.1.8",
"sphinx-copybutton>=0.3.1",
"docutils<0.18",
"recommonmark>=0.7.1",
"sphinx-markdown-tables>=0.0.15",
]

deps = {b: a for a, b in (re.findall(r"^(([^!=<>]+)(?:[!=<>].*)?$)", x)[0] for x in _deps)}
@@ -142,6 +144,8 @@ def deps_list(*pkgs):
"sphinxemoji",
"sphinx-copybutton",
"docutils",
"recommonmark",
"sphinx-markdown-tables",
)

extras["docs"] = extras["all"] + extras["docs_specific"]

0 comments on commit 23eca0d

Please sign in to comment.