Skip to content

Commit

Permalink
Fix TensorBoard file iterator (#178)
Browse files Browse the repository at this point in the history
* Move torch import to local scope and catch tensorboard summary iterator exceptions

* Update CHANGELOG
  • Loading branch information
Toni-SM committed Jul 21, 2024
1 parent 4a89f80 commit 82ea390
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Move the KL reduction from the PyTorch `KLAdaptiveLR` class to each agent using it in distributed runs
- Move the PyTorch distributed initialization from the agent base class to the ML framework configuration

### Fixed
- Catch TensorBoard summary iterator exceptions in `TensorboardFileIterator` postprocessing utils

## [1.2.0] - 2024-06-23
### Added
- Define the `environment_info` trainer config to log environment info (PyTorch implementation)
Expand Down Expand Up @@ -99,7 +102,7 @@ and Omniverse Isaac Gym environments when they are loaded

## [0.10.1] - 2023-01-26
### Fixed
- Tensorboard writer instantiation when `write_interval` is zero
- TensorBoard writer instantiation when `write_interval` is zero

## [0.10.0] - 2023-01-22
### Added
Expand Down Expand Up @@ -218,7 +221,7 @@ to allow storing samples in memories during evaluation
## [0.4.1] - 2022-03-22
### Added
- Examples of all Isaac Gym environments (preview 3)
- Tensorboard file iterator for data post-processing
- TensorBoard file iterator for data post-processing

### Fixed
- Init and evaluate agents in ParallelTrainer
Expand Down
33 changes: 19 additions & 14 deletions skrl/utils/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import os

import numpy as np
import torch

from skrl import logger


class MemoryFileIterator():
Expand Down Expand Up @@ -78,6 +79,7 @@ def _format_torch(self) -> Tuple[str, dict]:
:return: Tuple of file name and data
:rtype: tuple
"""
import torch
filename = os.path.basename(self.file_paths[self.n])
data = torch.load(self.file_paths[self.n])

Expand Down Expand Up @@ -158,18 +160,21 @@ def __next__(self) -> Tuple[str, dict]:
self.n += 1

data = {}
for event in summary_iterator(file_path):
try:
# get Tensorboard data
step = event.step
tag = event.summary.value[0].tag
value = event.summary.value[0].simple_value
# record data
if tag in self.tags:
if not tag in data:
data[tag] = []
data[tag].append([step, value])
except Exception as e:
pass
try:
for event in summary_iterator(file_path):
try:
# get Tensorboard data
step = event.step
tag = event.summary.value[0].tag
value = event.summary.value[0].simple_value
# record data
if tag in self.tags:
if not tag in data:
data[tag] = []
data[tag].append([step, value])
except Exception as e:
pass
except Exception as e:
logger.warning(str(e))

return os.path.dirname(file_path).split(os.sep)[-1], data

0 comments on commit 82ea390

Please sign in to comment.