Pix2Seq icon indicating copy to clipboard operation
Pix2Seq copied to clipboard

some bugs about test.py

Open JJJYmmm opened this issue 1 year ago • 2 comments

Hi Shariatnia, I meet some trouble in test.py

issue 1

Firstly, function postprocess does not consider the situation where the model detect nothing,so it will pass empty sequence(<BOS><EOS>) to tokenizer.decoder, and get error like #5. Considering this case, we can add a judgment conditionEOS_idx == 1 to include the empty seq case.

for i, EOS_idx in enumerate(EOS_idxs.tolist()):
        if EOS_idx == 0 or EOS_idx ==1: # invalid idx which EOS_idx = 0 or the model detect nothing when EOS_idx = 1 
            all_bboxes.append(None)
            all_labels.append(None)
            all_confs.append(None)
            continue

issue 2

Secondly,If I put CFG.run_eval=True and run test.py,I got nothing in voc_preds.csv.I try debug and I found that the problem comes from misjudgment of the type.I think the code wants to filter entries without prediction boxes.But at that time, x's type is numpy.ndarray

# preds_df = preds_df[preds_df['bbox'].map(lambda x: isinstance(x, list))].reset_index(drop=True)
# fix : list -> np.ndarray
preds_df = preds_df[preds_df['bbox'].map(lambda x: isinstance(x, np.ndarray))].reset_index(drop=True)

issue 3

The last issue occurs below.I think the code wants to assign the predict result with image id. It is OK when valid_df doesn't have duplicate entries.

preds_df = pd.DataFrame()
valid_df = valid_df.iloc[:len(all_bboxes)]
preds_df['id'] = valid_df['id'].copy()
preds_df['bbox'] = all_bboxes
preds_df['label'] = all_labels
preds_df['conf'] = all_confs

Actually,valid_df have some duplicate entries, because different objects in one image are save dependently.So it will lose some image and break the mapping relationship between images and predictions when useing slice [:len(all_bboxes)] to get corresponding img_id. To fix it, I use valid_df['id'].unique() to get validation set's id, it works because the order is fixed(dataloader,shuffle=True)

preds_df = pd.DataFrame()
preds_df['id'] = valid_df['id'].unique().copy()
preds_df['bbox'] = all_bboxes
preds_df['label'] = all_labels
preds_df['conf'] = all_confs

Then I use the modified code and the weight file you provided for testing,and get mAP=0.329(better than 0.264). image-20230901001735855

Finally, thank you again for your tutorial. It's really useful!

JJJYmmm avatar Sep 02 '23 03:09 JJJYmmm

Hello, I ran the test file and encountered the following problem, do you have any good solution:

Traceback (most recent call last): File "C:/Users/fc747/Desktop/Pix2Seq-master/test.py", line 136, in preds_df = preds_df.explode(['bbox', 'label', 'conf']).reset_index(drop=True) File "D:\anaconda\envs\try\lib\site-packages\pandas\core\frame.py", line 8254, in explode raise ValueError("columns must have matching element counts") ValueError: columns must have matching element counts

ff-jj-8 avatar Sep 22 '23 08:09 ff-jj-8

Hello, I ran the test file and encountered the following problem, do you have any good solution:

Traceback (most recent call last): File "C:/Users/fc747/Desktop/Pix2Seq-master/test.py", line 136, in preds_df = preds_df.explode(['bbox', 'label', 'conf']).reset_index(drop=True) File "D:\anaconda\envs\try\lib\site-packages\pandas\core\frame.py", line 8254, in explode raise ValueError("columns must have matching element counts") ValueError: columns must have matching element counts

@ff-jj-8 Hello! I didn't encountered the problem, you can check pandas version(pandas==1.3.5), or try to call single column explode iteratively like preds_df.explode('bbox').explode('label').explode('conf')

JJJYmmm avatar Sep 22 '23 13:09 JJJYmmm