ValueError in block-segmentation
Opened this issue · 4 comments
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.
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
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.
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
.