In the thread you posted is a valid solution:
Here is a small example using CIFAR10 from the other thread: