Optimized training and scalable implementation of Conditional Deep Neural Networks with early exits for Fog-supported IoT applications