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
#CODING TUTORIAL #PYTHON #RANDOM SEED #TENSORFLOW #TFRANDOMSHUFFLE

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…

#CODING TUTORIAL #PYTHON #RANDOM SEED #TENSORFLOW #TFRANDOMSHUFFLE

Related Posts

Related Videos

TensorFlow Lite With Platform.io and the ESP32 - Learn how to train a simple TensorFlow Lite model and run it on the ESP32 using PlatformIO! With clear instructions and a helpful video, this tutorial will have your project up and running in no time.
Build Your Own Voice-Controlled Robot with ESP32 & TensorFlow Lite - Learn how to create a voice-controlled robot using ESP32 and TensorFlow Lite with this step-by-step guide on creating neural networks, generating training data, and implementing firmware codes.
We don't need a DAC - ESP32 PDM Audio - In this video, I've made some fascinating explorations with the ESP32 S3 chips and TinyS3 boards from Unexpected Maker. Intriguingly, even without a DAC converter, S3 chips can produce an audio waveform. I've played around with a basic RC filter to reconstruct the analogue audio signal from a PDM signal. The result was quite impressive for a board without a native DAC! I also discussed the possibility of creating a simple amplifier using just a MOSFET as a switch. Finally, I gave a peek into some of my new boards from PCBWay and looked at how Delta Sigma modulation can be played with to recover original data. It's all quite a fun foray into the world of circuitry and audio signals!
AR Sudoku Solver in Your Browser: TensorFlow & Image Processing Magic - Discover how to recreate a Sudoku app using browser APIs and ecosystem advancements, and explore the image processing pipeline technique for extracting Sudoku puzzles and solving them.
PCB Mistake Turns into Vacuum Stencil Experiment | MHP30 Hotplate Test - Learn how to recover from a mistaken chip order and improve SMD soldering techniques using a mini hotplate and vacuum cleaner stencil holder. Watch the mesmerizing results under the microscope!
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