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

Image normalization #24

Closed
uutzinger opened this issue Jan 13, 2022 · 1 comment
Closed

Image normalization #24

uutzinger opened this issue Jan 13, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@uutzinger
Copy link

I understand your code is based Stanislas Bertrand's but please take a look at the following line in the preprocessor:

im_tensor[0, :, :, i] = (img[:, :, 2 - i] / pixel_scale - pixel_means[2 - i]) / pixel_stds[2 - i]

Under low light conditions this would result in same image contrast as with bright images as you remove the average image intensity and divide by the average fluctuations in the image.

However both Stansilas and you define pixel means to be 0 and stds to be 1 and you don't compute them for each image.
Basically your code subtracts 0 and divides each pixel by 1 which is unnecessary.
If people want to use retinaface on dark images it might be useful to provide option to compute means with np.mean(image) and np.std(image).

Simplified preprocessor:
def preprocess_image(img, allow_upscaling):
scales = [1024, 1980]
img, img_scale = resize_image(img, scales, allow_upscaling)
img = img.astype(np.float32)
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img_tensor = np.expand_dims(img_rgb, axis=0)
return img_tensor, img.shape[0:2], img_scale

Unfortunately most of computation time is used in the tensor computation and this changes has little impact on performance.

@serengil
Copy link
Owner

thank you for your contribution

@serengil serengil added the enhancement New feature or request label Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants