TensorFlow tricks I wish I knew earlier

Manpreet Singh
2 min readOct 4, 2021

Welcome back! TensorFlow is an awesome machine learning package developed by Google, if you don’t know anything about this package, check out the link below to learn more about it:

Now, let’s talk about a few TensorFlow tricks that I wish I had known earlier.

Loading Data In a Single Tensor

If you’re importing datasets that are smaller in size, meaning, they can fit inside your system memory, you can actually load them inside of a single tensor. In order to do this, we want to use batch_size = 1, then we can use tfds.as_numpy:

(img_train, label_train), (img_test, label_test) = tfds.as_numpy(tfds.load(
'mnist',
split=['train', 'test'],
batch_size=-1,
as_supervised=True,
))

Fast Image Decoding

Another way to speed up your TensorFlow is by using a faster image decoder, to do this, we can skip using tfds.decode.SkipDecoding, we can instead use tf.io.decode_image.

TensorBoard

--

--

Manpreet Singh
Manpreet Singh

No responses yet