Perhaps the most important part of this project is the RPi. The reason for this is because the Pi acts as our portable client. So long as the Pi has some network connection, we will be able to continuously send images to the server for processing. This part will go over the install steps required for our setup. For this setup, please have a micro-SD card + adapter on hand along with an SD card reader [or PC capable of reading SD cards].
For those who have worked with a Pi beforehand, you may proceed to flash the Raspbian image on the Pi without reading the following guide on how to do so...
On Windows, the simplest way to flash an image onto an SD card via some GUI program such as Etcher. To start, first install Etcher given the link before in any form (be it portable or via installer). Once you have acquired Etcher, the flash process is as simple as following the GUI program's request for the image, then selecting the device, and then confirming a user's decision to start the flashing process. Note that, at the end of the flashing process, Etcher performs a checksum check to ensure that the image has been flashed properly onto the SD card, so the entire process can take up to 15 minutes depending on the device's interface speed.
On Linux, we can use the dd command in order to handle all of the data copying. One thing to be aware of is that one mistake with dd can render your OS useless so do take care! To start, let us cover the basic syntax of the dd command:
sudo dd if=[INPUT_FILE] of=[OUTPUT_FILE]In the above command, the if represents the input file destination and the of represents the output file destination. In essence, you can treat the dd command as a more complex copy command.
For this process, we would like to set the Raspbian .img file (NOT THE .ZIP FILE!) as the input file and the SD card as the output file. Note that in Linux, all devices can be considered "files" of the form /dev/XXXXXX and can be listed using the lsblk command. Once you have determined the path of the SD card device, the command will look something as follows (replacing rpiIM.img with the Raspbian image file and the /dev/mmcblk1 path with the one you have identified as the SD card on your computer):
sudo dd if=rpiIM.img of=/dev/mmcblk1 bs=1MThe final argument can be replaced with (4M) or (2M) if need be. Copying with (1M) blocks can take up to 10 minutes to complete. Higher values for the block size will incur less overhead (and thus take less time), but the failures rate is generally higher.
Once you have copied the file over, make sure to eject the SD card using any method of your choice.
The steps for OSX are exactly the same as that for the Linux systems. The only difference is the fact that the device must first be unmounted (as the device will automatically be mounted to a mount point) and then the device must be ejected using diskutil. The process is as follows:
diskutil unmountDisk /dev/disk<X>sudo diskutil eject /dev/disk<X>It should be clear that the <X> tag should be replaced with the number corresponding to the device. This can be found by identifying the device through the diskutil list command (the OSX alternative to lsblk).
With the proper Raspbian image flashed onto the RPi, the software required for this project can now be installed. Luckily, students need not worry about the compilation of OpenCV any longer (which used to take a massive two to four hours to compile!). To start, first clone your git repository onto your RPi. After doing so, navigate to the setup/rpi/ directory within the repository and execute the installation script using bash as follows:
chmod u+x install_opencv2.sh./install_opencv2.shInstallation should take a maximum of about 20 minutes. Note that in order for installation to successfully take place, it is required that your RPi be configured to the correct time (you can use the setup.sh script within the same directory to configure ntp after initial time setup!) or you will get errors regarding the expiration of SSL certificates when using apt or pip.
Installation for your local PC is much simpler and results in a far more up-to-date experience as compilations for x86 systems are largely automated at this time. To start, first acquire the conda distribution from here and install it. If you are on Windows, this will take the form of an installer, but on Linux, you will need to execute a bash script in order to install conda. Make sure you install the Python 3 version so your code can run on both your RPi and PC!
With conda installed, the management of Python environments is simple enough. Open up the conda prompt (if using Windows) or any terminal emulator that has access to the conda binaries. We now install the modules that are required for the project:
conda activate baseconda install keras tensorflowpip install flask flask_corsNote that if you are on a Linux distribution, the first line will probably need to be source activate base instead of the line given. The syntax for activating environments is slightly different depending on the way conda installs itself.
If you would like to perform some GPU training on your personal computer for testing, install the tensorflow_gpu package instead of the default tensorflow one. If your GPU is supported (note that some older workstation cards and GPUs may not be supported by the precompiled binaries), then, when initiating the training session, there will be a notice identifying the GPU and reporting the GPU memory allocation. In this case, you will have to compile your own binaries, which should be easy enough to do given the docker environments Google provides (this will not be covered, however!).