seuretm / ocrd_typegroups_classifier

Apache License 2.0
10 stars 1 forks source link

make test fails with torch >= 1.1.0 #6

Closed mikegerber closed 5 years ago

mikegerber commented 5 years ago

Current master's "make test" fails when torch 1.1.0 is installed:

% make test                                                                                           master 
mkdir -p repo
cd repo; git clone --depth 1 https://github.com/OCR-D/assets
Cloning into 'assets'...
remote: Enumerating objects: 1364, done.
remote: Counting objects: 100% (1364/1364), done.
remote: Compressing objects: 100% (1068/1068), done.
remote: Total 1364 (delta 132), reused 1299 (delta 107), pack-reused 0
Receiving objects: 100% (1364/1364), 114.13 MiB | 19.02 MiB/s, done.
Resolving deltas: 100% (132/132), done.
rm -rf tests/assets
cp -r repo/assets/data tests/assets
cd tests; bash test.sh
+++ dirname test.sh
++ cd .
++ pwd
+ SCRIPTDIR=/home/mike/devel/OCR-D/monorepo/ocrd_typegroups_classifier/tests
+ net=/home/mike/devel/OCR-D/monorepo/ocrd_typegroups_classifier/tests/../ocrd_typegroups_classifier/models/classifier.tgc
+ cd /home/mike/devel/OCR-D/monorepo/ocrd_typegroups_classifier/tests/assets/pembroke_werke_1766/data
+ ocrd-typegroups-classifier -l DEBUG -g PHYS_0011 -m mets.xml -I DEFAULT -O OCR-D-FONTIDENT -p /dev/fd/63
++ echo '{"network": "/home/mike/devel/OCR-D/monorepo/ocrd_typegroups_classifier/tests/../ocrd_typegroups_classifier/models/classifier.tgc", "stride":143}'
12:46:22.057 INFO root - Overriding log level globally to DEBUG
12:46:22.057 DEBUG ocrd.resolver - workspace_from_url
mets_url='file:///home/mike/devel/OCR-D/monorepo/ocrd_typegroups_classifier/tests/assets/pembroke_werke_1766/data/mets.xml'
baseurl='file:///home/mike/devel/OCR-D/monorepo/ocrd_typegroups_classifier/tests/assets/pembroke_werke_1766/data'
dst_dir='None'
12:46:22.057 DEBUG ocrd.resolver - Copying mets url 'file:///home/mike/devel/OCR-D/monorepo/ocrd_typegroups_classifier/tests/assets/pembroke_werke_1766/data/mets.xml' to '/home/mike/devel/OCR-D/monorepo/ocrd_typegroups_classifier/tests/assets/pembroke_werke_1766/data/mets.xml'
12:46:22.057 DEBUG ocrd.resolver - Target and source mets are identical
12:46:22.059 DEBUG ocrd.processor - Running processor <class 'ocrd_typegroups_classifier.processor.TypegroupsClassifierProcessor'>
12:46:22.059 DEBUG ocrd.processor - Processor instance <ocrd_typegroups_classifier.processor.TypegroupsClassifierProcessor object at 0x7fa4a781ca90> (ocrd-typegroups-classifier v0.0.1 doing recognition/font-identification)
12:46:27.073 DEBUG ocrd_typegroups_classifier - Processing: [<ocrd_models.ocrd_file.OcrdFile object at 0x7fa4a75ca198>]
Traceback (most recent call last):
  File "/home/mike/.virtualenvs/ocrd/bin/ocrd-typegroups-classifier", line 11, in <module>
    load_entry_point('ocrd-typegroups-classifier', 'console_scripts', 'ocrd-typegroups-classifier')()
  File "/home/mike/.virtualenvs/ocrd/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/mike/.virtualenvs/ocrd/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/mike/.virtualenvs/ocrd/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/mike/.virtualenvs/ocrd/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/mike/devel/OCR-D/monorepo/ocrd_typegroups_classifier/ocrd_typegroups_classifier/cli/ocrd_cli.py", line 15, in cli
    return ocrd_cli_wrap_processor(TypegroupsClassifierProcessor, *args, **kwargs)
  File "/home/mike/.virtualenvs/ocrd/lib/python3.7/site-packages/ocrd/decorators.py", line 38, in ocrd_cli_wrap_processor
    run_processor(processorClass, ocrd_tool, mets, workspace=workspace, **kwargs)
  File "/home/mike/.virtualenvs/ocrd/lib/python3.7/site-packages/ocrd/processor/base.py", line 65, in run_processor
    processor.process()
  File "/home/mike/devel/OCR-D/monorepo/ocrd_typegroups_classifier/ocrd_typegroups_classifier/processor.py", line 39, in process
    result = classifier.run(pil_image, stride)
  File "/home/mike/devel/OCR-D/monorepo/ocrd_typegroups_classifier/ocrd_typegroups_classifier/typegroups_classifier.py", line 125, in run
  File "/home/mike/devel/OCR-D/monorepo/ocrd_typegroups_classifier/ocrd_typegroups_classifier/typegroups_classifier.py", line 125, in run
    return self.classify(pil_image, stride, batch_size, score_as_key)
  File "/home/mike/devel/OCR-D/monorepo/ocrd_typegroups_classifier/ocrd_typegroups_classifier/typegroups_classifier.py", line 168, in classify
    out, _, _ = self.network(tensors)
  File "/home/mike/.virtualenvs/ocrd/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/mike/devel/OCR-D/monorepo/ocrd_typegroups_classifier/ocrd_typegroups_classifier/network/vraec.py", line 183, in forward
    x = self.conv1(x)
  File "/home/mike/.virtualenvs/ocrd/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/mike/.virtualenvs/ocrd/lib/python3.7/site-packages/torch/nn/modules/conv.py", line 331, in forward
    if self.padding_mode == 'circular':
  File "/home/mike/.virtualenvs/ocrd/lib/python3.7/site-packages/torch/nn/modules/module.py", line 539, in __getattr__
    type(self).__name__, name))
AttributeError: 'Conv2d' object has no attribute 'padding_mode'
make: *** [Makefile:45: test] Error 1

The workaround I'm using now is to install torch < 1.1.0:

diff --git a/setup.py b/setup.py
index ff7c645..a2cdc4c 100644
--- a/setup.py
+++ b/setup.py
@@ -24,8 +24,8 @@ setup(
         'pandas',
         'Pillow >= 5.3.0',
         'scikit-image',
-        'torch',
-        'torchvision',
+        'torch < 1.1.0',
+        'torchvision < 0.3.0',
     ],
     package_data={
         '': ['*.json', '*.tgc'],
seuretm commented 5 years ago

Thank you for letting me know. I'm getting some coffee and will look into this.

seuretm commented 5 years ago

I just pushed a correction. Note that the new sample CNN has been trained for only one epoch - I'll upload a better one (and English-speaking) later. Can you try to run the test again to see if it works on other machines than mine? It should output something like "DEBUG ocrd_typegroups_classifier - Detected fraktur:27, ..."

mikegerber commented 5 years ago

It works with torch 1.1.0 now, but needs an updated dependency in requirements.txt, I'll submit a PR in a second :)

mikegerber commented 5 years ago

My make test output with master:

16:16:48.454 DEBUG ocrd_typegroups_classifier - Detected fraktur:27, gotico_antiqua:21, rotunda:20, antiqua:18, hebrew:9, griechisch:4, nicht_schrift:0
seuretm commented 5 years ago

The text of pembroke_werke_1766 seems to be indeed written in Fraktur, as there are some kinds of "elephant trunks", so although it was trained for only one epoch, this network processed the page and gave a correct answer for the most probable font group. The issue is then solved, thank you again for letting me know about it :+1: