-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
executable file
·147 lines (119 loc) · 4.07 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
testdir = tests
export
CUDA_VISIBLE_DEVICES=0
SHELL = /bin/bash
PYTHON ?= python
PIP ?= pip
PIP_INSTALL = $(PIP) install
LOG_LEVEL = INFO
PYTHONIOENCODING=utf8
TESTDATA = $(testdir)/assets/dfki-testdata/data
TESTS=tests
# Tag to publish docker image to
DOCKER_TAG = ocrd/anybaseocr
# BEGIN-EVAL makefile-parser --make-help Makefile
.PHONY: help
help:
@echo ""
@echo " Targets"
@echo ""
@echo " deps Install python deps via pip"
@echo " install Install"
@echo " ocrd_anybaseocr/pix2pixhd Checkout pix2pixhd submodule"
@echo " repo/assets Clone OCR-D/assets to ./repo/assets"
@echo " assets-clean Remove assets"
@echo " assets Setup test assets"
@echo " test Run unit tests"
@echo " cli-test Run CLI tests"
@echo " test-binarize Test binarization CLI"
@echo " test-deskew Test deskewing CLI"
@echo " test-crop Test cropping CLI"
@echo " test-tiseg Test text/non-text segmentation CLI"
@echo " test-block-segmentation Test block segmentation CLI"
@echo " test-textline Test textline segmentation CLI"
@echo " test-layout-analysis Test document structure analysis CLI"
@echo " test-dewarp Test page dewarping CLI"
@echo ""
@echo " Variables"
@echo ""
@echo " DOCKER_TAG Tag to publish docker image to"
# END-EVAL
# Install python deps via pip
.PHONY: deps
deps:
$(PIP_INSTALL) -r requirements.txt
# Install
install: ocrd_anybaseocr/pix2pixhd
$(PIP_INSTALL) .
ocrd_anybaseocr/pix2pixhd:
git submodule update --init $@
#
# Assets
#
# Download sample model TODO Add other models here
.PHONY: models
models:
ocrd resmgr download ocrd-anybaseocr-dewarp '*'
ocrd resmgr download ocrd-anybaseocr-layout-analysis '*'
.PHONY: docker
docker:
docker build \
--build-arg VCS_REF=$$(git rev-parse --short HEAD) \
--build-arg BUILD_DATE=$$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
-t '$(DOCKER_TAG)' .
# Clone OCR-D/assets to ./repo/assets
repo/assets:
mkdir -p $(dir $@)
git clone https://github.com/OCR-D/assets "$@"
# Remove assets
.PHONY: assets-clean
assets-clean:
rm -rf $(testdir)/assets
# Setup test assets
.PHONY: assets
assets: repo/assets models
mkdir -p $(testdir)/assets
cp -r -t $(testdir)/assets repo/assets/data/*
#
# Tests
#
# Run unit tests
.PHONY: test
test: assets-clean assets
$(PYTHON) -m pytest --continue-on-collection-errors $(TESTS)
# Run CLI tests
.PHONY: cli-test
cli-test: assets-clean assets
cli-test: test-binarize test-deskew test-crop test-textline test-layout-analysis test-dewarp
# Test binarization CLI
.PHONY: test-binarize
test-binarize: assets
ocrd-anybaseocr-binarize -m $(TESTDATA)/mets.xml -I MAX -O BIN-TEST
# Test deskewing CLI
.PHONY: test-deskew
test-deskew: test-binarize
ocrd-anybaseocr-deskew -m $(TESTDATA)/mets.xml -I BIN-TEST -O DESKEW-TEST
# Test cropping CLI
.PHONY: test-crop
test-crop: test-deskew
ocrd-anybaseocr-crop -m $(TESTDATA)/mets.xml -I DESKEW-TEST -O CROP-TEST
# Test text/non-text segmentation CLI
.PHONY: test-tiseg
test-tiseg: test-crop
ocrd-anybaseocr-tiseg -m $(TESTDATA)/mets.xml --overwrite -I CROP-TEST -O TISEG-TEST
# Test block segmentation CLI
.PHONY: test-block-segmentation
test-block-segmentation: test-tiseg
ocrd-anybaseocr-block-segmentation -m $(TESTDATA)/mets.xml -I TISEG-TEST -O OCR-D-BLOCK-SEGMENT
# Test textline segmentation CLI
.PHONY: test-textline
test-textline: test-crop
ocrd-anybaseocr-textline -m $(TESTDATA)/mets.xml -I CROP-TEST -O TL-TEST
# Test page dewarping CLI
.PHONY: test-dewarp
test-dewarp: test-crop
ocrd-anybaseocr-dewarp -m $(TESTDATA)/mets.xml -I CROP-TEST -O DEWARP-TEST
# Test document structure analysis CLI
.PHONY: test-layout-analysis
test-layout-analysis: test-binarize
ocrd-anybaseocr-layout-analysis -m $(TESTDATA)/mets.xml -I BIN-TEST -O LAYOUT