0
votes

Im trying to train the multi output model. Im loading the images in batches as follows,

def get_batch_features(self, idx):
    return np.array([load_image(im) for im in self.im_list[idx * self.bsz: (1 + idx) * self.bsz]])

Following is my load_image function where im normalizing the images to range between 0 and 255 as follows

def load_image(im):
    return img_to_array(load_img(im, target_size=(224, 224))) / 255.

Im loading the labels which are the target coordinates of 4 xy coordinates.

def get_batch_labels(self, idx):
    return self.labels[idx * self.bsz: (idx + 1) * self.bsz,:]

How do I normalize the target coordinates by scaling it to [-1, 1]? since im not scaling it, im getting a huge validation loss as the model is overfitting. Is there by any means that i can scale the target coordinates between [-1,1]?

1

1 Answers

0
votes

Assuming that your target coordinates are somewhere in the interval [0,223] as this is how many pixels your images have, what about just adjusting this to [-111.5,111.5] by subtracting 111.5 and dividing by 111.5 afterwards?

return (self.labels[idx * self.bsz: (idx + 1) * self.bsz,:]-111.5)/111.5

Actually, from my experience, you don't need to hit [-1,1] precisely, it should be sufficient to just divide them by 100 so that they are in the right order of magnitude. Besides that, you could also compute the statistics over all labels and normalize them so that they follow zero mean/unit variance which is a common strategy.