test000000

import os
from PIL import Image


def validate_images(directory, recursive=True, extensions=None):
    if extensions is None:
        extensions = ('.jpg', '.jpeg', '.png', '.bmp', '.tiff', '.gif')  # Add more extensions if needed

    error_log = []

    for root, dirs, files in os.walk(directory):
        if not recursive and root != directory:
            break

        for file in files:
            file_path = os.path.join(root, file)

            if file_path.endswith(extensions):
                try:
                    img = Image.open(file_path)
                    img.verify()  # Optionally verify that the image is intact (slower)
                    img.close()
                    print(f"Validated: {file_path}")
                except Exception as e:
                    error_log.append((file_path, str(e)))
                    print(f"Error loading image: {file_path} - {str(e)}")

    return error_log


if __name__ == "__main__":
    directory_to_validate = "../dataset/train2014"
    recursive_search = True  # Set to False to only check the specified directory (no subdirectories)

    error_log = validate_images(directory_to_validate, recursive=recursive_search)
    print("\nValidation complete.")

    if error_log:
        print("\nErrors encountered:")
        for file_path, error_msg in error_log:
            print(f"{file_path}: {error_msg}")
    else:
        print("No errors found.")

相关推荐

  1. test000000

    2024-04-05 16:20:05       18 阅读
  2. Photoshop_00000

    2024-04-05 16:20:05       19 阅读
  3. <span style='color:red;'>TEST</span>!!!!

    TEST!!!!

    2024-04-05 16:20:05      4 阅读
  4. 000003 - Hadoop集群配置

    2024-04-05 16:20:05       6 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-05 16:20:05       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-05 16:20:05       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-05 16:20:05       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-05 16:20:05       18 阅读

热门阅读

  1. LLM记录1

    2024-04-05 16:20:05       14 阅读
  2. 【C++算法】 卡常技巧

    2024-04-05 16:20:05       16 阅读
  3. Python程序设计 垃圾回收机制&鸭子类型

    2024-04-05 16:20:05       14 阅读
  4. vue3 模板编译过程

    2024-04-05 16:20:05       19 阅读
  5. 深度学习中的算子

    2024-04-05 16:20:05       12 阅读
  6. Linux服务器上安装多个版本cuda的一些准备

    2024-04-05 16:20:05       13 阅读
  7. 理想大模型实习面试题6道(答案解析)

    2024-04-05 16:20:05       17 阅读
  8. 设计模式:生活中的组合模式

    2024-04-05 16:20:05       15 阅读
  9. Android studio gradle 8.0引用libs目录下的aar库

    2024-04-05 16:20:05       14 阅读