def filter_dataset(dataset, data_filename, percentile, min_nrof_images_per_class):
    with h5py.File(data_filename, 'r') as f:
        distance_to_center = np.array(f.get('distance_to_center'))
        label_list = np.array(f.get('label_list'))
        image_list = np.array(f.get('image_list'))
        distance_to_center_threshold = find_threshold(distance_to_center, percentile)
        indices = np.where((distance_to_center >= distance_to_center_threshold))[0]
        filtered_dataset = dataset
        removelist = []
        for i in indices:
            label = label_list[i]
            image = image_list[i]
            if (image in filtered_dataset[label].image_paths):
                filtered_dataset[label].image_paths.remove(image)
            if (len(filtered_dataset[label].image_paths) < min_nrof_images_per_class):
                removelist.append(label)
        ix = sorted(list(set(removelist)), reverse=True)
        for i in ix:
            del filtered_dataset[i]
    return filtered_dataset
def filter_dataset(dataset, data_filename, percentile, min_nrof_images_per_class):
    with h5py.File(data_filename, 'r') as f:
        distance_to_center = np.array(f.get('distance_to_center'))
        label_list = np.array(f.get('label_list'))
        image_list = np.array(f.get('image_list'))
        distance_to_center_threshold = find_threshold(distance_to_center, percentile)
        indices = np.where((distance_to_center >= distance_to_center_threshold))[0]
        filtered_dataset = dataset
        removelist = []
        for i in indices:
            label = label_list[i]
            image = image_list[i]
            if (image in filtered_dataset[label].image_paths):
                filtered_dataset[label].image_paths.remove(image)
            if (len(filtered_dataset[label].image_paths) < min_nrof_images_per_class):
                removelist.append(label)
        ix = sorted(list(set(removelist)), reverse=True)
        for i in ix:
            del filtered_dataset[i]
    return filtered_dataset