Chess Steps Method Pdf To Jpg
using Neural Networks (SSD) on Tensorflow.
This repo documents steps and scripts used to train a hand detector using Tensorflow (Object Detection API). As with any DNN based task, the most expensive (and riskiest) part of the process has to do with finding or creating the right (annotated) dataset. I was interested mainly in detecting hands on a table (egocentric view point). I experimented first with the Oxford Hands Dataset (the results were not good). I then tried the Egohands Dataset which was a much better fit to my requirements.
Chess-Steps is praised as one of the most innovative chess instructional programs in the world. Princeton Chess Academy is the first chess school in USA that fully adopts the Steps Method as its core curriculum. After years of research, studying many popular manuals and curriculum from Kasparov Chess Foundation, ChessKids.com, Susan Polgar,. Printable copy in.pdf format. It's time for you to take a look at these ten tips to help you learn some simple ways to win more games: Look at your. White to move. Look at this position carefully. What would be a good plan for white? What moves would be involved in carrying out this plan?
The goal of this repo/post is to demonstrate how neural networks can be applied to the (hard) problem of tracking hands (egocentric and other views). Better still, provide code that can be adapted to other uses cases.
If you use this tutorial or models in your research or project, please cite this.
Here is the detector in action.
Realtime detection on video stream from a webcam .
Detection on a Youtube video.
Both examples above were run on a macbook pro CPU (i7, 2.5GHz, 16GB). Some fps numbers are:
FPS | Image Size | Device | Comments |
---|---|---|---|
21 | 320 * 240 | Macbook pro (i7, 2.5GHz, 16GB) | Run without visualizing results |
16 | 320 * 240 | Macbook pro (i7, 2.5GHz, 16GB) | Run while visualizing results (image above) |
11 | 640 * 480 | Macbook pro (i7, 2.5GHz, 16GB) | Run while visualizing results (image above) |
Note: The code in this repo is written and tested with Tensorflow 1.4.0-rc0
. Using a different version may result in some errors.You may need to generate your own frozen model graph using the model checkpoints in the repo to fit your TF version.
Content of this document
- Motivation - Why Track/Detect hands with Neural Networks
- Data preparation and network training in Tensorflow (Dataset, Import, Training)
- Training the hand detection Model
- Using the Detector to Detect/Track hands
- Thoughts on Optimizations.
P.S if you are using or have used the models provided here, feel free to reach out on twitter (@vykthur) and share your work!
Motivation - Why Track/Detect hands with Neural Networks?
There are several existing approaches to tracking hands in the computer vision domain. Incidentally, many of these approaches are rule based (e.g extracting background based on texture and boundary features, distinguishing between hands and background using color histograms and HOG classifiers,) making them not very robust. For example, these algorithms might get confused if the background is unusual or in situations where sharp changes in lighting conditions cause sharp changes in skin color or the tracked object becomes occluded.(see here for a review paper on hand pose estimation from the HCI perspective)
With sufficiently large datasets, neural networks provide opportunity to train models that perform well and address challenges of existing object tracking/detection algorithms - varied/poor lighting, noisy environments, diverse viewpoints and even occlusion. The main drawbacks to usage for real-time tracking/detection is that they can be complex, are relatively slow compared to tracking-only algorithms and it can be quite expensive to assemble a good dataset. But things are changing with advances in fast neural networks.
Furthermore, this entire area of work has been made more approachable by deep learning frameworks (such as the tensorflow object detection api) that simplify the process of training a model for custom object detection. More importantly, the advent of fast neural network models like ssd, faster r-cnn, rfcn (see here ) etc make neural networks an attractive candidate for real-time detection (and tracking) applications. Hopefully, this repo demonstrates this.
If you are not interested in the process of training the detector, you can skip straight to applying the pretrained model I provide in detecting hands.
Training a model is a multi-stage process (assembling dataset, cleaning, splitting into training/test partitions and generating an inference graph). While I lightly touch on the details of these parts, there are a few other tutorials cover training a custom object detector using the tensorflow object detection api in more detail[ see here and here ]. I recommend you walk through those if interested in training a custom object detector from scratch.
Data preparation and network training in Tensorflow (Dataset, Import, Training)
The Egohands Dataset
The hand detector model is built using data from the Egohands Dataset dataset. This dataset works well for several reasons. It contains high quality, pixel level annotations (>15000 ground truth labels) where hands are located across 4800 images. All images are captured from an egocentric view (Google glass) across 48 different environments (indoor, outdoor) and activities (playing cards, chess, jenga, solving puzzles etc).
If you will be using the Egohands dataset, you can cite them as follows:
Bambach, Sven, et al. 'Lending a hand: Detecting hands and recognizing activities in complex egocentric interactions.' Proceedings of the IEEE International Conference on Computer Vision. 2015.
The Egohands dataset (zip file with labelled data) contains 48 folders of locations where video data was collected (100 images per folder).
Converting data to Tensorflow Format
Some initial work needs to be done to the Egohands dataset to transform it into the format (tfrecord
) which Tensorflow needs to train a model. This repo contains egohands_dataset_clean.py
a script that will help you generate these csv files.
- Downloads the egohands datasets
- Renames all files to include their directory names to ensure each filename is unique
- Splits the dataset into train (80%), test (10%) and eval (10%) folders.
- Reads in
polygons.mat
for each folder, generates bounding boxes and visualizes them to ensure correctness (see image above). - Once the script is done running, you should have an images folder containing three folders - train, test and eval. Each of these folders should also contain a csv label document each -
train_labels.csv
,test_labels.csv
that can be used to generatetfrecords
Note: While the egohands dataset provides four separate labels for hands (own left, own right, other left, and other right), for my purpose, I am only interested in the general hand
class and label all training data as hand
. You can modify the data prep script to generate tfrecords
that support 4 labels.
Next: convert your dataset + csv files to tfrecords. A helpful guide on this can be found here.For each folder, you should be able to generate train.record
, test.record
required in the training process.
Training the hand detection Model
Now that the dataset has been assembled (and your tfrecords), the next task is to train a model based on this. With neural networks, it is possible to use a process called transfer learning to shorten the amount of time needed to train the entire model. This means we can take an existing model (that has been trained well on a related domain (here image classification) and retrain its final layer(s) to detect hands for us. Sweet!. Given that neural networks sometimes have thousands or millions of parameters that can take weeks or months to train, transfer learning helps shorten training time to possibly hours. Tensorflow does offer a few models (in the tensorflow model zoo) and I chose to use the ssd_mobilenet_v1_coco
model as my start point given it is currently (one of) the fastest models (read the SSD research paper here). The training process can be done locally on your CPU machine which may take a while or better on a (cloud) GPU machine (which is what I did). For reference, training on my macbook pro (tensorflow compiled from source to take advantage of the mac's cpu architecture) the maximum speed I got was 5 seconds per step as opposed to the ~0.5 seconds per step I got with a GPU. For reference it would take about 12 days to run 200k steps on my mac (i7, 2.5GHz, 16GB) compared to ~5hrs on a GPU.
Training on your own images: Please use the guide provided by Harrison from pythonprogramming on how to generate tfrecords given your label csv files and your images. The guide also covers how to start the training process if training locally. [see [here] (https://pythonprogramming.net/training-custom-objects-tensorflow-object-detection-api-tutorial/)]. If training in the cloud using a service like GCP, see the guide here.
As the training process progresses, the expectation is that total loss (errors) gets reduced to its possible minimum (about a value of 1 or thereabout). By observing the tensorboard graphs for total loss(see image below), it should be possible to get an idea of when the training process is complete (total loss does not decrease with further iterations/steps). I ran my training job for 200k steps (took about 5 hours) and stopped at a total Loss (errors) value of 2.575.(In retrospect, I could have stopped the training at about 50k steps and gotten a similar total loss value). With tensorflow, you can also run an evaluation concurrently that assesses your model to see how well it performs on the test data. A commonly used metric for performance is mean average precision (mAP) which is single number used to summarize the area under the precision-recall curve. mAP is a measure of how well the model generates a bounding box that has at least a 50% overlap with the ground truth bounding box in our test dataset. For the hand detector trained here, the mAP value was 0.9686@0.5IOU. mAP values range from 0-1, the higher the better.
Once training is completed, the trained inference graph (frozen_inference_graph.pb
) is then exported (see the earlier referenced guides for how to do this) and saved in the hand_inference_graph
folder. Now its time to do some interesting detection.
Using the Detector to Detect/Track hands
If you have not done this yet, please following the guide on installing Tensorflow and the Tensorflow object detection api. This will walk you through setting up the tensorflow framework, cloning the tensorflow github repo and a guide on
- Load the
frozen_inference_graph.pb
trained on the hands dataset as well as the corresponding label map. In this repo, this is done in theutils/detector_utils.py
script by theload_inference_graph
method. - Detect hands. In this repo, this is done in the
utils/detector_utils.py
script by thedetect_objects
method. - Visualize detected bounding detection_boxes. In this repo, this is done in the
utils/detector_utils.py
script by thedraw_box_on_image
method.
This repo contains two scripts that tie all these steps together.
- detect_multi_threaded.py : A threaded implementation for reading camera video input detection and detecting. Takes a set of command line flags to set parameters such as
--display
(visualize detections), image parameters--width
and--height
, videe--source
(0 for camera) etc. - detect_single_threaded.py : Same as above, but single threaded. This script works for video files by setting the video source parameter videe
--source
(path to a video file).
Update: If you do have errors loading the frozen inference graph in this repo, feel free to generate a new graph that fits your TF version from the model-checkpoint in this repo.Use the export_inference_graph.py script provided in the tensorflow object detection api repo.More guidance on this here.
Thoughts on Optimization.
A few things that led to noticeable performance increases.
- Threading: Turns out that reading images from a webcam is a heavy I/O event and if run on the main application thread can slow down the program. I implemented some good ideas from Adrian Rosebuck on parrallelizing image capture across multiple worker threads. This mostly led to an FPS increase of about 5 points.
- For those new to Opencv, images from the
cv2.read()
method return images in BGR format. Ensure you convert to RGB before detection (accuracy will be much reduced if you dont).
Keeping your input image small will increase fps without any significant accuracy drop.(I used about 320 x 240 compared to the 1280 x 720 which my webcam provides).
Model Quantization. Moving from the current 32 bit to 8 bit can achieve up to 4x reduction in memory required to load and store models. One way to further speed up this model is to explore the use of 8-bit fixed point quantization.
Performance can also be increased by a clever combination of tracking algorithms with the already decent detection and this is something I am still experimenting with. Have ideas for optimizing better, please share!
Note: The detector does reflect some limitations associated with the training set. This includes non-egocentric viewpoints, very noisy backgrounds (e.g in a sea of hands) and sometimes skin tone. There is opportunity to improve these with additional data.Integrating Multiple DNNs.
One way to make things more interesting is to integrate our new knowledge of where 'hands' are with other detectors trained to recognize other objects. Unfortunately, while our hand detector can in fact detect hands, it cannot detect other objects (a factor or how it is trained). To create a detector that classifies multiple different objects would mean a long involved process of assembling datasets for each class and a lengthy training process.
Given the above, a potential strategy is to explore structures that allow us efficiently interleave output form multiple pretrained models for various object classes and have them detect multiple objects on a single image.
An example of this is with my primary use case where I am interested in understanding the position of objects on a table with respect to hands on same table. I am currently doing some work on a threaded application that loads multiple detectors and outputs bounding boxes on a single image. More on this soon.
Acknowledgements
This work also served as an intense weekend crash course for me to learn Python and Tensorflow. It would be impossible without the Egohands Dataset, many thanks to the authors! The tensorflow custom object detection guides by Harrison from pythonprogramming and Dat Tran were immensely helpful to this learning process. And ofcourse, many thanks to the Tensorflow authors! Its a great frameworks!
If you have created something cool, send me a note (or tweet) and I'll be happy to include it here!
Citing this tutorial
If you'd like to cite this work, use the below.
Victor Dibia, Real-time Hand-Detection using Neural Networks (SSD) on Tensorflow, (2017), GitHub repository, https://github.com/victordibia/handtracking
Unless you have amazing powers of visualization, chess requires a chess set and a board for you to play on. The chessboard is divided up into sections called ranks and files, and the set is composed of different chessmen with different movements and powers. After you understand all of these topics, you can start playing the great game of chess, with checkmate as your goal.
Setting Up Your Chessboard
Setting up your chessboard is the first step in playing a game of chess. Take your time setting up the board, until you’re confident that you know where everything goes:
The rooks go on the corner squares.
Place the knights next to the rooks.
Put the bishops on the board next to the knights.
After the bishops come the queens. The queens always start on the square of the same shade — the white queen starts on a light square, and the black queen starts on a dark square.
Place the kings next to the queens, which is only fitting.
Add the pawns straight across the rank in front of the other pieces.
Naming Ranks and Files in Chess
The chessboard is divided into ranks (numbers) and files (letters). There are eight of each, and each is comprised of eight squares of equal size:
Learning Chess Step 6 Pdf
Ranks are rows that go from side to side across the chessboard and are referred to by numbers. Each chessboard has eight ranks, which are numbered from the bottom of the board (where the white pieces start) on up.
Files are columns that go up and down the chessboard, and each board has eight of them. Because numbers indicate ranks, letters indicate files, which are labeled from left to right.
The naming conventions for ranks and files allows you to give an identifier to every square by using what chess people call the file-first method. For example, the lower right-hand square is called h1. This name is shorthand for h-file, first rank.
Knowing the Moves that Chess Pieces Can Make
Before you can play a game of chess, you need to know how to move the pieces (legally). A chess piece’s power is tied to its mobility. The more mobile a piece is, the more powerful it is:
Pawns: Pawns can only move forward. On their first move, they can move one or two squares. Afterwards, they can move only one square at a time. They can capture an enemy piece by moving one square forward diagonally.
Bishops: Bishops can move any number of squares diagonally.
Knights: Knights can move only in an L-shape, one square up and two over, or two squares over and one down, or any such combination of one-two or two-one movements in any direction.
Rooks: Rooks can move any number of squares, up and down and side to side.
Queens: Queens can move any number of squares along ranks, files and diagonals.
Kings: Kings can move one square at a time in any direction.
Understanding Check, Checkmate, and Stalemate in Chess
In chess, check is an attack on an enemy king; this attack can’t be ignored. If the check can’t be neutralized, it is checkmate and the game is over. Stalemate occurs when one player has no legal moves, but his king isn’t in check. Here are a few additional details on check, checkmate, and stalemate in chess:
Chess Steps Method
Check: An attack on a king by either an opposing piece or an opposing pawn is called check. When in check, a player must do one of the following:
Move the king so that it’s no longer under attack.
Block the attack by interposing a piece between the king and the attacker.
Capture the attacking piece.
Checkmate: When a king is in check and can’t perform any of the preceding moves, it has been checkmated. If your king is checkmated, you lose the game. The term checkmate is commonly shortened to simply mate.
Stalemate:Stalemate is the relatively rare situation when a player whose king isn’t in check has no legal move to make. Stalemate is considered a draw. Neither player wins, but the game is over.