Learning the optimal regularizer for inverse problems