Code Monkey home page Code Monkey logo

image-checker's Introduction

Fast Image Integrity Checker

Check for corrupted JPEG,PNG (and more) images in bulk using GPU jpeg decoding powered by NVIDIA DALI!

Super fast compared to alternatives because it uses GPU decoding and checks in batches.

What is DALI? blogpost

Requirements

Depending on your cuda version install: NVIDIA DALI If it fails try pip3 install –upgrade pip

Usage

pip3 install image-checker

or

git clone https://github.com/cceyda/image-checker.git

CLI

There is a CLI that takes a folder --path to scan for images with the given extensions --ext. Outputs one line to error.log containing image path per broken file. Format of log file can be modified by --log_conf error handler using python logging example. If you don't want to use gpu provide --use_cpu flag. Use --recursive to traverse sub-folders.

image-check --path /mnt/data/dali_test/corrupt --recursive

usage: image-checker [-h] [-p PATH] [-b BATCH_SIZE] [-g DEVICE_ID]
                        [-ext EXTENSIONS] [-l LOG_CONG] [-r] [-d] [-c]

Check a folder of images for broken/misidentified images

optional arguments:
  -h, --help            show this help message and exit
  -p PATH, --path PATH  Path for folder to be checked
  -b BATCH_SIZE, --batch_size BATCH_SIZE
                        Number of files checked per iteration (Recommend <100)
  -g DEVICE_ID, --device_id DEVICE_ID
                        Gpu ID
  -ext EXTENSIONS, --extensions EXTENSIONS
                        (comma delimited) list of extentions to test for (only types supported by DALI)
  -l LOG_CONG, --log_conf LOG_CONF
                        Config file path
  -r, --recursive
  -d, --debug
  -c, --use_cpu

Code

from image_checker.checker import checker_batch,checker_single
from image_checker.iterators import folder_iterator

args = {
     "path": "/mnt/data/images/main/",
     "batch_size": 50,
     "prefetch": 1,
     "debug": False,
     "extensions": ["jpeg", "jpg", "png"],
     "recursive":False,
     "log_cong":"logging_config.json",
     "device":"mixed",
     "device_id":0
 }

ds = folder_iterator(args["path"], args["extensions"], args["recursive"])
bad_files=checker_batch(ds, args)

FAQ

  • What kind of corrupted images will this catch?

    • Images that can't be decoded by DALI.
    • GIFs pretending to be JPEGs (with a jpg,jpeg extension)
    • (Won't catch) files that can't be opened (TODO)
    • (Won't catch) empty image files
  • Supported image types?

Same as DALI supported formats: JPG, BMP, PNG, TIFF, PNM, PPM, PGM, PBM, JPEG 2000. Please note that GPU acceleration for JPEG 2000 decoding is only available for CUDA 11.

  • What is batch_size & prefetch?

DALI works with a batching+prefetching system. So batch_size * prefetch number of images are read at a time. If there is a corrupted file in the batch that batch is rechecked 1-by-1. So keep batch_size reasonable (0<100). Currently, only prefetch=1 works but it is a TODO item.

  • Package versioning follows dali for major.minor (since it heavily depends on it), patch is this packages version changes.

Alternatives

check-media-integrity: supports more types but uses PIL thus slow.

Bad Peggy: Checks JPEG images, maybe detects more types of errors than this one.

TODOs

Add tests

image-checker's People

Contributors

cceyda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

lilohuang

image-checker's Issues

`Critical error when building pipeline`

image-checker
{'path': './', 'batch_size': 50, 'device_id': 0, 'extensions': ['jpeg', 'jpg', 'png'], 'log_conf': 'logging_config.json', 'recursive': False, 'debug': False, 'use_cpu': False, 'prefetch': 1, 'device': 'mixed'}
Good images (±50): 0it [00:00,/usr/local/lib/python3.8/dist-packages/nvidia/dali/ops.py:649: DeprecationWarning: WARNING: `image_decoder` is now deprecated. Use `decoders.image` instead.
In DALI 1.0 all decoders were moved into a dedicated :mod:`~nvidia.dali.fn.decoders`
submodule and renamed to follow a common pattern. This is a placeholder operator with identical
functionality to allow for backward compatibility.
  op_instances.append(_OperatorInstance(input_set, self, **kwargs))
Traceback (most recent call last):
  File "/home/build/.local/bin/image-checker", line 8, in <module>
    sys.exit(main())
  File "/home/build/.local/lib/python3.8/site-packages/image_checker/cli.py", line 73, in main
    checker_batch(ds, args)
  File "/home/build/.local/lib/python3.8/site-packages/image_checker/checker.py", line 38, in checker_batch
    checker = DaliChecker(args["batch_size"], args["prefetch"],args["device"],args["device_id"])
  File "/home/build/.local/lib/python3.8/site-packages/image_checker/DaliChecker.py", line 27, in __init__
    self.pipe.build()
  File "/usr/local/lib/python3.8/dist-packages/nvidia/dali/pipeline.py", line 828, in build
    self._pipe.Build(self._generate_build_args())
RuntimeError: Critical error when building pipeline:
Error when constructing operator: ImageDecoder encountered:
Error in thread 0: nvml error (3): The nvml requested operation is not available on target device
Current pipeline object is no longer valid.
Bad images: 0it [00:02, ?it/s]
Good images (±50): 0it [00:02, ?it/s]

This runs on WSL 2 with NVIDIA drivers and CUDA 11 (11.0.228) support installed and available.
Or does Dali require explicit JPEG/image hardware decoder support on the GPU, which isn't present or passed-through on this system?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.