🌈 ESP32-S3 Rainbow: ZX Spectrum Emulator Board! Get it on Crowd Supply →
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

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…

Related Posts

TensorFlow Categorical Classification - In this blog, I venture beyond binary classification and delve into categorical classification using TensorFlow. Specifically, I show how to generate and classify images into four categories: blank, square, circle, and triangle. Crucially, I highlight the use of one-hot encoding for labeling and the softmax activation function in our model. I provide examples of code, results of my model's predictions, and link to the full code in my GitHub repository. Feel free to try it out and explore this exciting domain of machine learning further.
TensorFlow Binary Classification - In this playful tutorial for binary classification aided by visuals, we create a Python generator that generates alternating images of squares and circles, which we then classify using TensorFlow. We take special care to point out, too, that to get binary classification up and running, we must use a particular activation function and loss function. After training our model, illustrations show that it's excellent at identifying images as either squares or circles. So, if you're into Machine Learning and has a sense of humor, don’t forget to check out the 'hot dog or not hot dog' bit and visit the full part of the code on our GitHub repo!

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.
Tearing Down a Bistable Cholesteric Display - So, I finally tried out this bistable cholesteric display from my AliExpress stash after seeing Big Clive's teardown. It's super cool to play with, and I mean, it just clears up with a button press after you scribble on it. Gave it a whirl to understand the voltage involved and even ended up sparking it with some reverse polarity action (not the smartest move, I know). I might've broken it, but hey, it still sort of works manually. Check out Big Clive for a deeper dive into its reverse engineering, and remember to like and subscribe!
ESP32 Super Fast JPEG Decoder - 20ms! - In my exploration for the fastest JPEG decoder for the ESP32, I trod a path from the original JPEG decoder library at 109 milliseconds, to the accelerated TJPEG decoder at 55 milliseconds, and finally the impressive JPEG dec library at 32 milliseconds. But wait, there's more. Along came a GitHub issue suggesting decoding JPEG with SIMD, efficiently working wonders at a decoding speed of just 20 milliseconds. However, it threw a curveball when it came to drawing. The decoding process doesn't overlap with the pixel transfer making it slower than expected. It does bring great benefits for streaming JPEGs though, as the decoding of the next frame can start while the current one is loading. But the space this library would expropriate, around 130 kilobytes, from the memory of an ESP32 module can be an issue. Yet, there are promising improvements marching on the horizon, so stay tuned for the upcoming enhancements!
Level Shifter Circuit - simulation and real world test. - Hey there! If you're around my age, you'll probably get nostalgic over the sound of old school tape loading on the ZX Spectrum. I took a deep dive into how the data loads, using my oscilloscope to break it all down, and even built a circuit to handle the signal for my ESP32. Throw in some cool simulations using CircuitLab, and I'm all set! Plus, I discovered a neat trick using diodes to perfect the signal. Hands-on and really quite fun!
787 Volts From a $2 Board! - Let's have some fun with high voltage experiments and LED filaments! I've been dabbling with 300-400 volts, testing out capacitor charging, and saving some flickery Philips bulbs. With a new ESP32 Rainbow project in the works and a nifty minimalist ESP32 S3 board arriving soon, there's lots going on. Despite some high ripple issues and quirky sounds from the modules, swapping to an old-school surface mount board provides smooth performance with almost no ripple. Join me as I explore the limits and potential projects with these LEDs. And for a shocking tidbit at the end, explore some high voltage calculations—it's electrifying!
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