Skip to main content

Live stream Unity's ML-Agents training process from Google Colab to Twitch/YouTube server.

Project description

ML-Agents Video Streamer

Now you can Live Stream the Agent's learning behavior to Twitch/YouTube from Google Colab while training these Agents.


Try Google Colab Notebook

colab link


What’s In This Document

Installation

!pip install mlagents-video-streamer

And if you already have mlagents-video-streamer then upgrade it by this command.

!pip install --upgrade mlagents-video-streamer

Imports and Usage

from mlagents_video_streamer import SetupVirtualDisplay
from mlagents_video_streamer import VideoStreamer
  • Now Setup the Virtual Display:

    SetupVirtualDisplay()
    
  • Define your live stream information:

    # stream_info dictionary should be in this format only
    stream_info = {
        "URL": "rtmp://live.twitch.tv/app/", # example of Twitch URL
        "secret": "--- secret here ---"
    }
    
  • Initialize the VideoStreamer class with stream_info:

    videoStreamer = VideoStreamer(stream_info)
    

    *If you don't pass stream_info then it will simply store the video locally in the videos directory.

  • Start the video streamer before starting with the training process:

    videoStreamer.start()
    
  • Now capture the training process, using subprocess library:

    import subprocess
    from random import randrange
    
    try:
        train = subprocess.run([
            "mlagents-learn", 
            "config.yaml",
            "--run-id=train-1",
            "--env=3DBall_example/3DBall.x86_64",
            "--base-port=" + str(randrange(9000, 9999))
        ],
            cwd="/content/", stdout=subprocess.PIPE)
        print("Training process has been successfully ended.")
    except Exception as e:
        print("You killed the training process in between.")
    finally:
        videoStreamer.close()
    

    *At the end don't forget to close the video streamer by using close() method on videoStreamer object as shown in the above example.

License

Licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mlagents-video-streamer-2.0.tar.gz (5.5 kB view hashes)

Uploaded Source

Built Distribution

mlagents_video_streamer-2.0-py3-none-any.whl (7.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page