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

[Bug]: Logging a np.ndarray with Logger does not log a histogram

Open iwishiwasaneagle opened this issue 11 months ago • 0 comments

🐛 Bug

When logging a np.ndarray usingSummaryWriter, it detects this and logs it as a histogram. This is not the case in SB3's TensorBoardOutputFormat writer which currently completely ignores this type and does not log anything.

Relevant links

Torch

https://github.com/pytorch/pytorch/blob/c2e948edcad497fc49feef129532f9aff2553882/torch/utils/tensorboard/summary.py#L442-L460

https://github.com/pytorch/pytorch/blob/c2e948edcad497fc49feef129532f9aff2553882/torch/utils/tensorboard/_convert_np.py#L8-L26

SB3

https://github.com/DLR-RM/stable-baselines3/blob/ba77dd7c6180c0ec9a47dfa98291c2103e6750df/stable_baselines3/common/logger.py#L415-L416

To Reproduce

import numpy as np
from stable_baselines3.common.logger import Logger, TensorBoardOutputFormat
from tensorboard.backend.event_processing.event_accumulator import EventAccumulator
import torch as th
import tempfile

folder = tempfile.mktemp()

# Write the data

logger = Logger(folder=folder, output_formats=[TensorBoardOutputFormat(folder=folder)])

logger.record("numpy", np.random.rand(5))
logger.record("torch", th.rand(5))

logger.dump(0)

# Read the data

acc = EventAccumulator(folder)
acc.Reload()

print(acc.histograms.Keys())
# ['torch']
print(acc.compressed_histograms.Keys())
# ['torch']

Relevant log output / Error message

No response

System Info

  • OS: Linux-5.15.112-1-MANJARO-x86_64-with-glibc2.37 # 1 SMP PREEMPT Wed May 17 11:11:32 UTC 2023
  • Python: 3.10.10
  • Stable-Baselines3: 2.1.0a3
  • PyTorch: 2.0.1+cu117
  • GPU Enabled: False
  • Numpy: 1.25.1
  • Cloudpickle: 2.2.1
  • Gymnasium: 0.29.0

Checklist

  • [X] My issue does not relate to a custom gym environment. (Use the custom gym env template instead)
  • [X] I have checked that there is no similar issue in the repo
  • [X] I have read the documentation
  • [X] I have provided a minimal and working example to reproduce the bug
  • [X] I've used the markdown code blocks for both code and stack traces.

iwishiwasaneagle avatar Jul 28 '23 17:07 iwishiwasaneagle