Passport detection service
Usage
Run the service
Since some dependencies of the service are platform dependent (ARM64 vs X86_64), a small wrapper around the
docker compose command was created to run the service.
You can use it just like docker compose:
./passport-service up -d
or
./passport-service up
API documentation
Once the service is up the API documentation is available at http://localhost:8080/docs.
Detect passports
Model
Place your YOLO model exported as a .onnx file in the data/models directory.
Make sure it's correctly exported for batch processing (see how to do it here).
Data
To detect passport you first need to place your documents inside the data/passports directory.
Preprocessing
To process passport run:
curl -X 'POST' \
'http://localhost:8080/passports/preprocessing-tasks' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"docs": "my_doc_dir",
"detection_args": {"model_path": "model_v0.onnx"},
"batch_size": 64
}'
This will return you something like:
create-preprocessing-tasks-fd05a3b4d2774b269001cccce2fcf073
You can follow the task progress running:
curl -X 'GET' 'http://localhost:8080/tasks/create-preprocessing-tasks-fd05a3b4d2774b269001cccce2fcf073' \
-H 'accept: application/json'
and read the progress from the response.
Then when it's done, you can get the list of preprocessing tasks you can call:
curl -X 'GET' 'http://localhost:8080/tasks/create-preprocessing-tasks-fd05a3b4d2774b269001cccce2fcf073/result' \
-H 'accept: application/json'
Similarly, you can follow each preprocessing task progress.
Preprocessing task will then trigger passport detection on the output of the preprocessing.
You can get the ID of the created detection task from the preprocessing task result:
curl -X 'GET' 'http://localhost:8080/tasks/preprocess-docss-090943423909090000/result' \
-H 'accept: application/json'
When the deteection task is done, you can also call the above API with it ID to get the final output which should look like this:
[
{
"doc_path": "passports/passport.odt",
"doc_pages": [
{
"page": 0,
"passports": [
{
"class_id": "passport",
"confidence": 0.9391622543334961,
"box": [
57.185882568359375,
216.44244384765625,
375.8140869140625,
283.35162353515625
],
"scale": 1.2375,
"mrz": {
"country": "EOL",
"metadata": {
"mrz_type": "TD3",
"valid_score": 62,
"raw_text": "P<EOLSMITH<<JANE<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n01PP300009EOL8107145F2212315<<<<<<<<<<<<<<02",
"type": "P<",
"country": "EOL",
"number": "01PP30000",
"date_of_birth": "810714",
"expiration_date": "221231",
"nationality": "EOL",
"sex": "F",
"names": "JANE",
"surname": "SMITH",
"personal_number": "<<<<<<<<<<<<<<",
"check_number": "9",
"check_date_of_birth": "5",
"check_expiration_date": "5",
"check_composite": "2",
"check_personal_number": "0",
"valid_number": false,
"valid_date_of_birth": true,
"valid_expiration_date": true,
"valid_composite": false,
"valid_personal_number": true,
"method": "direct"
}
}
},
{
"class_id": "passport",
"confidence": 0.9231931567192078,
"box": [
58.3187255859375,
54.883644104003906,
373.454345703125,
185.15440368652344
],
"scale": 1.2375,
"mrz": null
}
]
}
]
},
{
"doc_path": "passports/not_a_passport.jpg",
"doc_pages": []
}
]
Notice that for each document, only pages with passports inside them are reported. On these page, there can be many passport pages, the algorithm outputs a bounding box and optionally a Machine Readable Zone (MRZ) for each one of these pages.
Coming soon...
- pipelined pre-processing and detection
Note on ONNX export and dynamic batch size
To overcome some OpenCV limitations, export the pytorch checkpoint using:
model.export(
format="onnx", imgsz=640, dynamic=True, opset=12, verbose=True, simplify=True
)
Then, follow the instructions of this issue to make OpenCV work with dynamic batch size.
- simplify using
onnxsim - set the
heightandwidthusing:
python -m onnxruntime.tools.make_dynamic_shape_fixed --dim_param <param> --dim_value 640 <input> <output>
Metadata
Release files for icij-passport-core 0.11.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| icij_passport_core-0.11.8.tar.gz | 14.6 MB | Without provenance | Details for icij_passport_core-0.11.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| icij_passport_core-0.11.8-py3-none-any.whl | Python 3 | none | any | Details for icij_passport_core-0.11.8-py3-none-any.whl |
Total release size: 25.5 MB
Release files / icij_passport_core-0.11.8.tar.gz
| Download URL | icij_passport_core-0.11.8.tar.gz |
|---|---|
| Size | 14.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
04faedb121327cece97e17168900d6e857e59be91c5dfb5a20f33dda82b9945d
|
|
BLAKE2b-256 checksum How to use checksums |
76da958dd0517213a359c4ba9a0d7fd5eacdfb325fe1f46b886918f04df16042
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / icij_passport_core-0.11.8-py3-none-any.whl
| Download URL | icij_passport_core-0.11.8-py3-none-any.whl |
|---|---|
| Size | 11.0 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a4c73d67f96fd03d8e6d8dd7f2d34bb6b4427c507e75a5fb5180f2bd30d6b790
|
|
BLAKE2b-256 checksum How to use checksums |
266ae4f391896dc200fb2288beb26ce9892dd180821c6d96f80108784a012850
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for icij-passport-core 0.11.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.