import pickle
import glob


def get_num_examples(data_dir, mode):
    """
    Get the number of examples in directory.
    :param data_dir: str - data directory
    :param mode: str - `training`, `test` or `validate` (must match folder names)
    :return: int - number of examples
    """
    with open('{}/labels.pickle'.format(data_dir), 'rb') as f:
        data = pickle.load(f)

    modes = list(data.keys())
    del modes[-1]
    assert mode in modes, "'{}' not a valid mode (must be one of {})".format(mode, str(modes))
    assert glob.glob(data_dir), "Check directory."
    return len(data[mode])