stable-baselines3 icon indicating copy to clipboard operation
stable-baselines3 copied to clipboard

[Feature Request] Inform what normalization from preprocess_obs was applied to verbose = 2

Open zippeurfou opened this issue 2 years ago • 3 comments

🚀 Feature

I suggest we add a log with verbose=2 that describe if preprocess_obs normalized any of the input for the network.

Motivation

This is a very small one but the fact we don't know if the image/on hot is normalized without manually having to check it manually is cumbersome. Most likely it ends up in behavior where people use VecNormalization when they don't have to.

Pitch

I would like to be able to see in my logs if my observation space got normalized.

Alternatives

Alternatively, it could be an extra property of the policy object after model training.

Additional context

No response

Checklist

  • [X] I have checked that there is no similar issue in the repo

zippeurfou avatar Dec 08 '22 05:12 zippeurfou

Hello,

I suggest we add a log with verbose=2 that describe if preprocess_obs normalized any of the input for the network.

where exactly do you want to print additional information?

For short, images are always normalized (by diving by 255 unless normalize_images=False as written in the doc) and discrete observations are always converted to one-hot vector. The rest (casting to float) is just to avoid pytorch errors and not interesting information for the user.

Most likely it ends up in behavior where people use VecNormalization when they don't have to.

we have explicit warning in the documentation for that normally.

EDIT: there seems to be a typo in https://stable-baselines3.readthedocs.io/en/master/guide/custom_env.html and note should be improved (feel free to open a PR for that ;))

araffin avatar Dec 09 '22 12:12 araffin

Thanks for the reply @araffin.

where exactly do you want to print additional information?

I would suggest doing it at the beginning of the training the same way we display this kind of log:

Using cpu device
Wrapping the env in a VecTransposeImage.
Logging to XXX

For short, images are always normalized (by diving by 255 unless normalize_images=False as written in the doc) and discrete observations are always converted to one-hot vector.

I was referring to this line: https://github.com/DLR-RM/stable-baselines3/blob/master/stable_baselines3/common/preprocessing.py#L34

The check is conservative so that it returns False if there is a doubt.

Because it mentions it is conservative I was thinking it might not be bad to actually report on it just in case.

Feel free to close it if you think it's not helpful.

zippeurfou avatar Dec 09 '22 14:12 zippeurfou

I would suggest doing it at the beginning of the training the same way we display this kind of log:

I see. Will be a bit harder in that case because the preprocess method is called multiple times.

Because it mentions it is conservative I was thinking it might not be bad to actually report on it just in case.

that's why we recommend using the env checker for custom envs. We also improved checks and error messages in https://github.com/DLR-RM/stable-baselines3/pull/1214

araffin avatar Jan 02 '23 09:01 araffin