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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
5 tasks done
iwishiwasaneagle opened this issue Jul 28, 2023 · 0 comments 路 May be fixed by #1635
Open
5 tasks done

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

iwishiwasaneagle opened this issue Jul 28, 2023 · 0 comments 路 May be fixed by #1635
Labels
bug Something isn't working

Comments

@iwishiwasaneagle
Copy link
Contributor

馃悰 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

if isinstance(value, th.Tensor):
self.writer.add_histogram(key, value, step)

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

  • My issue does not relate to a custom gym environment. (Use the custom gym env template instead)
  • I have checked that there is no similar issue in the repo
  • I have read the documentation
  • I have provided a minimal and working example to reproduce the bug
  • I've used the markdown code blocks for both code and stack traces.
@iwishiwasaneagle iwishiwasaneagle added the bug Something isn't working label Jul 28, 2023
@iwishiwasaneagle iwishiwasaneagle linked a pull request Jul 28, 2023 that will close this issue
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant