Compression defense against adversarial attacks in OCR systems
1.Install all dependencies for the research component using the following command
pip install -r requirements.txt
Required: Tensorflow:1.14.0, Python
2.Install the node modules for frontend using command
npm install
Required: Nodejs, Angularcli version: 9.0.3
3.Install flask
pip install flask flask-jsonpify flask-sqlalchemy flask-restful
pip install -U flask-cors
Required: Python
Synthetic data generator was used to generate dataset (TRDG) https://textrecognitiondatagenerator.readthedocs.io/en/latest/tutorial.html
Training data tested on: 72000 samples
Test data tested: 8000 images
Add data to data folder (both train/ test images)
Train model running the python file with following arguments
python run.py --train -ex ../data/train
NOTE: The model will be saved in the form of tensorflow checkpoints. The checkpoints are saved in the folder CRNN/CRNN/model
To test the model the saved trained model should be loaded using following
python run.py -ex ../data/test --test --restore
To take place attack for batches of images and obtain predictions for research purposes.
python run.py -ex ../data/test --attack --restore
In addition attack parameters should be passed
Attack name = fgsm, attack_parameters = {eps: 8}
To take place defense for batches of images and obtain predictions for research purposes.
python run.py -ex ../out/attacked/batch --defend --restore
In addition defense parameters should be passed
Defense name = compr, defense_parameters = {quality: 50}
Run ng serve -o
Navigate to http://localhost:4200/
Run app.py
NOTE: only a single image can be uploaded for experiments from the frontend. Here the parameters for the action (attack/defense/test) is passed from the frontend itself. Batches of image predictions can be tested by running the run.py file with the appropriate arguments