Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError in block-segmentation #99

Open
Schneipi opened this issue Feb 28, 2023 · 4 comments
Open

ValueError in block-segmentation #99

Schneipi opened this issue Feb 28, 2023 · 4 comments

Comments

@Schneipi
Copy link

I receive a ValueError when running ocrd-anybaseocr-block-segmentation on a single test image. I have tried different input groups (i.e. binarized/unbinarized) without success. The related block_segmentation_weights.h5 model has been correctly downloaded. Is there a way to avoid this error? Thanks for the help!

Traceback (most recent call last):
  File ".../venv/bin/ocrd-anybaseocr-block-segmentation", line 8, in <module>
    sys.exit(cli())
  File ".../venv/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File ".../venv/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File ".../venv/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File ".../venv/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File ".../venv/lib/python3.8/site-packages/ocrd_anybaseocr/cli/ocrd_anybaseocr_block_segmentation.py", line 450, in cli
    return ocrd_cli_wrap_processor(OcrdAnybaseocrBlockSegmenter, *args, **kwargs)
  File ".../venv/lib/python3.8/site-packages/ocrd/decorators/__init__.py", line 117, in ocrd_cli_wrap_processor
    run_processor(processorClass, ocrd_tool, mets, workspace=workspace, **kwargs)
  File ".../venv/lib/python3.8/site-packages/ocrd/processor/helpers.py", line 76, in run_processor
    processor = processorClass(
  File ".../venv/lib/python3.8/site-packages/ocrd_anybaseocr/cli/ocrd_anybaseocr_block_segmentation.py", line 84, in __init__
    self.setup()
  File ".../venv/lib/python3.8/site-packages/ocrd_anybaseocr/cli/ocrd_anybaseocr_block_segmentation.py", line 95, in setup
    self.mrcnn_model = model.MaskRCNN(mode="inference", model_dir=str(model_path), config=config)
  File ".../venv/lib/python3.8/site-packages/ocrd_anybaseocr/mrcnn/model.py", line 1850, in __init__
    self.keras_model = self.build(mode=mode, config=config)
  File ".../venv/lib/python3.8/site-packages/ocrd_anybaseocr/mrcnn/model.py", line 2048, in build
    fpn_classifier_graph(rpn_rois, mrcnn_feature_maps, input_image_meta,
  File ".../venv/lib/python3.8/site-packages/ocrd_anybaseocr/mrcnn/model.py", line 964, in fpn_classifier_graph
    mrcnn_bbox = KL.Reshape((s[1], num_classes, 4), name="mrcnn_bbox")(x)
  File ".../venv/lib/python3.8/site-packages/keras/engine/base_layer_v1.py", line 838, in __call__
    outputs = call_fn(cast_inputs, *args, **kwargs)
  File ".../venv/lib/python3.8/site-packages/keras/layers/reshaping/reshape.py", line 137, in call
    result = tf.reshape(inputs, (tf.shape(inputs)[0],) + self.target_shape)
  File ".../venv/lib/python3.8/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File ".../venv/lib/python3.8/site-packages/tensorflow/python/framework/op_def_library.py", line 571, in _ExtractInputsAndAttrs
    raise ValueError(
ValueError: Tried to convert 'shape' to a tensor and failed. Error: None values not supported.
@bertsky
Copy link
Contributor

bertsky commented Mar 1, 2023

Probably a problem with recent TensorFlow updates. We already migrated to 2.0, but not sure which was the last tested version.

Could you try replacing s[1] with s[1] or -1 on line

mrcnn_bbox = KL.Reshape((s[1], num_classes, 4), name="mrcnn_bbox")(x)
?

@Schneipi
Copy link
Author

Schneipi commented Mar 1, 2023

Thanks for the quick suggestion. Doesn't seem to do the trick unfortunately:

TypeError: in user code:

    File ".../venv/lib/python3.8/site-packages/ocrd_anybaseocr/mrcnn/model.py", line 823, in call  *
        detections_batch = utils.batch_slice(
    File ".../venv/lib/python3.8/site-packages/ocrd_anybaseocr/mrcnn/utils.py", line 795, in batch_slice  *
        output_slice = graph_fn(*inputs_slice)
    File ".../venv/lib/python3.8/site-packages/ocrd_anybaseocr/mrcnn/model.py", line 709, in refine_detections_graph  *
        probs = tf.where(tf.cast(K.tile(K.expand_dims(active_class_ids, 0), (probs.shape[0],1)), tf.bool),
    File ".../venv/lib/python3.8/site-packages/keras/backend.py", line 3893, in tile
        return tf.tile(x, n)

    TypeError: Failed to convert elements of (Dimension(None), 1) to Tensor. Consider casting elements to a supported type. See https://www.tensorflow.org/api_docs/python/tf/dtypes for supported TF dtypes.

@Schneipi
Copy link
Author

Schneipi commented Mar 1, 2023

I installed ocrd_anybaseocr according to the install instructions in https://github.com/OCR-D/ocrd_anybaseocr#installing.
The venv now contains Tensorflow 2.11.0.

@bertsky
Copy link
Contributor

bertsky commented Mar 4, 2023

Sorry, don't have time to repair this.

And as you can see here and imagine here, block segmentation is not worth investing IMO.

We have already been thinking of peeling off the cropper as an independent module (without the TF and Torch dependencies), and archive this one...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants