Skip to content

Commit

Permalink
chore: Added CI jobs to check evaluate, collect_env & demo (mindee#456)
Browse files Browse the repository at this point in the history
* chore: Added CI job to check whether the demo runs

* chore: Added CI jobs to check remaining scripts

* feat: Added options to run evaluation on limited samples

* test: Speeded up evaluation script testing
  • Loading branch information
fg-mindee authored Sep 3, 2021
1 parent b0d554f commit 64c7864
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: demo

on:
push:
branches: main
pull_request:
branches: main

jobs:
test-demo:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python: [3.7, 3.8]
steps:
- if: matrix.os == 'macos-latest'
name: Install MacOS prerequisites
run: brew install cairo pango gdk-pixbuf libffi
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python }}
architecture: x64
- name: Cache python modules
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pkg-deps-${{ matrix.python }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('demo/requirements.txt') }}-${{ hashFiles('**/*.py') }}
restore-keys: |
${{ runner.os }}-pkg-deps-${{ matrix.python }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('demo/requirements.txt') }}-
${{ runner.os }}-pkg-deps-${{ matrix.python }}-${{ hashFiles('requirements.txt') }}-
${{ runner.os }}-pkg-deps-${{ matrix.python }}-
${{ runner.os }}-pkg-deps-
${{ runner.os }}-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[tf] --upgrade
pip install -r demo/requirements.txt
- name: Run demo
run: |
streamlit --version
screen -dm streamlit run demo/app.py
sleep 5
curl http://localhost:8501
52 changes: 52 additions & 0 deletions .github/workflows/scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,55 @@ jobs:
run: |
wget https://github.com/mindee/doctr/releases/download/v0.1.0/sample.pdf
python scripts/analyze.py sample.pdf --noblock
test-evaluate:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python: [3.7, 3.8]
steps:
- if: matrix.os == 'macos-latest'
name: Install MacOS prerequisites
run: brew install cairo pango gdk-pixbuf libffi
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python }}
architecture: x64
- name: Cache python modules
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pkg-deps-${{ matrix.python }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('**/*.py') }}
restore-keys: |
${{ runner.os }}-pkg-deps-${{ matrix.python }}-${{ hashFiles('requirements.txt') }}-
${{ runner.os }}-pkg-deps-${{ matrix.python }}-
${{ runner.os }}-pkg-deps-
${{ runner.os }}-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[tf] --upgrade
- name: Run evaluation script
run: |
python scripts/evaluate.py db_resnet50 crnn_vgg16_bn --samples 10
test-collectenv:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: [3.7, 3.8]
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python }}
architecture: x64
- name: Run environment collection script
run: python scripts/collect_env.py
9 changes: 9 additions & 0 deletions scripts/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def main(args):
det_metric = LocalizationConfusion(iou_thresh=args.iou, rotated_bbox=args.rotation)
e2e_metric = OCRMetric(iou_thresh=args.iou, rotated_bbox=args.rotation)

sample_idx = 0
for dataset in sets:
for page, target in tqdm(dataset):
# GT
Expand Down Expand Up @@ -99,6 +100,13 @@ def main(args):
reco_metric.update(gt_labels, reco_words)
e2e_metric.update(gt_boxes, np.asarray(pred_boxes), gt_labels, pred_labels)

# Loop break
sample_idx += 1
if isinstance(args.samples, int) and args.samples == sample_idx:
break
if isinstance(args.samples, int) and args.samples == sample_idx:
break

# Unpack aggregated metrics
print(f"Model Evaluation (model= {args.detection} + {args.recognition}, "
f"dataset={'OCRDataset' if args.img_folder else args.dataset})")
Expand All @@ -125,6 +133,7 @@ def parse_args():
parser.add_argument('--rotation', dest='rotation', action='store_true', help='evaluate with rotated bbox')
parser.add_argument('-b', '--batch_size', type=int, default=32, help='batch size for recognition')
parser.add_argument('--mask_shape', type=int, default=None, help='mask shape for mask iou (only for rotation)')
parser.add_argument('--samples', type=int, default=None, help='evaluate only on the N first samples')
args = parser.parse_args()

return args
Expand Down

0 comments on commit 64c7864

Please sign in to comment.