Ensemble sampler for infinite-dimensional inverse problems