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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file mlagents-video-streamer-2.0.tar.gz.

File metadata

  • Download URL: mlagents-video-streamer-2.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.1

File hashes

Hashes for mlagents-video-streamer-2.0.tar.gz
Algorithm Hash digest
SHA256 78319a7b341be5b9f6a72fe11fbee53cb86d59ece72cc3aa1447c32ff863270b
MD5 231749e2b03f8336ed58e8fc1e45c995
BLAKE2b-256 a869906a65579c6e075d72239f7207db82a561fa637d7752ac632e9f7f0497bc

See more details on using hashes here.

File details

Details for the file mlagents_video_streamer-2.0-py3-none-any.whl.

File metadata

  • Download URL: mlagents_video_streamer-2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.1

File hashes

Hashes for mlagents_video_streamer-2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f73937f037cd5cb06b6318c17bc3dcddaf4df8f94f870ec5f2c3a8b36982db5e
MD5 abbfad2b35d463b932443eefd9d6bcd1
BLAKE2b-256 aa2dac78fe648c1563f88726c030d45726d75a5e5cc5cf8dac1807698eeb5509

See more details on using hashes here.

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