streaming machine learning pipeline with apache beam - google-cloud-platform

I'm using Beam to build a streaming ML pipeline that's very similar to Zeitgeist system mentioned in the original MillWheel paper. However, I'm have difficulty in using trained models to do online predictions (the blue vertical arrow "Models" in Figure 1. of the paper).
It seems that Zeitgeist models are updated incrementally each time (?) when a new windowed counter comes in. However, the specific model I'm using doesn't support incremental/online training, so I need to use some trigger/windowing to train the model in batches.
During prediction, I don't know how to align windows of features and batch-trained models.
using side input (see below) can make the pipeline run, but it stucks at the prediction step waiting for the model to be materialized.
CoGroupByKey does not work because the windows of features and ensembledModels are not the same.
I also want to do model ensemble, which makes things even more complicated.
Here's a rough sketch of what I have
// Correspond to "Window Counter" in MillWheel paper
final PCollection<Feature> features = pipeline
.apply(PubsubIO.read(...))
.apply(...some windowing...)
.apply(ParDo.of(new FeatureExtractor()));
// Correspond to "Model Calculator" in MillWheel paper
final PCollection<Iterable<Model>> ensembledModels = features
.apply(...some windowing and data triggers...)
.apply(new ModelTrainer()));
// Correspond to "Spike/Dip Detector" in MillWheel paper
// The pipeline stucks at here when run
final PCollection<Score> score = features
.apply(ParDo.of(new Predictor()).withSideInput(ensembledModels));

Related

Phantom Omni angular velocities are 0

I'm trying to build my application using the Phantom Omni haptic device and in order to get the angular velocity of the device, I'm using a function from its library (OpenHaptics):
hdGetDoublev(HD_CURRENT_ANGULAR_VELOCITY, ang_vel);
but it returns [0,0,0]. I'm using the same function to get the linear velocity:
hdGetDoublev(HD_CURRENT_VELOCITY, lin_vel);
and it's working fine. (Both lin_vel and ang_vel are defined as hduVector3Dd)
What am I missing?
I asked directly to Open Haptics support and this was the answer: "This is not a bug, HD_CURRENT_ANGULAR_VELOCITY doesn't apply to Touch/Omni model, because its gimbal encoder wouldn't be sufficient for accurate angular velocity calculation".
I hope it can save you some time.

Pytorch Lightning Tensorboard Logger Across Multiple Models

I'm relatively new to Lightning and Loggers vs manually tracking metrics. I am trying to train two distinct models and have their accuracy and loss plotted on the same charts in tensorboard (or any other logger) within Colab.
What I have right now is basically:
trainer1 = pl.Trainer(gpus=n_gpus, max_epochs=n_epochs, progress_bar_refresh_rate=20, num_sanity_val_steps=0)
trainer2 = pl.Trainer(gpus=n_gpus, max_epochs=n_epochs, progress_bar_refresh_rate=20, num_sanity_val_steps=0)
trainer1.fit(Model1, train_loader, val_loader)
trainer2.fit(Model2, train_loader, val_loader)
#Then later:
%load_ext tensorboard
%tensorboard --logdir lightning_logs/
What I'd like to see at this point are those logged metrics charted together on the same chart, any help would be appreciated. I've spent some time trying to toy with this but I'm a bit out of my depth on this, thank you!
The exact chart used for logging a specific metric depends on the key name you provide in the .log() call (its a feature that Lightning inherits from TensorBoard itself)
def validation_step(self, batch, _):
# This string decides which chart to use in the TB web interface
# vvvvvvvvv
self.log('valid_acc', acc)
Just use the same string for both .log() calls and have both runs saved in same directory.
logger = TensorBoardLogger(save_dir='lightning_logs/', name='model1')
logger = TensorBoardLogger(save_dir='lightning_logs/', name='model2')
If you run tesnsorboard --logdir ./lightning_logs pointing at the parent directory, you should be able to see both metric in the same chart with the key named valid_acc.

How can I track eye movements with Google Video Intelligence API?

I have a video with 3 persons speaking and I would like to annotate the location of people's eyes during it. I know that the Google Video Intelligence API has functionalities for object tracking, but it's possible to handle such an eye-tracking process using the API?
Google Video Intelligence API represents Face detection feature, which gives you opportunity to perform face detection from within video frames as well as special face attributes.
In general, you need to adjust FaceDetectionConfig throughout videos.annotate method, supplying includeBoundingBoxes and includeAttributes arguments in JSON request body:
{
"inputUri":"string",
"inputContent":"string",
"features":[
"FACE_DETECTION"
],
"videoContext":{
"segments":[
"object (VideoSegment)"
],
"faceDetectionConfig":{
"model":"string",
"includeBoundingBoxes":"true",
"includeAttributes":"true"
}
},
"outputUri":"string",
"locationId":"string"
}
There is a detailed (Python) example from Google on how to track objects and print out detected objects afterward. You could combine this with the AIStreamer live object tracking feature, to which you can upload a live video stream to get results back.
Some ideas/steps you could follow:
Recognize the eyes in the first frame of the video.
Set/highlight a box around the eyes you are tracking.
Track the eyes as an object in the next frames.

Update Dataflow Streaming job with Session and Siding window embedded in DF

In my use-case, I'm performing Session as well as Sliding window inside Dataflow job. So basically my Sliding window timing is 10 hour with sliding time 4 min. Since I'm applying grouping and performing max function on top of that, on every 3 min interval, window will fire the pane and it will go into Session window with triggering logic on it. Below is the code for the same.
Window<Map<String, String>> windowMap = Window.<Map<String, String>>into(
SlidingWindows.of(Duration.standardHours(10)).every(Duration.standardMinutes(4)));
Window<Map<String, String>> windowSession = Window
.<Map<String, String>>into(Sessions.withGapDuration(Duration.standardHours(10))).discardingFiredPanes()
.triggering(Repeatedly
.forever(AfterProcessingTime.pastFirstElementInPane().plusDelayOf(Duration.standardSeconds(5))))
.withAllowedLateness(Duration.standardSeconds(10));
I would like to add logger on some steps for Debugging, so I'm trying to update the current streaming job using below code:
options.setRegion("asia-east1");
options.setUpdate(true);
options.setStreaming(true);
So previously I had around 10k data and I updated the existing pipeline using above config and now I'm not able to see that much data in steps of updated DF job. So help me with the understanding whether it preserves the previous job data or not as I'm not seeing previous DF step count in updated Job.

Tensorflow, missing checkpoint files. Does saver only allow for keeping 5 check points?

I am working with tensorflow and have been training some models and saving them after each epoch using the tf.saver() method. I am able to save and load models just fine and I am doing this in the usual way.
with tf.Graph().as_default(), tf.Session() as session:
initialiser = tf.random_normal_initializer(config.mean, config.std)
with tf.variable_scope("model",reuse=None, initializer=initialiser):
m = a2p(session, config, training=True)
saver = tf.train.Saver()
ckpt = tf.train.get_checkpoint_state(model_dir)
if ckpt and tf.gfile.Exists(ckpt.model_checkpoint_path)
saver.restore(session, ckpt.model_checkpoint_path)
...
for i in range(epochs):
runepoch()
save_path = saver.save(session, '%s.ckpt'%i)
My code is set up to save a model for each epoch which should be labelled accordingly. However, I have noticed that after fifteen epochs of training I only have check point files for the last five epochs (10, 11, 12, 13,14). The documentation doesn't say anything about this so I am at a loss as to why it is happening.
Does the saver only allow for keeping five checkpoints or have I done something wrong?
Is there a way to make sure that all of the checkpoints are kept?
You can choose how many checkpoints to save when you create your Saver object by setting the max_to_keep argument which defaults to 5.
saver = tf.train.Saver(max_to_keep=10000)
setting max_to_keep=None actually makes the Saver keep all checkpoints.
For eg.,
saver = tf.train.Saver(max_to_keep=None)