-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathppo_tra.py
More file actions
32 lines (21 loc) · 896 Bytes
/
Copy pathppo_tra.py
File metadata and controls
32 lines (21 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import gymnasium as gym
from stable_baselines3 import PPO
from video_streaming_env import VideoStreamingEnv
import os
env = VideoStreamingEnv()
model =PPO.load("ppo_video_streamerrrr", env=env) if os.path.exists("ppo_video_streamerrrr.zip") else PPO("MlpPolicy", env, verbose=1)
model.learn(total_timesteps=20000,progress_bar=True)
print("--- TRAINING FINISHED ---")
model.save("ppo_video_streamer_2")
print("\n--- TESTING THE NEW BRAIN ---")
obs, _ = env.reset()
total_reward = 0
for _ in range(20):
action, _states = model.predict(obs)
obs, reward, done, _, info = env.step(action)
speed = f"{obs[0]:.0f}kbps"
qual = ["Low", "Med", "High"][int(obs[2])]
print(f"AI Chose: {qual} | Speed: {speed} | Rebuffer: {info['rebuffer']:.2f}s | Reward: {reward:.2f}")
total_reward += reward
if done: break
print(f"Total Reward: {total_reward:.2f}")