DDMAL / Rodan

:dragon_face: A web-based workflow engine.
https://rodan2.simssa.ca/
47 stars 13 forks source link

[Interactive Classifier] Interactive Classifier fails when pressing "Regroup and Reclassify" #860

Closed timothydereuse closed 1 year ago

timothydereuse commented 1 year ago

From Gen:

When running from scratch, without any training data:

File "/usr/local/lib/python3.7/site-packages/celery/app/trace.py", line 412, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/celery/app/trace.py", line 704, in __protected_call__
    return self.run(*args, **kwargs)
  File "/code/Rodan/rodan/jobs/base.py", line 773, in run
    retval = self.run_my_task(inputs, settings, arg_outputs)
  File "/code/Rodan/rodan/jobs/interactive_classifier/wrapper.py", line 182, in run_my_task
    features)
  File "/code/Rodan/rodan/jobs/interactive_classifier/interactive_classifier.py", line 246, in run_correction_stage
    cknn.classify_glyph_automatic(gamera_glyph)
  File "/usr/local/lib/python3.7/site-packages/gamera/classify.py", line 259, in classify_glyph_automatic
    (id, conf) = self._classify_automatic_impl(glyph)
  File "/usr/local/lib/python3.7/site-packages/gamera/classify.py", line 693, in _classify_automatic_impl
    return self.classify_with_images(self.database, glyph)
TypeError: knn: could not get string from id_name tuple.

The job also fails if I ask IC to "Finalize". This is the traceback for that:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/celery/app/trace.py", line 412, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/celery/app/trace.py", line 704, in __protected_call__
    return self.run(*args, **kwargs)
  File "/code/Rodan/rodan/jobs/base.py", line 773, in run
    retval = self.run_my_task(inputs, settings, arg_outputs)
  File "/code/Rodan/rodan/jobs/heuristic_pitch_finding/base.py", line 183, in run_my_task
    pitches = pf.get_pitches(glyphs, staves)
  File "/code/Rodan/rodan/jobs/heuristic_pitch_finding/PitchFinding.py", line 38, in get_pitches
    self._find_pitches(self.glyphs)
  File "/code/Rodan/rodan/jobs/heuristic_pitch_finding/PitchFinding.py", line 88, in _find_pitches
    glyph_var = g.get_main_id().decode().split('.')
AttributeError: 'str' object has no attribute 'decode'

Also fails when given training data:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/celery/app/trace.py", line 412, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/celery/app/trace.py", line 704, in __protected_call__
    return self.run(*args, **kwargs)
  File "/code/Rodan/rodan/jobs/base.py", line 773, in run
    retval = self.run_my_task(inputs, settings, arg_outputs)
  File "/code/Rodan/rodan/jobs/interactive_classifier/wrapper.py", line 158, in run_my_task
    features)
  File "/code/Rodan/rodan/jobs/interactive_classifier/interactive_classifier.py", line 232, in run_correction_stage
    features_file_path)
  File "/code/Rodan/rodan/jobs/interactive_classifier/interactive_classifier.py", line 133, in prepare_classifier
    glyph.classify_manual(g['class_name'])
  File "/usr/local/lib/python3.7/site-packages/gamera/core.py", line 362, in classify_manual
    raise TypeError("id_name must be a string or a list")
TypeError: id_name must be a string or a list

As far as we know, the last time it worked was last summer, possibly before the migration to Python 3.

timothydereuse commented 1 year ago

Looking at the code I'm almost positive this is one of those python2 -> python3 issues that stems from differences in how it handles strings.

malajvan commented 1 year ago
sabrina0822 commented 1 year ago

We found another error traceback. Seems like this error is going through the group_and_correct function as opposed to the run_correction_stage. This happens when we press group and reclassify.

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/celery/app/trace.py", line 412, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/celery/app/trace.py", line 704, in __protected_call__
    return self.run(*args, **kwargs)
  File "/code/Rodan/rodan/jobs/base.py", line 773, in run
    retval = self.run_my_task(inputs, settings, arg_outputs)
  File "/code/Rodan/rodan/jobs/interactive_classifier/wrapper.py", line 209, in run_my_task
    features)
  File "/code/Rodan/rodan/jobs/interactive_classifier/interactive_classifier.py", line 193, in group_and_correct
    criterion = criterion)
  File "/usr/local/lib/python3.7/site-packages/gamera/classify.py", line 141, in group_list_automatic
    splits, removed = self.classify_list_automatic(glyphs)
  File "/usr/local/lib/python3.7/site-packages/gamera/classify.py", line 338, in classify_list_automatic
    return self._classify_list_automatic(glyphs, max_recursion, 0, progress)
  File "/usr/local/lib/python3.7/site-packages/gamera/classify.py", line 292, in _classify_list_automatic
    (id, conf) = self._classify_automatic_impl(glyph)
  File "/usr/local/lib/python3.7/site-packages/gamera/classify.py", line 693, in _classify_automatic_impl
    return self.classify_with_images(self.database, glyph)
TypeError: knn: could not get string from id_name tuple.

The first error that Gen sent happens whenever we press Reclassify.

sabrina0822 commented 1 year ago

@malajvan was able to modify the error message (finally). Here are steps:

  1. Go inside the py3-celery container.
  2. Go into the /gamera4-rodan directory and change the knnmodule.hpp in gamera-4/include
  3. Since header files don't recompile if the cpp doesn't change, you have to change the cpp file that includes it (knncoremodule.cpp)
  4. Recompile with INSTALLL.sh (still inside py3-celery)
  5. Restart the containers and run everything again.

Turns out it was the second version of this error that was causing things to break. Screenshot 2023-05-10 at 2 55 16 PM We are going to investigate more now.

malajvan commented 1 year ago

We managed to pass the error by converting the id PyObject in knnmodule.hpp (above screenshots) to PyBytes instead of strings. We are currently seeing if we can fix this from outside of the hpp and preferably outside of gamera, while also testing if that fix works. Worst case we will fix inside our gamera src code and test to make it a quick fix and see where the root of the problem is later.

fujinaga commented 1 year ago

Glad to see that you're making progress!

malajvan commented 1 year ago

Turns out the error was from the class_name of the glyphs (i.e 'UNCLASSIFIED' etc). Gamera itself agrees with class_names being strings (as commented and implemented in the gamera python files) , but for some reason check if it's bytes in knnmodule.hpp. I'll implement a quick fix and ask the gamera people

malajvan commented 1 year ago

The fix for Interactive Classifier can be found on branch IC_fix. We are attempting another fix that doesn't touch the gamera source code. If you want to run Interactive Classifier before we merge into develop, you can run rodan locally and pull the Docker images as specified in the IC_fix branch.

malajvan commented 1 year ago

posted an issue to the official gamera-4 repo (#69)

sabrina0822 commented 1 year ago

Just added our fix onto staging. Still waiting to hear back from the official repo but things seem to be working for now so I will close this issue.