Efficient semidefinite-programming-based inference for binary and multi-class MRFs