AP-Perf: Incorporating Generic Performance Metrics in Differentiable Learning