Giter Site home page Giter Site logo

nba_detector's Introduction

NBA Detector

README IS OUT OF DATE

(npm i, brew install ffmpeg)

A TamperMonkey script for detecting NBA games, so you never need to watch a mid-game commercial again.

During a commercial break, mute your stream and put the tab in the background. Whenever the game comes back on, the stream will automatically unmute itself using a tensorflow model trained to detect live games.

Getting Started

Download TamperMonkey for Chrome here.

Add the contents of script.js to your installed userscripts on the TamperMonkey dashboard. At the top of the file, add as many @include tags as you'd like for any sites where you watch NBA streams in order for the script to run on those sites.

Uploading the Model

The trained model files are named ml5_basketball_model.json, ml5_basketball_model.weights.bin, and ml5_basketball_model_meta.json. The model data file is named ml5_basketball_model_data.json.

You have two options for uploading the model.

  1. Host an HTTP server at port 8080 serving the model files - a simple solution is to run http-server in a directory with these files (i.e. npx http-server --cors). You will hear a beep when the model has loaded (the beep will only sound if you have first interacted with the page in some way).
  2. Set manualUpload = true at the top of script.js. You will instead be prompted to upload the files manually by a modal. The text of the modal will change to indicate the model has loaded when ready.

Further Training the Model

If the model innacurately classifies the stream, you can further train the model yourself - or even train your own model from scratch (for example, for NFL streams). At the bottom of your web page, the script appends classified images with their scores. If you click on any of these images your browser will prompt you - select "OK" to indicate the image is of an active NBA game, or select "Cancel" to indicate the image is not of an active NBA game. You can also trigger a classification manually by typing c, and again, clicking the image at the bottom of the page.

Once you have collected the data you'd like, type ctrl + s to download the data. Then, reload the page, but append the url parameter train=1 (or if you're using the manual upload process, reload the page and only upload the data file, and then type t). This will initiate training of a new model based on this data. Make sure the window is in view in order for the training to progress. Once complete, the newly trained model files will be downloaded.

Video Delay

If the video stream is delayed, you should hear a beeping sound while it's muted in the background (it may be helpful to refresh the page in this case).

Screen Capture

If the video is streamed from a cross-origin iframe, the default setup may not work. At the top of script.js set shouldCaptureScreen = true, and when prompted, select the chrome tab you are streaming from. For best results, put the video player into fullscreen.

Hotkeys

f - Puts the video into fullscreen (see the handleKeyDown method of script.js if the document selector does not work for your streaming site).

m - Mutes the video (see the handleKeyDown method of script.js if the document selector does not work for your streaming site).

ctrl + m - "Permanently" mutes the video (the background classification won't run to automatically unmute the video - you can re-enable auto-unmute by just typing m).

y - Adds the currently displayed image on the video stream to the collection of data for the model under 'y' indicating that the image is of an active NBA game.

n - Adds the currently displayed image on the video stream to the collection of data for the model under 'n' indicating that the image is not of an active NBA game.

t - Initiate training of the model with the uploaded data (note that a trained model must not have been uploaded for this command to work).

c - Classify the currently displayed image on the video stream. The image will be appended to the bottom of the page along with its clasification and score.

ctrl + s - Download the model data file.

nba_detector's People

Contributors

ileeds avatar

Watchers

James Cloos avatar  avatar

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.