microsoft / table-transformer

Table Transformer (TATR) is a deep learning model for extracting tables from unstructured documents (PDFs and images). This is also the official repository for the PubTables-1M dataset and GriTS evaluation metric.
MIT License
2.22k stars 247 forks source link

--words_dir file.json : argument to inference.py #97

Open PawarKishori opened 1 year ago

PawarKishori commented 1 year ago

What should be the content of file.json along with the format? Thanks :)

PawarKishori commented 1 year ago

What should be the content of file.json along with the format? Thanks :)

My file.json looks as follows:

{ "header": [ "Id", "Address"] }

After this I am getting an error:

Traceback (most recent call last): File "inference.py", line 939, in main() File "inference.py", line 904, in main token['span_num'] = idx TypeError: 'str' object does not support item assignment

My assumption is the tokens expected by the code and mine and differing and hence this error... Please correct me if I am wrong. Awaiting for reply!

semzero commented 1 year ago

Source and for more details -> docs/INFERENCE.md


The json file should look something like this:

[
    {
        "bbox": [0.0, 0.0, 50.0, 50.0]
        "text": "First"
    },
    {
        "bbox": [52.0, 0.0, 102.0, 50.0]
        "text": "next"
    }
]

Let's say you have an image image_01.jpg in folder images. And the corresponding json file's name should be image_01_words.json in a folder -let's say- image_words.

The --words_dir flag accepts only folder path, single json file path won't work. (You should put the json file in a folder even if you want to work with single image and its corresponding json file.

Finally, your folder structure should look something like this:

images/
  image_01.jpg
  image_02.jpg
  ...

image_words/
  image_01_words.json
  image_02_words.json
  ...

Now your inference command becomes: (just for structure recognition/extraction)

## cd into `src` folder of this repo
python inference.py \
--mode recognize --structure_config_path structure_config.json \
--structure_model_path /path/to/pubtables1m_structure_detr_r18.pth \  ## <- your weights path
--structure_device cpu \   ## <- your device choice "cuda, cpu or mps"
--image_dir /path/to/images/ \  ## <- your folder path containing images
--words_dir /path/to/image_words/ \  ## <- your folder path containing corresponding json files
--out_dir ../00_outputs/ \  ## <- your output folder path
-o -l -m -v -z  ## <- other flags of your choice

I hope this helps.