A Unified Approach to Count-Based Weakly Supervised Learning