ValueError: cannot convert float NaN to integer
See original GitHub issueThanks for this open source contribution!
I am seeing the same problem as in issue #37 - although I am using the fix for that issue (commit c85ca3f5b1c00b785ca346882a8983d57287d75f to generate my datalist)
Specifically, when I train on my own data (open source dataset FinTabNet) I see the following errors:
/home/usr/DAVAR-Lab-OCR/davarocr/davar_table/core/mask/lp_mask_target.py:55: RuntimeWarning: Mean of empty slice.
middle_x, middle_y = round(np.where(box_text == 1)[1].mean()), round(np.where(box_text == 1)[0].mean())
/home/usr/DAVAR-Lab-OCR/davarocr/davar_table/core/mask/lp_mask_target.py:55: RuntimeWarning: Mean of empty slice.
Traceback (most recent call last):
File "acx-tsr/scripts/train_lgpma.py", line 316, in <module>
main()
File "acx-tsr/scripts/train_lgpma.py", line 311, in main
meta=meta,
File "/home/usr/DAVAR-Lab-OCR/davarocr/davar_common/apis/train.py", line 174, in train_model
middle_x, middle_y = round(np.where(box_text == 1)[1].mean()), round(np.where(box_text == 1)[0].mean())
runner.run(data_loaders, cfg.workflow)
File "/home/usr/mmcv/mmcv/runner/epoch_based_runner.py", line 125, in run
epoch_runner(data_loaders[i], **kwargs)
File "/home/usr/mmcv/mmcv/runner/epoch_based_runner.py", line 50, in train
self.run_iter(data_batch, train_mode=True, **kwargs)
File "/home/usr/mmcv/mmcv/runner/epoch_based_runner.py", line 30, in run_iter
**kwargs)
File "/home/usr/mmcv/mmcv/parallel/data_parallel.py", line 67, in train_step
return self.module.train_step(*inputs[0], **kwargs[0])
File "/home/usr/mmdetection/mmdet/models/detectors/base.py", line 247, in train_step
losses = self(**data)
File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 918, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/usr/mmcv/mmcv/runner/fp16_utils.py", line 124, in new_func
output = old_func(*new_args, **new_kwargs)
File "/home/usr/mmdetection/mmdet/models/detectors/base.py", line 181, in forward
return self.forward_train(img, img_metas, **kwargs)
File "/home/usr/DAVAR-Lab-OCR/davarocr/davar_table/models/detectors/lgpma.py", line 132, in forward_train
**kwargs)
File "/home/usr/DAVAR-Lab-OCR/davarocr/davar_table/models/roi_heads/lgpma_roi_head.py", line 84, in forward_train
gt_masks, img_metas, gt_bboxes)
File "/home/usr/DAVAR-Lab-OCR/davarocr/davar_table/models/roi_heads/lgpma_roi_head.py", line 131, in _mask_forward_train
self.train_cfg, gt_bboxes)
File "/home/usr/DAVAR-Lab-OCR/davarocr/davar_table/models/roi_heads/mask_heads/lpma_mask_head.py", line 105, in get_targets
gt_lpma_hor, gt_lpma_ver = get_lpmasks(gt_masks, gt_bboxes)
File "/home/usr/DAVAR-Lab-OCR/davarocr/davar_table/core/mask/lp_mask_target.py", line 30, in get_lpmasks
gt_masks_temp = list(gt_masks_temp)
File "/home/usr/DAVAR-Lab-OCR/davarocr/davar_table/core/mask/lp_mask_target.py", line 55, in get_lpmask_single
middle_x, middle_y = round(np.where(box_text == 1)[1].mean()), round(np.where(box_text == 1)[0].mean())
ValueError: cannot convert float NaN to integer
Any help would be very appreciated!
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top Results From Across the Web
Pandas: ValueError: cannot convert float NaN to integer
NB: You have to go through numpy float first and then to nullable Int32, for some reason. The size of the int if...
Read more >How to Fix: ValueError: cannot convert float NaN to integer
This error occurs when you attempt to convert a column in a pandas DataFrame from a float to an integer, yet the column...
Read more >How to Fix: ValueError: cannot convert float NaN to integer
In Python, NaN stands for Not a Number. This error will occur when we are converting the dataframe column of the float type...
Read more >ValueError: cannot convert float NaN ... - Net-Informations.Com
NaN is short for Not a Number . It is a numeric data type used to represent any value that is undefined or...
Read more >valueerror: cannot convert float nan to integer ( Solved )
There are many times when a programmer raises an exception that is the ValueError. You can get this error when you give a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Could you provide the datalist you generated (you may send it by email)?
To update on this if anyone else is having this issue I added a hack to fix it here: https://github.com/AccelexTechnology/DAVAR-Lab-OCR/commit/ce6d9ce766573362e3354ece5718ca722feaa4c4
^ this was only appropriate as it affected a small proportion of my dataset (~1/5000 samples) - it will give bad results otherwise as I am setting the index to an arbitrary (and hence likely incorrect) non-NaN value
I spent a long time looking at one of the samples from FinTabNet that was causing the issue here:
But couldn’t see anything wrong that would allow me to programatically filter the bad samples out of the dataset. I think the issue arose in the DavarLoadAnnotations._poly2mask function but didn’t debug further than this