Downloads · 30 days
0
0% of all-time downloads
Flavio0834/a2c-CartPole-v1
a2c-CartPole-v1 is a reinforcement learning model from Flavio0834. Use it for the reinforcement learning task on the model card, and read the license before you ship it in a product. It is set up for stable-baselines3.
This is a trained model of a A2C agent playing CartPole-v1 using the stable-baselines3 library.
Downloads · 30 days
0
0% of all-time downloads
All-time downloads
38
Public
Repo size
188 KB
Likes
0
Public
Click a slice to open those files.
.zip101 KB · 46%
From the Hugging Face model README
This is a trained model of a A2C agent playing CartPole-v1 using the stable-baselines3 library.
import gymnasium as gym
from stable_baselines3 import A2C
from stable_baselines3.common.evaluation import evaluate_policy
from huggingface_sb3 import package_to_hub
from huggingface_hub import login
def main():
# CONSTANTS
TOTAL_TIMESTEPS = 100_000 # Avec SB3 on raisonne souvent en "timesteps" (étapes) plutôt qu'en "épisodes"
ENV_ID = "CartPole-v1"
# 1. Env setup
env = gym.make(ENV_ID)
# 2. Model setup (cf. documentation)
model = A2C("MlpPolicy", env, verbose=1)
print("Début de l'entraînement avec Stable-Baselines3 (A2C)...")
# 3. Training
model.learn(total_timesteps=TOTAL_TIMESTEPS)
# 4. Save model
model.save("a2c_sb3_cartpole")
print("Modèle sauvegardé sous a2c_sb3_cartpole.zip !")
# 5. Evaluation
print("Évaluation du modèle entraîné...")
mean_reward, std_reward = evaluate_policy(model, env, n_eval_episodes=100, render=False)
print(f"RÉSULTATS DE L'ÉVALUATION: Récompense moyenne = {mean_reward} +/- {std_reward}")
env.close()
# HuggingFace
# 6. Upload du modèle sur le Hub Hugging Face
print("Préparation du modèle pour le Hub Hugging Face...")
model_name = "a2c-CartPole-v1"
repo_id = f"Flavio0834/{model_name}"
commit_message = "Upload du modèle A2C pour CartPole-v1 (BE Apprentissage Automatique)"
package_to_hub(
model=model, # Notre modèle entraîné en mémoire
model_name=model_name, # Le nom affiché sur le repo
model_architecture="A2C", # L'algorithme
env_id=ENV_ID, # L'ID gym
eval_env=gym.make(ENV_ID, render_mode="rgb_array"), # Un env spécifique pour générer la vidéo
repo_id=repo_id, # Le repo cible
commit_message=commit_message # Le message de git commit
)
print(f"Modèle envoyé avec succès sur : https://huggingface.co/{repo_id}")
if __name__ == '__main__':
main()