Skip to content

Triggered the assertion when the program try to execute vec2word #1

@Geographish

Description

@Geographish

Problem description:

Hello! I want to use mapKurator to analyze Chinese characters in map pictures, but I encountered an issue after replacing the config folder and Model weight of the Chinese + japanese Version.

Upon entering the command:

python tools/inference.py \
    --config-file ./configs/PALEJUN/config-ch/SynthMap-ch/SynthMap_Polygon.yaml \
    --output_json --input /linkfrom/A01.jpg \
    --output ./output 

I expect it execute successfully, but I receive an assertion error:

[01/21 04:18:12 detectron2]: Arguments: Namespace(confidence_threshold=0.3, config_file='./configs/PALEJUN/config-ch/SynthMap-ch/SynthMap_Polygon.yaml', input=['/linkfrom/A01.jpg'], opts=[], output='./output', output_json=True, video_input=None, webcam=False)
WARNING [01/21 04:18:12 d2.config.compat]: Config './configs/PALEJUN/config-ch/SynthMap-ch/SynthMap_Polygon.yaml' has no VERSION. Assuming it to be compatible with latest v2.
  0%|                                                                                                                                            | 0/1 [00:00<?, ?it/s]/root/anaconda3/envs/mapkurator/lib/python3.8/site-packages/torch/functional.py:445: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at  /opt/conda/conda-bld/pytorch_1634272068694/work/aten/src/ATen/native/TensorShape.cpp:2157.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
  0%|                                                                                                                                            | 0/1 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "tools/inference.py", line 96, in <module>
    predictions, poly_text_score_dict_list = demo.inference_on_image(img)
  File "/home/spotter_v2/PALEJUN/tools/predictor.py", line 95, in inference_on_image
    visualizer = TextVisualizer(image, self.metadata, instance_mode=self.instance_mode, cfg=self.cfg)
  File "/home/spotter_v2/PALEJUN/adet/utils/visualizer.py", line 19, in __init__
    assert(int(self.voc_size - 1) == len(self.CTLABELS)), "voc_size is not matched dictionary size, got {} and {}.".format(int(self.voc_size - 1), len(self.CTLABELS))
AssertionError: voc_size is not matched dictionary size, got 7004 and 95.

How can I resolve this issue?

Operating environment:

  • All operations are running on Docker (knowledgecomputing/mapkurator_recogito_2023:latest)
  • The working directory is in /home/spotter_v2/PALEJUN
  • The conda environment is already activated (using the command that “conda activate mapKurator”)

Here are my observations:

The following is a code snippet from the mapKurator source code

# line 44 from /home/spotter_v2/PALEJUN/adet/utils/visualizer.py 

class TextVisualizer(Visualizer):
    def __init__(self, image, metadata, instance_mode, cfg):
        Visualizer.__init__(self, image, metadata, instance_mode=instance_mode)
        self.voc_size = cfg.MODEL.BATEXT.VOC_SIZE
        self.use_customer_dictionary = cfg.MODEL.BATEXT.CUSTOM_DICT
        self.use_polygon = cfg.MODEL.TRANSFORMER.USE_POLYGON
        if not self.use_customer_dictionary:
            self.CTLABELS = [' ','!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/','0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?','@','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[','\\',']','^','_','`','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','{','|','}','~']
        else:
            with open(self.use_customer_dictionary, 'rb') as fp:
                self.CTLABELS = pickle.load(fp)
        assert(int(self.voc_size - 1) == len(self.CTLABELS)), "voc_size is not matched dictionary size, got {} and {}.".format(int(self.voc_size - 1), len(self.CTLABELS))

From the code snippet, it seems that there is an intention to perform a vec2word operation. If cfg.MODEL.BATEXT.CUSTOM_DICT is not specified, the program is able to use the default self.CTLABELS (for the English version of the model). However, the default vector size does not match VOC_SIZE in the Chinese configuration file (as shown below).

# from github https://github.com/knowledge-computing/mapkurator-spotter 
# file config-ch/SynthMap-ch/SynthMap_Polygon.yaml

_BASE_: "Base-SynthMap-Polygon.yaml"
DATASETS:
  TRAIN: ("synmap_jp_osm", "synmap_jp_skeleton","synthtext_ch",)
  TEST: ("synthtext_ch",)
MODEL:
  # ...skip...
  BATEXT:
      CANONICAL_SIZE: 7005
      CONV_DIM: 256
      CUSTOM_DICT: # for self.use_customer_dictionary
      IN_FEATURES:
      - p2
      - p3
      - p4
      NUM_CHARS: 47
      NUM_CONV: 2
      POOLER_RESOLUTION:
      - 8
      - 32
      POOLER_SCALES:
      - 0.25
      - 0.125
      - 0.0625
      RECOGNITION_LOSS: ctc
      RECOGNIZER: attn
      SAMPLING_RATIO: 1
      USE_AET: false
      USE_COORDCONV: false
      VOC_SIZE: 7005 # for self.voc_size

Additionlly, I can't find the file that stores CTLABELS for the Chinese version, so I cannot specify cfg.MODEL.BATEXT.CUSTOM_DICT.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions