In this paper we propose an optimization framework able to handle the solution of partially known nonconvex variational models, which often arise in several imaging problems addressed by exploiting machine learning strategies. Our approach consists in a forward--backward method with line--search based on approximated values of the objective function and its gradient. As a special case of our general scheme, we derive two algorithms: a line--search based FISTA-like algorithm and a specific inexact method for bilevel optimization problems. The numerical experiments on deblurring and blind deconvolution problems show that the proposed methods are competitive with existing approaches.