Giter Site home page Giter Site logo

Comments (4)

mihran113 avatar mihran113 commented on September 12, 2024

Hey @eltonjohnfanboy! Sorry for late response and thanks for opening the issue. There's an issue in our callback, I'll make sure to include the fix in the upcoming release. In the meantime you can use the following script as a workaround to track the metrics:

from typing import Any, Dict, Tuple, Union
import os
import gymnasium
from stable_baselines3 import PPO
from stable_baselines3.common.vec_env import DummyVecEnv
from stable_baselines3.common.evaluation import evaluate_policy
from stable_baselines3.common.logger import HumanOutputFormat, KVWriter, Logger

from aim import Run
import numpy as np


class AimOutputFormat(KVWriter):
    """
    Track key/value pairs into Aim run.
    """

    def __init__(
        self,
        aim_run
    ):
        self.aim_run = aim_run

    def write(
        self,
        key_values: Dict[str, Any],
        key_excluded: Dict[str, Union[str, Tuple[str, ...]]],
        step: int = 0,
    ) -> None:
        for (key, value), (_, excluded) in zip(
            sorted(key_values.items()), sorted(key_excluded.items())
        ):
            if excluded is not None and 'aim' in excluded:
                continue

            if isinstance(value, np.ScalarType):
                if not isinstance(value, str):
                    tag, key = key.split('/')
                    if tag in ['train', 'valid']:
                        context = {'subset': tag}
                    else:
                        context = {'tag': tag}

                    self.aim_run.track(value, key, step=step, context=context)


run = Run()
loggers = Logger(
    folder=None,
    output_formats=[AimOutputFormat(run)],
)

environment_name = 'CartPole-v1'
env = gymnasium.make(environment_name)

env = DummyVecEnv([lambda: env])
model = PPO('MlpPolicy', env, verbose = 1)
model.set_logger(loggers)
model.learn(total_timesteps=10_000)

from aim.

eltonjohnfanboy avatar eltonjohnfanboy commented on September 12, 2024

Hi @mihran113, no worries at all. Thanks a lot for your work and the update! Looking forward to the upcoming release and will be using the script in the meantime. :))

from aim.

mihran113 avatar mihran113 commented on September 12, 2024

Hey @eltonjohnfanboy! The new version of aim has been shipped (3.23.0) which includes the fix for this issue. Please let me know if everything works as expected so I can close the issue.

from aim.

eltonjohnfanboy avatar eltonjohnfanboy commented on September 12, 2024

Hi @mihran113, sorry for the delayed response. Thanks for the update; it works correctly now! :))

from aim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.