Giter VIP home page Giter VIP logo

poker_ml's Introduction

Poker ML

This was my 2020 winter break project.
Primary objectives: refresh my memory of ML, and get a bit better with Rust, as well as have some fun playing poker texas hold'em. It might be a good project for someone to start with and expand on it.
Everything is tested on Ingition Casino web poker interface. I used web interface and that particular online casino because I use linux, and none of them have clients for linux.

Disclaimer: project is named poker_ml, implying that there is some sort of machine learning applied to poker game, but in reality ML is used only for card recognition.

This project consists of several sub-projects.

Hand Ranker

This was taken from this github project
I only used scores.py part of it to categorize different hands. Also had to fix some bugs in it as well, as some hands were not categorized correctly.
When running scores.py it will generate hands.csv file that contains all 2.6 million hand combinations that can be made with 52 card deck in texas hold'em. This file is then used in expected_value sub project.

Card Recognizer ML

This is a simple CNN machine learning project.
It is trained to recognize cards and dealer button. All train and validate data included.

OCR

This uses tesseract to convert pot value into a string that can be used later on. It is also used to convert call amount into string as well.
It works remarkably well after a bit of fine tuning.

Expected Value

This is the main part of the project. It takes input from card recognizer and ocr to get a state of current game. And then it outputs some data that can be useful during the game.
Pre flop: It will output information about average equity of your starting hands, as well as it will take your position on the table and will tell you if your cards are playable in that position or if they should be folded. Playable card ranges are hard coded currently.
Post flop: It will tell your current hand's equity (how it compares in strength to possible range of opponent's hands), as well as based on equity will calculate your EV of raising or calling. Also if you have a drawing hand, it will show odds of completing your draw.
It will also show possible hands that your opponent might have as well as a probability of having those hands.

Orchestrator

This takes pixel coordinates of all relevant cards (currently hard coded).
Takes screenshots of those areas 10 times a second.
If it detects a change, it runs those screenshots through card recognizer and ocr, and passes that data into expected_value program, which then spits out valuable information for you to act upon.
It runs really fast on my machine. Once cards are dealt, I get results back in less then a second.

Requirements

Everything is tested on Ubuntu 20.04.
You need nVidia GPU to run ML (it is possible to run without GPU but you will need to tweak docker image used for tensorflow to use base image without GPU support I think).
You need docker installed to run docker images.
You need Python3 and Rust installed.

How to use

If you want to give this project a try (and maybe even expand on it)

  1. Create an account on Ignition Casino
  2. Use their web interface to play poker. Only texas hold'em is supported in this project.
  3. Run hand_ranker/scores.py to generate hands.csv file. Copy that file into expected_value/data/hands.csv.
  4. There are some hard coded paths at the top of main() function in expected_value/src/main.rs. Update them to match your environment.
  5. Run cargo build --release in expected_value to compile rust project.
  6. Run expected_value executable to generate all necessary data (that might take a minute or two). It will save all data, so that next run will be fast.
  7. Run make image in card_recognizer_ml to create docker image for that project.
  8. Run make image in ocr to create docker image.
  9. Run make run in the root folder of the project. It should start two containers and should start scanning for changes.
  10. ...
  11. Profit!

Screenshots

Pre-flop example:

Post-flop example:

poker_ml's People

Contributors

sagor999 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

heisk3478

poker_ml's Issues

Card Recognizer ML Errors

Detected change
2023-11-17 21:11:45.936936: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
2023-11-17 21:11:45.936965: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
2023-11-17 21:11:45.937662: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
Touched trigger. Waiting for ML
2023-11-17 21:11:47.150733: W tensorflow/core/common_runtime/gpu/gpu_device.cc:2256] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
ML output:  
OCR:  Total pot: 208.94
Main pot: 200.94

----------------------------------

Above is the output of running make run.

Never reads the cards sent to it just gets stuck like this forever.
Anyone can point me in right direction?

Here is how the input looks.

1
2

Nvidia gpu have the drivers verified, verified Tensorflow[and-cude] are installed

Hard coded paths in main.rs

Hey, it seems that you forgot to say that there is another hard coded path besides the ones at the top of main( ). It is the first line of fn generate_ml_data( ) line 1326.

Missing files

In poker_ml/expected_value/src/main.rs

There are paths to files that don't exist with one such example: combinations.bin in
let combinations_path: String = "/home/pavel/nvme/GitHub/poker_ml/expected_value/data/combinations.bin".to_string();

When running ./poker_ev there is then an error that says cannot find file and directory

Maybe these were files that you meant to include in your project?

ImportError: ImageGrab is macOS and Windows only

from PIL import Image, ImageGrab, ImageChops, ImageOps

When I do make run in the root folder, I get this issue:

python3 orchestrator/main.py Traceback (most recent call last): File "orchestrator/main.py", line 1, in <module> from PIL import Image, ImageGrab, ImageChops, ImageOps File "/usr/lib/python3/dist-packages/PIL/ImageGrab.py", line 26, in <module> raise ImportError("ImageGrab is macOS and Windows only") ImportError: ImageGrab is macOS and Windows only make: *** [Makefile:5: run] Error 1

Is this meant to be ran in Windows/macOS terminals after creating all the files in Linux?

Makefile has hardcoded paths

docker run --name card_ml --runtime=nvidia -t -d -v $$(pwd)/data:/data -v $$(pwd):/src --rm paveltumik/tf-gpu:latest bash

I'm not too familiar with docker, but it seems there are hardcoded paths here... Any tips on how I would change it to my machine?

  1. Is tf-gpu a directory where tensorflow is installed?

  2. Also what is $$(pwd)/data:/data -v $$(pwd):/src

  3. I have nvidia gpu with nvidia graphics driver installed, but do I need anything to make sure --runtime=nvidia works?

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.