Data Access
Here is where we house libraries that handle the reading and writing of data. For now we are merely just reading from jpeg files. However, we will moved onto support for networking interfaces.
Python Bindings
Although this library is written in Rust we have the ability to use it in Python. This is done by using the pyo3
crate. We can install
the library using a pip install
and pointing to the directory of this readme file. Once the library is installed we can use it in the
following way:
= 480
= 853
=
Image Loading
This library handles the reading of jpeg files. It is a simple library that is used to read in the jpeg files and convert them
to a stream of bytes. The loading and conversion of the jpeg files is done in the data_access/basic/src/images.rs
.
For our images we are handling data in the following outline:
Here we can see that we have three layers of a frame. Each layer of the Z
axis corresponds to the RGB values of the
pixel in the X, Y
coordinate. We package the image frame as a 1D
array of u8
values. The u8
values and calculate
the index of the pixel in the 1D
array with the following formula example where the maximum width is 10
, the maximum
height is 5
, and there are 3
layers for the RGB values:
() ) => ()
Here we can see that we can map the X, Y, Z
coordinates to the 1D
array. To see the sequence of this mapping we can
look at the following testing code:
We can see that our mapping function follows the exact same pattern as the reshape function that numpy
has and this
can be seen in the file engines/pytorch_train/tests/test_numpy_quality_control.py
.
Networking
If you just want to use the raw rust binary for ML training, you can directly call the rust binary that loads the images, and pipe this data into the python pytorch engine as seen in the following example:
|
This means we can chunk the data into the stream and thus the ML model to be trained further. We are doing this to
give users flexibility on the size of the RAM memory needed to train the model. For instance, if the user has a
60GB
folder of images, it is unlikely that they will be able to load all of these images into memory at once
as depicted in the following:
)
This also gives us a lot of flexibility in the future. For instance, if we need to send the training data over
a network we can easily swap out the std::io::stdin
with a networking layer like the following:
)
We can use the Command
in a program to coordinate pipes over multiple cores and manage the flow of data.
We can also pipe in the ffmpeg
command as seen in the following example:
| |
We can map this with the following Rust code:
use ;
Local Test Setup for FFmpeg
SRT listener server in OBS Studio
At this stage, we do not have steady access to Panasonic AW-UE150 cameras. Hence, for initial testing purposes, we set up a Secure Reliable Transport (SRT) listener server using OBS Studio. The server URL is
srt://127.0.0.1:9999?mode=listener&timeout=500000&transtype=live
- '127.0.0.1': IP address of the listener server
- '9999': Port of the listener server
- 'timeout=500000': The listener server waits for connection for 500 s before auto-abort
- 'transtype=live': Optimised for live streaming
Output resolution is set to 1920 X 1080 with an FPS of 1. The images in the CAMMA-public/cholect50 are sourced as an Image Slide Show.
The listener listens for connection requests from callers. The callers are implemented in srt_receiver.rs
.
Download and Install FFmpeg
Download FFmpeg here. Versions are available for Windows, Linux, and Mac OS.
FFmpeg Documentation
Official documentation of FFmpeg is here.