Simple convolutional neural network to predict handwritten digits using Keras + CoreML built for WWDC '18 scholarship submission [Accepted]
“A convolutional neural network is a class of deep, feed-forward artificial neural networks that have successfully been applied to analyzing visual imagery.
They were inspired by biological processes in that the connectivity pattern between neurons resembles the organization of the animal visual cortex. Individual cortical neurons respond to stimuli only in a restricted region of the visual field known as the receptive field. The receptive fields of different neurons partially overlap such that they cover the entire visual field.”
☝️ From Wikipedia
☝️ Watch the full video on YouTube by Denis Dmitriev
The MNIST database is arguably the most famous database in the field of machine learning; it is a large database of 28x28 pixel images of handwritten digits created in 1999 by Yann LeCun.
Our model consists of 12 layers:
- Input (28x28 pixel image)
- Conv2D (Relu activation)
- MaxPooling2D
- Conv2D (Relu activation)
- MaxPooling2D
- Conv2D (Relu activation)
- MaxPooling2D
- Dropout (0.3)
- Flatten
- Dense
- Dropout (0.4)
- Dense (Softmax activation)
Run the MNIST+CoreML.playground on Xcode 9.0+ or Swift Playground app on the iPad
Make sure disable Enable Results
before running
The model was created and trained using Keras (a high-level neural networks API, written in Python)
☝️ Run the Jupyter notebook to train the network on your own device 💯
Core ML is a framework introduced by Apple at WWDC '17 to integrate machine learning models into iOS, tvOS, macOS and watchOS apps.
The coremltools python package makes it very easy to generate the .mlmodel file, then all you need to do is just drag and drop that file into your Xcode project and you're all set 😎
- The model was inspired by mnist_cnn.py by Keras.
- Udacity for their awesome Deep Learning Nanodegree course.
- Sasmito Adibowo for his blog post on how to add
.mlmodel
files to Swift Playground.
Your feedback is always appreciated and welcomed. If you find a bug in the source code, you can help me by submitting an issue. Even better you can submit a Pull Request with a fix :)
This project is released under the MIT License