Bilevel Hyperparameter Learning for Nonsmooth Regularized Imaging and Machine Learning Models