├── .gitignore ├── LICENSE ├── README.md ├── data ├── test │ ├── 021 │ │ ├── forged-01.png │ │ ├── forged-02.png │ │ ├── forged-03.png │ │ ├── forged-04.png │ │ ├── forged-05.png │ │ ├── forged-06.png │ │ ├── forged-another-01.png │ │ ├── forged-another-02.png │ │ ├── forged-another-03.png │ │ ├── forged-another-04.png │ │ ├── forged-another-05.png │ │ ├── forged-another-06.png │ │ ├── genuine-01.png │ │ ├── genuine-02.png │ │ ├── genuine-03.png │ │ ├── genuine-04.png │ │ ├── genuine-05.png │ │ ├── genuine-06.png │ │ ├── genuine-07.png │ │ ├── genuine-08.png │ │ ├── genuine-09.png │ │ ├── genuine-10.png │ │ ├── genuine-11.png │ │ └── genuine-12.png │ ├── 024 │ │ ├── forged-01.png │ │ ├── forged-02.png │ │ ├── forged-03.png │ │ ├── forged-04.png │ │ ├── forged-05.png │ │ ├── forged-06.png │ │ ├── forged-07.png │ │ ├── forged-08.png │ │ ├── forged-09.png │ │ ├── forged-10.png │ │ ├── forged-11.png │ │ ├── forged-12.png │ │ ├── genuine-01.png │ │ ├── genuine-02.png │ │ ├── genuine-03.png │ │ ├── genuine-04.png │ │ ├── genuine-05.png │ │ ├── genuine-06.png │ │ ├── genuine-07.png │ │ ├── genuine-08.png │ │ ├── genuine-09.png │ │ ├── genuine-10.png │ │ ├── genuine-11.png │ │ └── genuine-12.png │ └── 029 │ │ ├── forged-01.png │ │ ├── forged-02.png │ │ ├── forged-03.png │ │ ├── forged-04.png │ │ ├── forged-05.png │ │ ├── forged-06.png │ │ ├── forged-07.png │ │ ├── forged-08.png │ │ ├── forged-09.png │ │ ├── forged-10.png │ │ ├── forged-11.png │ │ ├── forged-12.png │ │ ├── genuine-01.png │ │ ├── genuine-02.png │ │ ├── genuine-03.png │ │ ├── genuine-04.png │ │ ├── genuine-05.png │ │ ├── genuine-06.png │ │ ├── genuine-07.png │ │ ├── genuine-08.png │ │ ├── genuine-09.png │ │ ├── genuine-10.png │ │ ├── genuine-11.png │ │ └── genuine-12.png └── training │ ├── 021 │ ├── forged-01.png │ ├── forged-02.png │ ├── forged-03.png │ ├── forged-04.png │ ├── forged-05.png │ ├── forged-06.png │ ├── forged-another-01.png │ ├── forged-another-02.png │ ├── forged-another-03.png │ ├── forged-another-04.png │ ├── forged-another-05.png │ ├── forged-another-06.png │ ├── genuine-01.png │ ├── genuine-02.png │ ├── genuine-03.png │ ├── genuine-04.png │ ├── genuine-05.png │ ├── genuine-06.png │ ├── genuine-07.png │ ├── genuine-08.png │ ├── genuine-09.png │ ├── genuine-10.png │ ├── genuine-11.png │ └── genuine-12.png │ ├── 024 │ ├── forged-01.png │ ├── forged-02.png │ ├── forged-03.png │ ├── forged-04.png │ ├── forged-05.png │ ├── forged-06.png │ ├── forged-07.png │ ├── forged-08.png │ ├── forged-09.png │ ├── forged-10.png │ ├── forged-11.png │ ├── forged-12.png │ ├── genuine-01.png │ ├── genuine-02.png │ ├── genuine-03.png │ ├── genuine-04.png │ ├── genuine-05.png │ ├── genuine-06.png │ ├── genuine-07.png │ ├── genuine-08.png │ ├── genuine-09.png │ ├── genuine-10.png │ ├── genuine-11.png │ └── genuine-12.png │ └── 029 │ ├── forged-01.png │ ├── forged-02.png │ ├── forged-03.png │ ├── forged-04.png │ ├── forged-05.png │ ├── forged-06.png │ ├── forged-07.png │ ├── forged-08.png │ ├── forged-09.png │ ├── forged-10.png │ ├── forged-11.png │ ├── forged-12.png │ ├── genuine-01.png │ ├── genuine-02.png │ ├── genuine-03.png │ ├── genuine-04.png │ ├── genuine-05.png │ ├── genuine-06.png │ ├── genuine-07.png │ ├── genuine-08.png │ ├── genuine-09.png │ ├── genuine-10.png │ └── genuine-11.png ├── network.py ├── preprocessor.py ├── setup.py ├── sigrecog.py └── sigrecogtf.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | 3 | # C extensions 4 | *.so 5 | 6 | # Packages 7 | *.egg 8 | *.egg-info 9 | dist 10 | build 11 | eggs 12 | parts 13 | bin 14 | var 15 | sdist 16 | out 17 | develop-eggs 18 | .installed.cfg 19 | lib 20 | lib64 21 | __pycache__ 22 | 23 | # Installer logs 24 | pip-log.txt 25 | 26 | # Unit test / coverage reports 27 | .coverage 28 | .tox 29 | nosetests.xml 30 | 31 | # Translations 32 | *.mo 33 | 34 | # Mr Developer 35 | .mr.developer.cfg 36 | .project 37 | .pydevproject 38 | 39 | .idea 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Signature Recognition ✍️ 2 | 3 | Verify the authenticity of handwritten signatures through digital image processing and neural networks. 4 | 5 | This is an **experimental project** built during our research on the usage of AI throughout the most diverse fields. 6 | 7 | ## Dataset 8 | We got the dataset from [ICDAR 2009 Signature Verification Competition (SigComp2009)](http://www.iapr-tc11.org/mediawiki/index.php?title=ICDAR_2009_Signature_Verification_Competition_(SigComp2009)). 9 | 10 | ## Usage 11 | - `python sigrecog.py` runs using our backpropagation neural network implementation 12 | - `python sigrecogtf.py` runs using a tensorflow model based on logistic regression 13 | 14 | ## Built with 15 | - OpenCV 16 | - Tensorflow 17 | 18 | ## Requirements 19 | - Python 3.6 20 | - OpenCV 3.2 21 | - Numpy 22 | - Tensorflow 23 | 24 | ## Contributors 25 | 26 | 27 | 28 | 34 | 40 | 41 |
29 | 30 | Guilherme's avatar
31 | Guilherme Baron 32 |
33 |
35 | 36 | Anisio's
37 | Anisio Marques Junior 38 |
39 |
42 | 43 | 44 | -------------------------------------------------------------------------------- /data/test/021/forged-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/forged-01.png -------------------------------------------------------------------------------- /data/test/021/forged-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/forged-02.png -------------------------------------------------------------------------------- /data/test/021/forged-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/forged-03.png -------------------------------------------------------------------------------- /data/test/021/forged-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/forged-04.png -------------------------------------------------------------------------------- /data/test/021/forged-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/forged-05.png -------------------------------------------------------------------------------- /data/test/021/forged-06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/forged-06.png -------------------------------------------------------------------------------- /data/test/021/forged-another-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/forged-another-01.png -------------------------------------------------------------------------------- /data/test/021/forged-another-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/forged-another-02.png -------------------------------------------------------------------------------- /data/test/021/forged-another-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/forged-another-03.png -------------------------------------------------------------------------------- /data/test/021/forged-another-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/forged-another-04.png -------------------------------------------------------------------------------- /data/test/021/forged-another-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/forged-another-05.png -------------------------------------------------------------------------------- /data/test/021/forged-another-06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/forged-another-06.png -------------------------------------------------------------------------------- /data/test/021/genuine-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/genuine-01.png -------------------------------------------------------------------------------- /data/test/021/genuine-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/genuine-02.png -------------------------------------------------------------------------------- /data/test/021/genuine-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/genuine-03.png -------------------------------------------------------------------------------- /data/test/021/genuine-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/genuine-04.png -------------------------------------------------------------------------------- /data/test/021/genuine-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/genuine-05.png -------------------------------------------------------------------------------- /data/test/021/genuine-06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/genuine-06.png -------------------------------------------------------------------------------- /data/test/021/genuine-07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/genuine-07.png -------------------------------------------------------------------------------- /data/test/021/genuine-08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/genuine-08.png -------------------------------------------------------------------------------- /data/test/021/genuine-09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/genuine-09.png -------------------------------------------------------------------------------- /data/test/021/genuine-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/genuine-10.png -------------------------------------------------------------------------------- /data/test/021/genuine-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/genuine-11.png -------------------------------------------------------------------------------- /data/test/021/genuine-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/021/genuine-12.png -------------------------------------------------------------------------------- /data/test/024/forged-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/forged-01.png -------------------------------------------------------------------------------- /data/test/024/forged-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/forged-02.png -------------------------------------------------------------------------------- /data/test/024/forged-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/forged-03.png -------------------------------------------------------------------------------- /data/test/024/forged-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/forged-04.png -------------------------------------------------------------------------------- /data/test/024/forged-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/forged-05.png -------------------------------------------------------------------------------- /data/test/024/forged-06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/forged-06.png -------------------------------------------------------------------------------- /data/test/024/forged-07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/forged-07.png -------------------------------------------------------------------------------- /data/test/024/forged-08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/forged-08.png -------------------------------------------------------------------------------- /data/test/024/forged-09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/forged-09.png -------------------------------------------------------------------------------- /data/test/024/forged-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/forged-10.png -------------------------------------------------------------------------------- /data/test/024/forged-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/forged-11.png -------------------------------------------------------------------------------- /data/test/024/forged-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/forged-12.png -------------------------------------------------------------------------------- /data/test/024/genuine-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/genuine-01.png -------------------------------------------------------------------------------- /data/test/024/genuine-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/genuine-02.png -------------------------------------------------------------------------------- /data/test/024/genuine-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/genuine-03.png -------------------------------------------------------------------------------- /data/test/024/genuine-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/genuine-04.png -------------------------------------------------------------------------------- /data/test/024/genuine-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/genuine-05.png -------------------------------------------------------------------------------- /data/test/024/genuine-06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/genuine-06.png -------------------------------------------------------------------------------- /data/test/024/genuine-07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/genuine-07.png -------------------------------------------------------------------------------- /data/test/024/genuine-08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/genuine-08.png -------------------------------------------------------------------------------- /data/test/024/genuine-09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/genuine-09.png -------------------------------------------------------------------------------- /data/test/024/genuine-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/genuine-10.png -------------------------------------------------------------------------------- /data/test/024/genuine-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/genuine-11.png -------------------------------------------------------------------------------- /data/test/024/genuine-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/024/genuine-12.png -------------------------------------------------------------------------------- /data/test/029/forged-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/forged-01.png -------------------------------------------------------------------------------- /data/test/029/forged-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/forged-02.png -------------------------------------------------------------------------------- /data/test/029/forged-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/forged-03.png -------------------------------------------------------------------------------- /data/test/029/forged-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/forged-04.png -------------------------------------------------------------------------------- /data/test/029/forged-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/forged-05.png -------------------------------------------------------------------------------- /data/test/029/forged-06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/forged-06.png -------------------------------------------------------------------------------- /data/test/029/forged-07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/forged-07.png -------------------------------------------------------------------------------- /data/test/029/forged-08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/forged-08.png -------------------------------------------------------------------------------- /data/test/029/forged-09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/forged-09.png -------------------------------------------------------------------------------- /data/test/029/forged-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/forged-10.png -------------------------------------------------------------------------------- /data/test/029/forged-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/forged-11.png -------------------------------------------------------------------------------- /data/test/029/forged-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/forged-12.png -------------------------------------------------------------------------------- /data/test/029/genuine-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/genuine-01.png -------------------------------------------------------------------------------- /data/test/029/genuine-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/genuine-02.png -------------------------------------------------------------------------------- /data/test/029/genuine-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/genuine-03.png -------------------------------------------------------------------------------- /data/test/029/genuine-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/genuine-04.png -------------------------------------------------------------------------------- /data/test/029/genuine-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/genuine-05.png -------------------------------------------------------------------------------- /data/test/029/genuine-06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/genuine-06.png -------------------------------------------------------------------------------- /data/test/029/genuine-07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/genuine-07.png -------------------------------------------------------------------------------- /data/test/029/genuine-08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/genuine-08.png -------------------------------------------------------------------------------- /data/test/029/genuine-09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/genuine-09.png -------------------------------------------------------------------------------- /data/test/029/genuine-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/genuine-10.png -------------------------------------------------------------------------------- /data/test/029/genuine-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/genuine-11.png -------------------------------------------------------------------------------- /data/test/029/genuine-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/test/029/genuine-12.png -------------------------------------------------------------------------------- /data/training/021/forged-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/forged-01.png -------------------------------------------------------------------------------- /data/training/021/forged-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/forged-02.png -------------------------------------------------------------------------------- /data/training/021/forged-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/forged-03.png -------------------------------------------------------------------------------- /data/training/021/forged-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/forged-04.png -------------------------------------------------------------------------------- /data/training/021/forged-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/forged-05.png -------------------------------------------------------------------------------- /data/training/021/forged-06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/forged-06.png -------------------------------------------------------------------------------- /data/training/021/forged-another-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/forged-another-01.png -------------------------------------------------------------------------------- /data/training/021/forged-another-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/forged-another-02.png -------------------------------------------------------------------------------- /data/training/021/forged-another-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/forged-another-03.png -------------------------------------------------------------------------------- /data/training/021/forged-another-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/forged-another-04.png -------------------------------------------------------------------------------- /data/training/021/forged-another-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/forged-another-05.png -------------------------------------------------------------------------------- /data/training/021/forged-another-06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/forged-another-06.png -------------------------------------------------------------------------------- /data/training/021/genuine-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/genuine-01.png -------------------------------------------------------------------------------- /data/training/021/genuine-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/genuine-02.png -------------------------------------------------------------------------------- /data/training/021/genuine-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/genuine-03.png -------------------------------------------------------------------------------- /data/training/021/genuine-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/genuine-04.png -------------------------------------------------------------------------------- /data/training/021/genuine-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/genuine-05.png -------------------------------------------------------------------------------- /data/training/021/genuine-06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/genuine-06.png -------------------------------------------------------------------------------- /data/training/021/genuine-07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/genuine-07.png -------------------------------------------------------------------------------- /data/training/021/genuine-08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/genuine-08.png -------------------------------------------------------------------------------- /data/training/021/genuine-09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/genuine-09.png -------------------------------------------------------------------------------- /data/training/021/genuine-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/genuine-10.png -------------------------------------------------------------------------------- /data/training/021/genuine-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/genuine-11.png -------------------------------------------------------------------------------- /data/training/021/genuine-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/021/genuine-12.png -------------------------------------------------------------------------------- /data/training/024/forged-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/forged-01.png -------------------------------------------------------------------------------- /data/training/024/forged-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/forged-02.png -------------------------------------------------------------------------------- /data/training/024/forged-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/forged-03.png -------------------------------------------------------------------------------- /data/training/024/forged-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/forged-04.png -------------------------------------------------------------------------------- /data/training/024/forged-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/forged-05.png -------------------------------------------------------------------------------- /data/training/024/forged-06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/forged-06.png -------------------------------------------------------------------------------- /data/training/024/forged-07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/forged-07.png -------------------------------------------------------------------------------- /data/training/024/forged-08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/forged-08.png -------------------------------------------------------------------------------- /data/training/024/forged-09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/forged-09.png -------------------------------------------------------------------------------- /data/training/024/forged-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/forged-10.png -------------------------------------------------------------------------------- /data/training/024/forged-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/forged-11.png -------------------------------------------------------------------------------- /data/training/024/forged-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/forged-12.png -------------------------------------------------------------------------------- /data/training/024/genuine-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/genuine-01.png -------------------------------------------------------------------------------- /data/training/024/genuine-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/genuine-02.png -------------------------------------------------------------------------------- /data/training/024/genuine-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/genuine-03.png -------------------------------------------------------------------------------- /data/training/024/genuine-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/genuine-04.png -------------------------------------------------------------------------------- /data/training/024/genuine-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/genuine-05.png -------------------------------------------------------------------------------- /data/training/024/genuine-06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/genuine-06.png -------------------------------------------------------------------------------- /data/training/024/genuine-07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/genuine-07.png -------------------------------------------------------------------------------- /data/training/024/genuine-08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/genuine-08.png -------------------------------------------------------------------------------- /data/training/024/genuine-09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/genuine-09.png -------------------------------------------------------------------------------- /data/training/024/genuine-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/genuine-10.png -------------------------------------------------------------------------------- /data/training/024/genuine-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/genuine-11.png -------------------------------------------------------------------------------- /data/training/024/genuine-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/024/genuine-12.png -------------------------------------------------------------------------------- /data/training/029/forged-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/forged-01.png -------------------------------------------------------------------------------- /data/training/029/forged-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/forged-02.png -------------------------------------------------------------------------------- /data/training/029/forged-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/forged-03.png -------------------------------------------------------------------------------- /data/training/029/forged-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/forged-04.png -------------------------------------------------------------------------------- /data/training/029/forged-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/forged-05.png -------------------------------------------------------------------------------- /data/training/029/forged-06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/forged-06.png -------------------------------------------------------------------------------- /data/training/029/forged-07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/forged-07.png -------------------------------------------------------------------------------- /data/training/029/forged-08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/forged-08.png -------------------------------------------------------------------------------- /data/training/029/forged-09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/forged-09.png -------------------------------------------------------------------------------- /data/training/029/forged-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/forged-10.png -------------------------------------------------------------------------------- /data/training/029/forged-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/forged-11.png -------------------------------------------------------------------------------- /data/training/029/forged-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/forged-12.png -------------------------------------------------------------------------------- /data/training/029/genuine-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/genuine-01.png -------------------------------------------------------------------------------- /data/training/029/genuine-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/genuine-02.png -------------------------------------------------------------------------------- /data/training/029/genuine-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/genuine-03.png -------------------------------------------------------------------------------- /data/training/029/genuine-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/genuine-04.png -------------------------------------------------------------------------------- /data/training/029/genuine-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/genuine-05.png -------------------------------------------------------------------------------- /data/training/029/genuine-06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/genuine-06.png -------------------------------------------------------------------------------- /data/training/029/genuine-07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/genuine-07.png -------------------------------------------------------------------------------- /data/training/029/genuine-08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/genuine-08.png -------------------------------------------------------------------------------- /data/training/029/genuine-09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/genuine-09.png -------------------------------------------------------------------------------- /data/training/029/genuine-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/genuine-10.png -------------------------------------------------------------------------------- /data/training/029/genuine-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnbaron/signature-recognition/35d68f81c091e1f86c82657806208e81846c0f67/data/training/029/genuine-11.png -------------------------------------------------------------------------------- /network.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import random 3 | 4 | 5 | class NeuralNetwork(): 6 | 7 | def __init__(self, sizes): 8 | # sizes is an array with the number of units in each layer 9 | # [2,3,1] means w neurons of input, 3 in the hidden layer and 1 as output 10 | self.num_layers = len(sizes) 11 | self.sizes = sizes 12 | # the syntax [1:] gets all elements of sizes array beginning at index 1 (second position) 13 | # np,random.randn(rows, cols) retuns a matrix of random elements 14 | # np.random.randn(2,1) => 15 | # array([[ 0.68265325], 16 | # [-0.52939261]]) 17 | # biases will have one vector per layer 18 | self.biases = [np.random.randn(y,1) for y in sizes[1:]] 19 | #zip returns a tuple in which x is the element of the first array and y the element of the second 20 | #sizes[:-1] returns all the elements till the second to last 21 | #sizes[1:] returns all the elements from the second and on] 22 | # [2,3,1] means: 23 | # * matrix of 3 rows and 2 columns -- will be multiplied by the inputs 24 | # * matrix of 1 row and 3 columns -- will multiply the hidden layer and produce the output 25 | self.weights = [np.random.randn(y,x) for x,y in zip(sizes[:-1],sizes[1:])] 26 | 27 | def feedforward(self, a): 28 | for b,w in zip(self.biases, self.weights): 29 | a = sigmoid(np.dot(w, a) + b) 30 | return a 31 | 32 | def separate_batches(self, training_data, batch_size): 33 | random.shuffle(training_data) 34 | n = len(training_data) 35 | # extracts chunks of data from the training set 36 | # the xrange function will return indices starting with 0 untill n, with a step size o batch_size 37 | # batches, then, will have several chunks of the main set, each defined by the batch_size_variable 38 | return [training_data[i:i + batch_size] for i in range(0, n, batch_size)] 39 | 40 | def update_batches(self, batches, alpha): 41 | for batch in batches: 42 | nabla_b = [np.zeros(b.shape) for b in self.biases] 43 | nabla_w = [np.zeros(w.shape) for w in self.weights] 44 | 45 | m = len(batch) 46 | 47 | # x is a array of length 901 48 | # y is a single value indicating the digit represented by the 901 elements 49 | for x, y in batch: 50 | delta_b, delta_w = self.backpropagation(x, y) 51 | nabla_b = [nb + dnb for nb, dnb in zip(nabla_b, delta_b)] 52 | nabla_w = [nw + dnw for nw, dnw in zip(nabla_w, delta_w)] 53 | 54 | self.weights = [w - (alpha / m) * nw for w, nw in zip(self.weights, nabla_w)] 55 | self.biases = [b - (alpha / m) * nb for b, nb in zip(self.biases, nabla_b)] 56 | 57 | def backpropagation(self, x, y): 58 | nabla_b = [np.zeros(b.shape) for b in self.biases] 59 | nabla_w = [np.zeros(w.shape) for w in self.weights] 60 | 61 | activation = x 62 | activations = [x] 63 | zs = [] 64 | for b, w in zip(self.biases, self.weights): 65 | # layer-bound b and w 66 | z = np.dot(w, activation)+b 67 | zs.append(z) 68 | activation = sigmoid(z) 69 | activations.append(activation) 70 | # backward pass 71 | delta = self.cost_derivative(activations[-1], y) * \ 72 | sigmoid_prime(zs[-1]) 73 | nabla_b[-1] = delta 74 | nabla_w[-1] = np.dot(delta, activations[-2].transpose()) 75 | 76 | for l in range(2, self.num_layers): 77 | z = zs[-l] 78 | sp = sigmoid_prime(z) 79 | delta = np.dot(self.weights[-l+1].transpose(), delta) * sp 80 | nabla_b[-l] = delta 81 | nabla_w[-l] = np.dot(delta, activations[-l-1].transpose()) 82 | return (nabla_b, nabla_w) 83 | 84 | def sgd(self, training_data, epochs, batch_size, alpha, test_data): 85 | n_test = len(test_data) 86 | 87 | for epoch in range(epochs): 88 | batches = self.separate_batches(training_data, batch_size) 89 | self.update_batches(batches, alpha) 90 | 91 | print("Epoch {0}: {1} / {2}".format(epoch, self.evaluate(test_data), n_test)) 92 | 93 | def evaluate(self, test_data): 94 | #r = [self.feedforward(x) for (x, y) in test_data] 95 | #for a in r: 96 | # print("{0}, {1}".format(format(a[0][0], 'f'), format(a[1][0], 'f'))) 97 | test_results = [(np.argmax(self.feedforward(x)), y) 98 | for (x, y) in test_data] 99 | return sum(int(x == y) for (x, y) in test_results) 100 | 101 | def cost_derivative(self, output_activations, y): 102 | return output_activations - y 103 | 104 | 105 | def sigmoid(z): 106 | return 1.0 / (1.0 + np.exp(-z)) 107 | 108 | 109 | def sigmoid_prime(z): 110 | return sigmoid(z) * (1-sigmoid(z)) 111 | -------------------------------------------------------------------------------- /preprocessor.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | 5 | def prepare(input): 6 | # preprocessing the image input 7 | clean = cv2.fastNlMeansDenoising(input) 8 | ret, tresh = cv2.threshold(clean, 127, 1, cv2.THRESH_BINARY_INV) 9 | img = crop(tresh) 10 | 11 | # 40x10 image as a flatten array 12 | flatten_img = cv2.resize(img, (40, 10), interpolation=cv2.INTER_AREA).flatten() 13 | 14 | # resize to 400x100 15 | resized = cv2.resize(img, (400, 100), interpolation=cv2.INTER_AREA) 16 | columns = np.sum(resized, axis=0) # sum of all columns 17 | lines = np.sum(resized, axis=1) # sum of all lines 18 | 19 | h, w = img.shape 20 | aspect = w / h 21 | 22 | return [*flatten_img, *columns, *lines, aspect] 23 | 24 | 25 | def crop(img): 26 | points = cv2.findNonZero(img) 27 | x, y, w, h = cv2.boundingRect(points) 28 | return img[y: y+h, x: x+w] -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | setup( 4 | name='sigrecog', 5 | version='1.0', 6 | entry_points={ 7 | 'console_scripts': [ 8 | 'sigrecog = __main__:main' 9 | ] 10 | }, 11 | packages=['sigrecog'], 12 | license=open('LICENSE').read(), 13 | long_description=open('README.md').read(), 14 | ) 15 | -------------------------------------------------------------------------------- /sigrecog.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import os 3 | import numpy as np 4 | import network 5 | import preprocessor 6 | 7 | 8 | def main(): 9 | print('OpenCV version {} '.format(cv2.__version__)) 10 | 11 | current_dir = os.path.dirname(__file__) 12 | 13 | author = '021' 14 | training_folder = os.path.join(current_dir, 'data/training/', author) 15 | test_folder = os.path.join(current_dir, 'data/test/', author) 16 | 17 | training_data = [] 18 | for filename in os.listdir(training_folder): 19 | img = cv2.imread(os.path.join(training_folder, filename), 0) 20 | if img is not None: 21 | data = np.array(preprocessor.prepare(img)) 22 | data = np.reshape(data, (901, 1)) 23 | result = [[0], [1]] if "genuine" in filename else [[1], [0]] 24 | result = np.array(result) 25 | result = np.reshape(result, (2, 1)) 26 | training_data.append((data, result)) 27 | 28 | test_data = [] 29 | for filename in os.listdir(test_folder): 30 | img = cv2.imread(os.path.join(test_folder, filename), 0) 31 | if img is not None: 32 | data = np.array(preprocessor.prepare(img)) 33 | data = np.reshape(data, (901, 1)) 34 | result = 1 if "genuine" in filename else 0 35 | test_data.append((data, result)) 36 | 37 | net = network.NeuralNetwork([901, 500, 500, 2]) 38 | net.sgd(training_data, 10, 50, 0.01, test_data) 39 | 40 | 41 | if __name__ == '__main__': 42 | main() -------------------------------------------------------------------------------- /sigrecogtf.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import os 3 | import tensorflow as tf 4 | import preprocessor 5 | 6 | 7 | def main(): 8 | print('OpenCV version {} '.format(cv2.__version__)) 9 | 10 | current_dir = os.path.dirname(__file__) 11 | 12 | author = '021' 13 | training_folder = os.path.join(current_dir, 'data/training/', author) 14 | test_folder = os.path.join(current_dir, 'data/test/', author) 15 | 16 | training_data = [] 17 | training_labels = [] 18 | for filename in os.listdir(training_folder): 19 | img = cv2.imread(os.path.join(training_folder, filename), 0) 20 | if img is not None: 21 | data = preprocessor.prepare(img) 22 | training_data.append(data) 23 | training_labels.append([0, 1] if "genuine" in filename else [1, 0]) 24 | 25 | test_data = [] 26 | test_labels = [] 27 | for filename in os.listdir(test_folder): 28 | img = cv2.imread(os.path.join(test_folder, filename), 0) 29 | if img is not None: 30 | data = preprocessor.prepare(img) 31 | test_data.append(data) 32 | test_labels.append([0, 1] if "genuine" in filename else [1, 0]) 33 | 34 | sgd(training_data, training_labels, test_data, test_labels) 35 | 36 | 37 | # Softmax Regression Model 38 | def regression(x): 39 | W = tf.Variable(tf.zeros([901, 2]), name="W") 40 | b = tf.Variable(tf.zeros([2]), name="b") 41 | y = tf.nn.softmax(tf.matmul(x, W) + b) 42 | return y, [W, b] 43 | 44 | 45 | def sgd(training_data, training_labels, test_data, test_labels): 46 | # model 47 | with tf.variable_scope("regression"): 48 | x = tf.placeholder(tf.float32, [None, 901]) 49 | y, variables = regression(x) 50 | 51 | # train 52 | y_ = tf.placeholder("float", [None, 2]) 53 | cross_entropy = -tf.reduce_sum(y_ * tf.log(y)) 54 | train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy) 55 | correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1)) 56 | accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) 57 | 58 | with tf.Session() as sess: 59 | sess.run(tf.global_variables_initializer()) 60 | sess.run(train_step, feed_dict={x: training_data, y_: training_labels}) 61 | print(sess.run(accuracy, feed_dict={x: test_data, y_: test_labels})) 62 | 63 | if __name__ == '__main__': 64 | main() --------------------------------------------------------------------------------