/Deep-Study

Practice projects. Internet poker card classifier with a CNN in tensorflow (and pytorch) and RuneScape ore segmenter with OpenCV

Primary LanguagePythonMIT LicenseMIT

Deep-Study

Practice projects. Internet poker card classifier with a CNN in tensorflow (and pytorch) and RuneScape ore segmenter with OpenCV

Deep card classifier

Augmented image examples Original image examples

TensorFlow

TensorFlow version is a custom built CNN with layers selected and hyperparameters chosen by intuition and trial/error. Most of the work was put into image preprocessing and training set augmentation.

For some yet unknown reason it usually classifies all other cards successfully except it misclassifies 3c as 6c or vice versa.

Some additional difficulty arises from the fact that the card images are from two completely different poker sites, where for example the card with the value ten, is written T in the other and 10 in the other. But both are classified correctly as T.

The net reaches approx 99.4-99.7% validation set accuracy:

PyTorch

The PyTorch version is transfer-learned by retraining the last layer of 18 layers deep ResNet (resnet18), it only reaches around 80-90% classification accuracy. Probably unfreezing more than the last layer, and possibly having a shallower network might work, since the card images are rather small.

RuneScape ore segmentation

Here it's running live, finding iron ore. It runs at least 30fps on my desktop.

While I initially planned to use deep learning for this, the OpenCV version (that I was originally building just for creating a training set for the deep learning algorithm) was already so good I didn't think there was any point in doing a deep learning version. Got some nice pictures ouf of the OpenCV experiments though:

RGB HSV
The lower right of the HSV graph nicely shows the iron ore colors separated from the other colors:

Segmentation algorithm steps:

  • Only using HSV thresholding to segment the images leaves spots in the ores, and some random individual pixels are found here and there.
  • Using morphological closing, the black spots within the ores disappear:
  • Using morphological erosion with a 2 by 2 kernel gets rid of most of the individual pixels:

After some experiments and trial & error with coal ore, finally adding one additional round of of erosion makes the segmenter work well for both iron and coal ores, with the latter having more 1-2 pixel group noise, since there are a lot of black pixels like the ones found in coal ores in other objects in RuneScape.

Final result: