def _purge_missing_data(self):
        """Iterate over all data and throw out missing images."""
        JPG = b'\xff\xd8\xff'

        clean_meta = []
        invalid_files = 0
        for entry in self.meta:
            full_path = os.path.join(self.root, self.BASE_FOLDER, entry['path'])
            with open(full_path, 'rb') as file_handle:
                if file_handle.read(3) == JPG:
                    clean_meta.append(entry)
                else:
                    invalid_files += 1
        print(f'Discarded {invalid_files} invalid files.')
        self.meta = clean_meta

        self.labels = [int(entry['species_id']) for entry in self.meta]
        self.paths = [os.path.join(self.root, self.BASE_FOLDER, entry['path']) for entry in self.meta]
Iterate over all data and throw out missing images.
clip_benchmark/clip_benchmark/datasets/birdsnap.py