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

DataGenerator - Bounding box scaling Issue #24

Open
rdbch opened this issue Mar 28, 2019 · 0 comments
Open

DataGenerator - Bounding box scaling Issue #24

rdbch opened this issue Mar 28, 2019 · 0 comments

Comments

@rdbch
Copy link

rdbch commented Mar 28, 2019

Hi,

As trying to train my model I have found the following issue in the DataGenerator.py file.

In read_image_and_gt(), the original width and height are stored after the image was resized thus resulting in the fact that the scaling coefficients for X and Y will always be 1. If you were to train on images with different sizes this could be a major problem, because the bounding boxes won't be scaled accordingly.

def read_image_and_gt(img_files, gt_files, config):
.............
    for img_name, gt_name in zip(img_files, gt_files):

        #open img
        img = cv2.imread(img_name).astype(np.float32, copy=False)

        # scale image
        img = cv2.resize( img, (config.IMAGE_WIDTH, config.IMAGE_HEIGHT))

        #subtract means
        img = (img - np.mean(img))/ np.std(img)

        #store original height and width?
        orig_h, orig_w, _ = [float(v) for v in img.shape]

    .............................................................
       # scale annotation
        x_scale = config.IMAGE_WIDTH / orig_w
        y_scale = config.IMAGE_HEIGHT / orig_h

        # scale boxes
        bboxes_per_file[:, 0::2] = bboxes_per_file[:, 0::2] * x_scale
        bboxes_per_file[:, 1::2] = bboxes_per_file[:, 1::2] * y_scale
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