Keras to TFJS - Unknown layer: TFOpLambda


I’m new to ML and I’m trying to get keypoint detection working in the browser. I found this Keras tutorial:

I got it working in Python, and then added a line to export it to .h5:'keypoint.h5')

I then converted it to tfjs:
tensorflowjs_converter --input_format=keras /keypoint.h5 /tfjs_model

However when I try and run it in the browser like so:
const model = await tf.loadLayersModel(‘path/to/model.json’);

I get the following error:
Error: Unknown layer: TFOpLambda

Looking inside model.json I can see the following Lambda layers:

{"class_name": "TFOpLambda", "config": {"name": "tf.math.truediv_1", "trainable": true, "dtype": "float32", "function": "math.truediv"}, "name": "tf.math.truediv_1", "inbound_nodes": [["input_4", 0, 0, {"y": 127.5, "name": null}]]}, 
{"class_name": "TFOpLambda", "config": {"name": "tf.math.subtract_1", "trainable": true, "dtype": "float32", "function": "math.subtract"}, "name": "tf.math.subtract_1", "inbound_nodes": [["tf.math.truediv_1", 0, 0, {"y": 1.0, "name": null}]]}

I’ve read that I need to create a custom layer, but this is where I’m completely stumped. How do I go about this? This is well beyond my current understanding but I’m keen to learn - any help appreciated.


Maybe @lina128 or @pyu can shed some light here.