Abstract
I made a prototype program to classify images using Keras and OpenCV. You can determine the outcome of the backgammon precision dice. The accuracy is also reasonable.
Backgammon dice recognition with Keras https://t.co/XO8vibXdBy via @YouTube
— Masahiro Kisono (@mkisono) July 16, 2016
Related work
I made the same thing last year. At that time, it was Caffe + OpenCV.
It worked reasonably well, but I soon got tired of it because Caffe was difficult and it became troublesome to write in C ++. However, the same learning data was used this time. In a sense, the task of creating learning data is the most difficult, so this time it was the job that I got on my shoulder last year.
I used the model of CIFAR10 sample. To load training and validation data from an image file, here It is easy to use ImageDataGenerator.flow_from_directory () as shown in.
Let's classify the images using the completed model. If you want to read and classify JPEG files, you can use the code from the blog above.
img = load_img('data/train/cats/cat.0.jpg') # this is a PIL image
x = img_to_array(img) # this is a Numpy array with shape (3, 150, 150)
x = x.reshape((1,) + x.shape) # this is a Numpy array with shape (1, 3, 150, 150)
x /= 255
You can call model.predict () with this x as an argument.
However, it took some time to use OpenCV format data. The image data of OpenCV was already an array of numpy, but since the color order is BGR, it needs to be converted to RGB. In addition, I will go to the array to match the shape.
x = cv2.cvtColor(img, cv2.COLOR_BGR2RGB).astype(np.float32)
x = x.transpose((2, 0, 1))
x = x.reshape((1,) + x.shape)
x /= 255
Conclusions
I was frustrated by Caffe, but Keras is quite so. The YouTube video program at the beginning is about 100 lines. I'm really glad I remember Python.
Future work
I'm thinking of trying to recognize backgammon checkers.
Acknowlegements
I referred to the following page.
Recommended Posts