DevashishPrasad / CascadeTabNet

This repository contains the code and implementation details of the CascadeTabNet paper "CascadeTabNet: An approach for end to end table detection and structure recognition from image-based documents"
MIT License
1.49k stars 427 forks source link

Run a prediction #37

Closed gireek closed 4 years ago

gireek commented 4 years ago

I am using Pytorch for the first time. I am not able to understand how to run a prediction on an image to get the table. Please guide.

AyanGadpal commented 4 years ago

We are using mmdetection 1.2, which provide ready to use api for inference

# Load model
config_file = './model_config.py'
checkpoint_file = './model.pth'
model = init_detector(config_file, checkpoint_file, device='cuda:0')

# Test a single image 
img = "demo.jpg"

# Run Inference
result = inference_detector(model, img)

# Visualization results
show_result_pyplot(img, result, model.CLASSES)

# or save the visualization results to image files
model.show_result(img, result, out_file='result.jpg')

You can refer this Notebook.

gireek commented 4 years ago

Any changes required in the config file provided here before predicting? From the model zoo part I have picked the checkpoint corresponding to ICDAR 19 (Track A Modern) table detection but the above inference method fails on the last line :

from mmdet.apis import init_detector, inference_detector, show_result_pyplot
import mmcv
config_file = "cascade_mask_rcnn_hrnetv2p_w32_20e.py"
checkpoint_file = 'epoch_14.pth'
model = init_detector(config_file, checkpoint_file, device='cuda:0')

with the following error:

Exception ignored in: <bound method _TemporaryFileCloser.__del__ of <tempfile._TemporaryFileCloser object at 0x7f6aaed08710>>
Traceback (most recent call last):
  File "/usr/lib/python3.6/tempfile.py", line 591, in __del__
    self.close()
  File "/usr/lib/python3.6/tempfile.py", line 587, in close
    unlink(self.name)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpv3b8_1bi/tmp_ggj0sgp.py'
Exception ignored in: <bound method _TemporaryFileCloser.__del__ of <tempfile._TemporaryFileCloser object at 0x7f6aaed08d30>>
Traceback (most recent call last):
  File "/usr/lib/python3.6/tempfile.py", line 591, in __del__
    self.close()
  File "/usr/lib/python3.6/tempfile.py", line 587, in close
    unlink(self.name)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpdqwfqynw/tmpu40_ids3.py'

I think this is what this issue is also asking.

gireek commented 4 years ago

A similar unsolved issue has been mentioned here. It is unsolved.

AyanGadpal commented 4 years ago

I was unable to reproduce the error you are getting, Please take a look at demo notebook : Open In Colab Do tell us if you are still getting that error or not

cfz1025 commented 4 years ago

the code is wrong in mmcv.utils.config.py for create the tempfile,I change it like following

` def _file2dict(filename): filename = osp.abspath(osp.expanduser(filename)) check_file_exist(filename) if filename.endswith('.py'): with tempfile.TemporaryDirectory() as temp_config_dir: temp_config_file = tempfile.NamedTemporaryFile( dir=temp_config_dir, suffix='.py')

close temp file

            temp_config_file.close()

            temp_config_name = osp.basename(temp_config_file.name)
            shutil.copyfile(filename,
                            osp.join(temp_config_dir, temp_config_name))
            temp_module_name = osp.splitext(temp_config_name)[0]
            sys.path.insert(0, temp_config_dir)
            mod = import_module(temp_module_name)
            sys.path.pop(0)
            cfg_dict = {
                name: value
                for name, value in mod.__dict__.items()
                if not name.startswith('__')
            }
            # delete imported module
            del sys.modules[temp_module_name]

`

15926273249 commented 4 years ago

Any changes required in the config file provided here before predicting? From the model zoo part I have picked the checkpoint corresponding to ICDAR 19 (Track A Modern) table detection but the above inference method fails on the last line :

from mmdet.apis import init_detector, inference_detector, show_result_pyplot
import mmcv
config_file = "cascade_mask_rcnn_hrnetv2p_w32_20e.py"
checkpoint_file = 'epoch_14.pth'
model = init_detector(config_file, checkpoint_file, device='cuda:0')

with the following error:

Exception ignored in: <bound method _TemporaryFileCloser.__del__ of <tempfile._TemporaryFileCloser object at 0x7f6aaed08710>>
Traceback (most recent call last):
  File "/usr/lib/python3.6/tempfile.py", line 591, in __del__
    self.close()
  File "/usr/lib/python3.6/tempfile.py", line 587, in close
    unlink(self.name)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpv3b8_1bi/tmp_ggj0sgp.py'
Exception ignored in: <bound method _TemporaryFileCloser.__del__ of <tempfile._TemporaryFileCloser object at 0x7f6aaed08d30>>
Traceback (most recent call last):
  File "/usr/lib/python3.6/tempfile.py", line 591, in __del__
    self.close()
  File "/usr/lib/python3.6/tempfile.py", line 587, in close
    unlink(self.name)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpdqwfqynw/tmpu40_ids3.py'

I think this is what this issue is also asking.

have you solved this problem?