Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CheXpert bbox annotations scaling #1

Closed
uizdd opened this issue May 15, 2022 · 1 comment
Closed

CheXpert bbox annotations scaling #1

uizdd opened this issue May 15, 2022 · 1 comment

Comments

@uizdd
Copy link

uizdd commented May 15, 2022

I have trained the model with the CheXpert dataset (440Gb version). Unfortunately, the generated masks are all scaled incorrectly.
https://we.tl/t-BejaX6Plgg (The generated masks seem to be too large by a factor of about 1.3.)

For the NIH Chest X-ray14 dataset, everything works fine.

My understanding is that the images and bounding boxes are always transformed together. So it is not clear to me how such an error can occur.

@uizdd
Copy link
Author

uizdd commented May 16, 2022

Due to the annotation format differing from the NIH Chest X-ray14 dataset, I suggest the following changes if you are using the CheXpert dataset:

net_utils.py

    #factor = float(config['img_size']) / 1024.           
    factor_h = float(config['img_size']) / 2320.
    factor_w = float(config['img_size']) / 2828.
    for b_i in range(len(config['Data_CLASSES'])):
        if config['Data_CLASSES'][b_i] in bbox_img_gt:
            for loc in bbox_img_gt[config['Data_CLASSES'][b_i]]:
                #bbox_img = cv2.rectangle(bbox_img, (int(loc[0]*factor), int(loc[1]*factor)), (int((loc[0]+loc[2])*factor), int((loc[1]+loc[3])*factor)), (palette[b_i+1][2],palette[b_i+1][1],palette[b_i+1][0]), 4)
                bbox_img = cv2.rectangle(bbox_img, (int(loc[0]*factor_w), int(loc[1]*factor_h)), (int(loc[2]*factor_w), int(loc[3]*factor_h)), (palette[b_i+1][2],palette[b_i+1][1],palette[b_i+1][0]), 4)
    cv2.imwrite(bbox_path, bbox_img)

custom_dataset.py

    class BBoxToMask(object):
        def __call__(self, bboxs, classes, img, im_w, im_h, name, using_crf):
            img = np.array(img)
            img = np.ascontiguousarray(img)
            mask = []
            for idx in range(len(classes)):
                class_gts = np.zeros((im_h, im_w))
                if classes[idx] in bboxs:
                    mask_h = 0
                    mask_w = 0
                    j = 0
                    for loc in bboxs[classes[idx]]:
                        #mask_h += loc[2]
                        mask_h += (loc[2] - loc[2])
                        #mask_w += loc[3]
                        mask_w += (loc[3] - loc[1])
                        #class_gts[int(loc[1]):int(loc[1]+loc[3]), int(loc[0]):int(loc[0]+loc[2])] = 1
                        class_gts[int(loc[1]):int(loc[3]), int(loc[0]):int(loc[2])] = 1
                        j += 1

@uizdd uizdd closed this as completed May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant