def generate_crop_synset(synset_annotation_folder,images_folder,target_folder): synset_images_cropped = 0 synset_crops_saved = 0 synset_images_notfound = 0 try: annotation_files = os.listdir(synset_annotation_folder) for xml_file in annotation_files: image_annotation = Annotation(synset_annotation_folder + xml_file) try: image = Image.open(images_folder + image_annotation.folder + '/' + image_annotation.filename + ".JPEG") synset_crops_saved += image_annotation.save_crops(image,target_folder,scale=True,p=0.2) synset_images_cropped += 1 except IOError: synset_images_notfound += 1 except OSError: print(synset_annotation_folder + " not found") print(str(synset_images_cropped) + ' images cropped') print(str(synset_images_notfound) + ' images with annotations not found in this synset') print(str(synset_crops_saved) + ' synset crops saved') return [synset_crops_saved,synset_images_cropped,synset_images_notfound]