Dynamic neural networks for efficient image and video classification