Training an ANN based on MNIST is something you might want to do in future projects as well. To make our code more reusable, we can write a Python module that is solely dedicated to this training process. Then (in the next section, Implementing the main module), we will import this training module into a main module, where we will implement our demonstration of digit detection and classification.
Let's implement the training module in a file called digits_ann.py:
- To begin, we will import the gzip and pickle modules from the Python standard library. As usual, we will also import OpenCV and NumPy:
import gzipimport pickleimport cv2import numpy as np
We will use the gzip and pickle modules to decompress ...