Article Image
Article Image
View All Posts
read
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi
#GLOBAL SEED #NEURAL NETWORKS #OPERATION-LEVEL SEED #RANDOM SEEDS #TENSORFLOW

This is more of a reminder for myself, but I’m sure it will be useful for someone else.

What do you think the output of this should be?

a = tf.random.shuffle([1,2,3,4,5,6], seed=567436).numpy()
b = tf.random.shuffle([1,2,3,4,5,6], seed=567436).numpy()
a,b

If you were expecting a and b to be the same, you’re in for a nasty surprise.

What you should be doing is:

tf.random.set_seed(123456)
a = tf.random.shuffle([1,2,3,4,5,6], seed=567436).numpy()
tf.random.set_seed(123456)
b = tf.random.shuffle([1,2,3,4,5,6], seed=567436).numpy()
a,b
(array([6, 4, 2, 1, 5, 3], dtype=int32),
 array([6, 4, 2, 1, 5, 3], dtype=int32))

Note the call to tf.random.set_seed() - make sure you do this before each operation.

TensorFlow has two random seeds - of course, this is actually well documented and I should have read the docs first before diving in:

Operations that rely on a random seed actually derive it from two seeds: the global and operation-level seeds. This sets the global seed.

Its interactions with operation-level seeds is as follows:

  1. If neither the global seed nor the operation seed is set: A randomly picked seed is used for this op.
  2. If the graph-level seed is set, but the operation seed is not: The system deterministically picks an operation seed in conjunction with the graph-level seed so that it gets a unique random sequence. Within the same version of TensorFlow and user code, this sequence is deterministic. However across different versions, this sequence might change. If the code depends on particular seeds to work, specify both graph-level and operation-level seeds explicitly.
  3. If the operation seed is set, but the global seed is not set: A default global seed and the specified operation seed are used to determine the random sequence.
  4. If both the global and the operation seed are set: Both seeds are used in conjunction to determine the random sequence.

Now to work out why despite feeding it complete garbage my neural network appeared to train really well…

#GLOBAL SEED #NEURAL NETWORKS #OPERATION-LEVEL SEED #RANDOM SEEDS #TENSORFLOW

Related Posts

Related Videos

TensorFlow Lite With Platform.io and the ESP32 - Master the process of training a TensorFlow Lite model and deploying it on the ESP32 using PlatformIO with this comprehensive tutorial, complete with clear instructions and an informative video.
Browser-Based Augmented Reality Sudoku Solver using TensorFlow and Image Processing - Learn how to build a Sudoku app using browser APIs and modern techniques, including image processing pipeline, TensorFlow-powered neural networks, and OCR to efficiently identify, extract, and solve Sudoku puzzles.
Voice Controlled Robot using the ESP32 and TensorFlow Lite - Master the process of building a voice-controlled robot with ESP32 and TensorFlow Lite, including creating neural networks, generating training data, and implementing firmware codes for a seamlessly programmed robot.
Self Organising LEDs - Discover the power of transforming random LED chaos into eye-catching geometric patterns using the ESP32 camera board, image processing, and WS2811 addressable RGB LEDs. Learn how to create the circuit, design the software, and control the LEDs through a simple web interface.
We weren't really going for speed - but this gets quite fast... - Dive into the world of 3D printing and learn how to overcome challenges, such as open loop mode errors and excessive vibrations, by creatively utilizing leftover proof of concepts.
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
Blog Logo

Chris Greening


Published

> Image

atomic14

A collection of slightly mad projects, instructive/educational videos, and generally interesting stuff. Building projects around the Arduino and ESP32 platforms - we'll be exploring AI, Computer Vision, Audio, 3D Printing - it may get a bit eclectic...

View All Posts