AdvancedLiterateMachinery icon indicating copy to clipboard operation
AdvancedLiterateMachinery copied to clipboard

Update create_grid_input.py

Open LUCIFERX92 opened this issue 1 year ago • 1 comments
trafficstars

TypeError in create_grid_input.py

Description of the Issue

When running the script, the following error occurs:

File "/Users/i_manav.gupta/VGT_V4/VGT/object_detection/create_grid_input.py", line 215, in <module>
    save_pkl_file(grid, args.output, f"page_{page}", page, args.model)
TypeError: save_pkl_file() takes from 3 to 4 positional arguments but 5 were given

This error suggests that the save_pkl_file() function is being called with more arguments than it can accept.

Proposed Solution

Update the save_pkl_file() function in VGT/object_detection/create_grid_input.py to accept the correct number of arguments:

def save_pkl_file(grid, output_dir, filename, model):
    os.makedirs(output_dir, exist_ok=True)
    if model == 'doclaynet':
        with open(os.path.join(output_dir, f"{filename}.pkl"), 'wb') as f:
            pickle.dump(grid, f)
    else:
        with open(os.path.join(output_dir, f"{filename}.pdf.pkl"), 'wb') as f:
            pickle.dump(grid, f)

Also, update the function call to match the new signature:

save_pkl_file(grid, args.output, f"page_{page}", args.model)

Steps to Reproduce

  1. Navigate to the VGT/object_detection/ directory
  2. Run the create_grid_input.py script
  3. Observe the TypeError

Expected Behavior

The script should run without errors and save the pickle file as intended.

Additional Context

This issue appears to be caused by a mismatch between the function definition and its usage. The proposed solution adjusts both to ensure they are consistent.

LUCIFERX92 avatar Jul 15 '24 05:07 LUCIFERX92