concrete function
Better performance with tf.function
If you would like to execute Python code during each invocation of a Function, tf.py_function is an exit hatch. The drawback of tf.py_function is that it's not portable or particularly performant, cannot be saved with SavedModel, and does not work well in distributed (multi-GPU, TPU) setups. Also, since tf.py_function has to be wired into the graph, it casts all inputs/outputs to tensors. Changing Python global and free variables counts as a Python side effect, so it only happens during tracing. Sometimes unexpected behaviors are very hard to notice.
Training Keras Models using the Rust TensorFlow Bindings
Rust has become increasingly popular. Its safe execution and super fast runtime, combined with a strong community support, have made it an attractive alternative to languages like C. With little overhead it is possible to run Rust in production on micro-devices and, in the context of Edge Computing, might be a good choice when deploying Neural Networks at Edge. While there are many examples available to use pre-trained TensorFlow models with the Rust bindings or the TensorFlow-C API, there is little or none available on how to actually train models directly in Rust. Therefore in this brief tutorial I will outline a way to do so. For this demonstration we will create a very simple model, that merely receives a tensor with two elements and a single value as a target.