From the course: Computer Vision on the Raspberry Pi 4

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Training CNNs with TensorFlow

Training CNNs with TensorFlow

- [Instructor] Training a CNN requires a lot of processing, so this video explains how to train CNNs on a PC. OpenCV doesn't have functions for creating and training CNNs, so I'll install TensorFlow with the command pip3 install tensorflow. This can take some time, but in my case, the package is already present so I'll launch thonny. To begin, I'll set the number of classes that the network should recognize. There's one class for each toy car and one class for no cars. Next, I'll load images and labels by calling the load_data function. This accepts the directory containing training files and the number of classes. To create the neural network, I'll set model equal to models.Sequential. For the first convolution layer, I'll call model.add with layers.Conv2D. I'll set the number of kernels to 16, the size of each kernel to 3,3, the activation function to relu, and the input_shape to the shape of the first image.…

Contents