Skip to main content

API for defect detection in PCB and other components.

Project description

defect_detection

PyPI Build

This packge provides a basic API to implement defect detection algorithms. Those can be tuned in order to automatically detect any defects in a PCB or other components.

Requirement

The following packages are required :

  • numpy
  • opencv-python
  • torch
  • scikit-learn

Recommended python version >= 3.8

Installation

To install the latest stable release from PyPI :

pip install defect_detection

For developper who wants to work with a local and editable version :

git clone https://github.com/lovaslin/defect_detection.git
cd defect_detection
pip install -e .

For the local install, you should of course run the commands using a clean python environment. I recommend to use venv to setup a pip-friendly environemnt.

Example script

An example script is available in the example/ directory of this repository.
The directory also contains all the required configuration files.

In order to run the script, you must first run the get_source_images.sh script to install the example source dataset.

cd example
./get_source_images.sh

Once the data is installed you can run the example.py script.
This script demonstrates the following features :

  • Generating a augmanted dataset from source images
  • Loading batches of images from disk
  • Training a basic unsupervised model for defect detection
  • Apply a train model to a batch of images
  • Use clusturing and filtering to extract the most anomalous pixel clusters in a given image

Available features

  • Dataset creation

The provided defect_detection.generate_dataset function can be used to generate a dataset suitable for training and/or testing models. A list of the source image file names must be provided together with preprocessing and data augmentation parameters.

The specification of the function arguments are available in the docstring.

  • Input batch loading

A batch of images can be loaded from disk directly using the defect_detection.load_batch function. Optionally, it is possible to produce a noisy version of the input batch that can be used e.g. for training a new model. The batch of images is returned as a torch tensor stored on the required device.

If the data was already loaded as a numpy array, it is possible to convert it to a torch tensor using the defect_detection.get_tensor function. The option to generate a noisy version is also available.

  • New model training

The defect_detection.deepAE_train function provides a basic training loop to train a new unsupervised defect detection model. It is recommended to use a dataset generated with the defect_detection.generate_dataset to perform the training (but not mandatory). Note that a file containing the specification of the model structure hyperparameters must be provided (see specification in wiki). The trained model will be saved on disk and the training and validation loss functions will be returned after completion of the training.

It is also possible to write a custom training loop using the built-in AE_cls.batch_train method to compute the loss and update model parameters.

  • Load a existing model for application

The defect_detection.deepAE_load function allows loading a previously trained model from the disk. By default, the model will be set for application only (no training functionality available).

Once a model is loaded, it is possible to compute both the per pixel anomaly score map and loss using the built-in AE_cls.batch_apply method.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

defect_detection-0.4.4.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

defect_detection-0.4.4-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file defect_detection-0.4.4.tar.gz.

File metadata

  • Download URL: defect_detection-0.4.4.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for defect_detection-0.4.4.tar.gz
Algorithm Hash digest
SHA256 004bb89421b369bb7f0d7ce7556f97566f62b7d5df92da16644eaf567b0393a7
MD5 931baf849c58e09aaf61e07cb3ebd559
BLAKE2b-256 89decc8581e20e8d4641fd50316641ef8d5d7b868786b7c46bd8d8aa22ac5fb4

See more details on using hashes here.

File details

Details for the file defect_detection-0.4.4-py3-none-any.whl.

File metadata

File hashes

Hashes for defect_detection-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 32c74f4a781d87ce28b753a8de043c59133567ef92333c0ead56aaa139a42caf
MD5 677791140e85481f5a86f49e1260a256
BLAKE2b-256 5d321207d9afa70cd7e1e380d1d0be6faa5f0fa04ae1a938319385e620d0b6b5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page