DeepRule Deep Learning Framework

repository·master·Indexed 41 days ago

https://github.com/soap117/deeprule

A deep learning framework for chart analysis supporting Bar, Pie, and Line charts. It features specialized components for corner pooling, NMS, and OCR integration, with model implementations including CornerNetPureBar, CornerNetPurePie, CornerNetLine, CornerNetLineClsReal, and CornerNetCls.

Tokens
845
Snippets
7
Records
9
Agent score
50%

What's inside DeepRule

  1. Implement or replace the OCR API

    master

    The original implementation uses an Azure web service. If you do not have access to Azure, you can replace the ocr_result(image_path) function using the pytesseract package.

    The function must return a dictionary (or similar structure) where each word entry contains:

    • text: The string version of the word.
    • boundingBox: The bounding box in the format [topleft_x, topleft_y, bottomleft_x, bottomleft_y].
  2. Install and set up the DeepRule environment

    master

    DeepRule requires an Anaconda environment and a machine with a GPU and CUDA installed.

    1. Create the environment using the provided package list:
    conda create --name DeepRule --file DeepRule.txt
    1. Activate the environment:
    source activate DeepRule

    If the original DeepRule.txt fails to install, try using requirements-2023.txt instead.

    conda create --name DeepRule --file DeepRule.txt
    source activate DeepRule
  3. Compile Corner Pooling Layers

    master

    You must compile the C++ implementation of the corner pooling layers. This implementation is based on CornerNet. Navigate to the specific directory within your CornerNet installation and run the setup script:

    cd <CornerNet dir>/models/py_utils/_cpools/
    python setup.py build_ext --inplace
  4. Train DeepRule models

    master

    To train a model, you need a JSON configuration file in config/ and a corresponding .py model file in models/.

    Module Configuration Names:

    • Bar: CornerNetPureBar
    • Pie: CornerNetPurePie
    • Line: CornerNetLine
    • Query: CornerNetLineClsReal
    • Cls: CornerNetCls

    Training Command:

    python train_chart.py --cfg_file <model_name> --data_dir <data_path>
    # Example:
    python train_chart.py --cfg_file CornerNetBar --data_dir /home/data/bardata(1031)
    python train_chart.py --cfg_file CornerNetBar --data_dir /home/data/bardata(1031)
  5. Test a batch of data with a specific chart type

    master

    To test a batch of images directly, you must pre-assign the chart type using the test_pipe_type_cloud.py script:

    python test_pipe_type_cloud.py --image_path <image_path> --save_path <save_path> --type <type>
    # Example:
    python test_pipe_type_cloud.py --image_path /data/bar_test --save_path save --type Bar
    python test_pipe_type_cloud.py --image_path /data/bar_test --save_path save --type Bar
  6. Understand DeepRule data formats

    master

    The dataset contains different formats depending on the chart type:

    • Pie data: bbox is [center_x, center_y, edge_1_x, edge_1_y, edge_2_x, edge_2_y], representing the three critical points for a sector.
    • Line data: bbox is [d_1_x, d_1_y, ..., d_n_x, d_n_y], representing the data points for a line.
    • Bar data: bbox is the standard bounding box of the bars.
    • Cls data: bbox is the standard bounding box. Different category_id values refer to different components (e.g., draw area, title, legends).