@@ -53,6 +53,8 @@ PKG_CONFIG_PATH := $(VIRTUAL_ENV)/lib/pkgconfig:$(PKG_CONFIG_PATH)
5353endif
5454export PKG_CONFIG_PATH
5555
56+ SHELL = /bin/bash
57+
5658OCRD_EXECUTABLES = $(BIN ) /ocrd # add more CLIs below
5759CUSTOM_DEPS = unzip wget python3-venv parallel git less # add more packages for deps-ubuntu below (or modules as preqrequisites)
5860
@@ -245,6 +247,7 @@ ifeq (0,$(MAKELEVEL))
245247cor-asv-ann-check :
246248 $(MAKE ) check OCRD_MODULES=cor-asv-ann VIRTUAL_ENV=$(SUB_VENV ) /headless-tf1
247249else
250+ $(pip_install_tf1nvidia)
248251 $(pip_install)
249252endif
250253endif
@@ -276,6 +279,7 @@ ifeq (0,$(MAKELEVEL))
276279cor-asv-fst-check :
277280 $(MAKE ) check OCRD_MODULES=cor-asv-fst VIRTUAL_ENV=$(SUB_VENV ) /headless-tf1
278281else
282+ $(pip_install_tf1nvidia)
279283 . $(ACTIVATE_VENV) && $(MAKE) -C $< deps
280284 $(pip_install)
281285endif
@@ -292,6 +296,7 @@ ifeq (0,$(MAKELEVEL))
292296ocrd_keraslm-check :
293297 $(MAKE ) check OCRD_MODULES=ocrd_keraslm VIRTUAL_ENV=$(SUB_VENV ) /headless-tf1
294298else
299+ $(pip_install_tf1nvidia)
295300 $(pip_install)
296301endif
297302endif
@@ -362,6 +367,7 @@ ifeq (0,$(MAKELEVEL))
362367ocrd_segment-check :
363368 $(MAKE ) check OCRD_MODULES=ocrd_segment VIRTUAL_ENV=$(SUB_VENV ) /headless-tf1
364369else
370+ $(pip_install_tf1nvidia)
365371 $(pip_install)
366372endif
367373endif
@@ -481,10 +487,10 @@ OCRD_ANYBASEOCR += $(BIN)/ocrd-anybaseocr-textline
481487OCRD_ANYBASEOCR += $(BIN ) /ocrd-anybaseocr-layout-analysis
482488$(call multirule,$(OCRD_ANYBASEOCR ) ) : ocrd_anybaseocr
483489ifeq (0,$(MAKELEVEL ) )
484- $(MAKE) -B -o $< $(notdir $(OCRD_ANYBASEOCR)) VIRTUAL_ENV=$(SUB_VENV)/headless-tf21
485- $(call delegate_venv,$(OCRD_ANYBASEOCR),$(SUB_VENV)/headless-tf21 )
490+ $(MAKE) -B -o $< $(notdir $(OCRD_ANYBASEOCR)) VIRTUAL_ENV=$(SUB_VENV)/headless-tf2
491+ $(call delegate_venv,$(OCRD_ANYBASEOCR),$(SUB_VENV)/headless-tf2 )
486492ocrd_anybaseocr-check :
487- $(MAKE ) check OCRD_MODULES=ocrd_anybaseocr VIRTUAL_ENV=$(SUB_VENV ) /headless-tf21
493+ $(MAKE ) check OCRD_MODULES=ocrd_anybaseocr VIRTUAL_ENV=$(SUB_VENV ) /headless-tf2
488494else
489495 cd $< ; $(MAKE) patch-pix2pixhd
490496 $(pip_install)
@@ -528,6 +534,7 @@ ifeq (0,$(MAKELEVEL))
528534sbb_binarization-check :
529535 $(MAKE ) check OCRD_MODULES=sbb_binarization VIRTUAL_ENV=$(SUB_VENV ) /headless-tf1
530536else
537+ $(pip_install_tf1nvidia)
531538 $(pip_install)
532539endif
533540endif
@@ -546,6 +553,7 @@ ifeq (0,$(MAKELEVEL))
546553sbb_textline_detector-check :
547554 $(MAKE ) check OCRD_MODULES=sbb_textline_detector VIRTUAL_ENV=$(SUB_VENV ) /headless-tf1
548555else
556+ $(pip_install_tf1nvidia)
549557 $(pip_install)
550558endif
551559endif
@@ -564,6 +572,7 @@ ifeq (0,$(MAKELEVEL))
564572eynollah-check :
565573 $(MAKE ) check OCRD_MODULES=eynollah VIRTUAL_ENV=$(SUB_VENV ) /headless-tf1
566574else
575+ $(pip_install_tf1nvidia)
567576 $(pip_install)
568577endif
569578endif
@@ -601,6 +610,31 @@ define pip_install
601610. $(ACTIVATE_VENV ) && cd $< && $(SEMPIP ) $(PIP ) install $(PIP_OPTIONS_E ) . && touch -c $@
602611endef
603612
613+ # Workaround for missing prebuilt versions of TF<2 for Python==3.8
614+ # todo: find another solution for 3.9, 3.10 etc
615+ # Nvidia has them, but under a different name, so let's rewrite that:
616+ define pip_install_tf1nvidia =
617+ . $(ACTIVATE_VENV ) && if ! $(PYTHON ) -c "import sys; sys.exit(sys.version_info.major==3 and sys.version_info.minor==8)" && ! $(PIP ) show -q tensorflow-gpu; then \
618+ $(PIP ) install nvidia-pyindex && \
619+ pushd $$(mktemp -d ) && \
620+ $(PIP ) download --no-deps nvidia-tensorflow && \
621+ for name in nvidia_tensorflow-*.whl; do name=$${name%.whl}; done && \
622+ $(PYTHON ) -m wheel unpack $$name.whl && \
623+ for name in nvidia_tensorflow-*/; do name=$${name%/}; done && \
624+ newname=$${name/nvidia_tensorflow/tensorflow_gpu} &&\
625+ sed -i s/nvidia_tensorflow/tensorflow_gpu/g $$name/$$name.dist-info/METADATA && \
626+ sed -i s/nvidia_tensorflow/tensorflow_gpu/g $$name/$$name.dist-info/RECORD && \
627+ sed -i s/nvidia_tensorflow/tensorflow_gpu/g $$name/tensorflow_core/tools/pip_package/setup.py && \
628+ pushd $$name && for path in $$name*; do mv $$path $${path/$$name/$$newname}; done && popd && \
629+ $(PYTHON ) -m wheel pack $$name && \
630+ $(PIP ) install $$newname*.whl && popd && rm -fr $$OLDPWD; fi && \
631+ $(PIP ) install imageio==2.4.1 && \
632+ $(PIP ) install "tifffile<2022"
633+ endef
634+ # last recipe 2 lines:
635+ # - preempt conflict over numpy between scikit-image and tensorflow
636+ # - preempt conflict over numpy between tifffile and tensorflow
637+
604638# pattern for recursive make:
605639# $(executables...): module...
606640# ifeq (0,$(MAKELEVEL))
@@ -794,13 +828,20 @@ clean-tesseract:
794828deps-ubuntu :
795829 apt-get update
796830 apt-get -y install git parallel
831+ ifneq ($(suffix $(PYTHON ) ) ,)
832+ # install specific Python version in system via PPA
833+ apt-get install -y software-properties-common
834+ add-apt-repository -y ppa:deadsnakes/ppa
835+ apt-get update
836+ apt-get install -y --no-install-recommends $(notdir $(PYTHON))-dev $(notdir $(PYTHON))-venv
837+ endif
797838 $(MAKE) deps-ubuntu-modules
798839 chown -R --reference=$(CURDIR) .git $(OCRD_MODULES)
799840# prevent the sem commands during above module updates from imposing sudo perms on HOME:
800841 chown -R --reference=$(HOME) $(HOME)/.parallel
801842
802843deps-ubuntu-modules :
803- set -e; for dir in $^; do $( MAKE) -C $$ dir deps-ubuntu; done
844+ set -e; for dir in $^; do $( MAKE) -C $$ dir deps-ubuntu PYTHON= $( PYTHON ) PIP= $( PIP ) ; done
804845 apt-get -y install $(CUSTOM_DEPS )
805846
806847.PHONY : deps-ubuntu deps-ubuntu-modules
@@ -845,6 +886,7 @@ docker%: Dockerfile $(DOCKER_MODULES)
845886 --build-arg OCRD_MODULES=" $( DOCKER_MODULES) " \
846887 --build-arg PIP_OPTIONS=" $( PIP_OPTIONS) " \
847888 --build-arg PARALLEL=" $( DOCKER_PARALLEL) " \
889+ --build-arg PYTHON=" $( PYTHON) " \
848890 -t $(DOCKER_TAG ) :$(or $(*:-%=% ) ,latest) .
849891
850892
0 commit comments