Enhancing PCB Manufacturing with Rekognition for Defect Detection
AWS Rekognition can revolutionize PCB manufacturing by automating defect detection, improving accuracy, and speeding up quality control. This blog covers how Rekognition’s image analysis can spot defects like component misplacements and soldering issues, streamlining the inspection process. Learn how to integrate Rekognition into your production line to boost efficiency, reduce errors, and improve overall product quality.
In PCB manufacturing, manual inspection is slow and error-prone. By using AWS Rekognition, we automated defect detection through image analysis, reducing inspection time and improving accuracy. This helped us catch issues like missing components and misalignments early, leading to faster production cycles and better product quality.
Architecture Diagram:
Architecture Diagram
Pre-requisite:
AWS Account
Create a role for the lambda function
Create a S3 bucket for the athena
QuickSight Account
Steps to be followed:
Step 1 - Create s3 bucket with the name pcb-defect-images-s3-buck0912 store the pcb image.
pcb-bucket
Step 2 - Now let's create the Amazon Rekognition before creating the agent lets disccuss about what is Amazon Rekognition.
What is Amazon Rekognition ?
Amazon Rekognition is a cloud-based image and video analysis service that makes it easy to add advanced computer vision capabilities to your applications. The service is powered by proven deep learning technology and it requires no machine learning expertise to use. Amazon Rekognition includes a simple, easy-to-use API that can quickly analyze any image or video file that’s stored in Amazon S3.
Amazon Rekognition Custom Labels lets you identify objects/scenes specific to your business (e.g., logos, products, plant health, machine parts).
Traditional image model development takes months and thousands of labeled images.
Rekognition simplifies this by requiring only a few hundred labeled images.
You can label images using its built-in tool or Amazon SageMaker Ground Truth.
The platform handles data inspection, algorithm selection, model training, and performance evaluation.
A custom model can be ready in hours and accessed via the Rekognition API for integration into your apps.
Amazon Rekognition Custom Labels project is a group of resources needed to create and manage a model. A project manages the following:
Step 4 - After creating a projects we will create dataset to train our model
create dataset
Step 5 - Now we will upload the dataset let's explore option, Select Start with a Single dataset To create the datasets for a project, you import the images in one of the following ways:
Import images from your local computer. (I have selected this option)
Import images from an S3 bucket. Amazon Rekognition Custom Labels can label the images using the folder names that contain the images.
Import an Amazon SageMaker AI Ground Truth manifest file.
Copy an existing Amazon Rekognition Custom Labels dataset.
starting config
Step 6 - You will see this kind of ui in front.
Dataset ui
Step 7 - adding the image dataset i have used PCB defect Dataset from kaggle you can refer this.
Adding label
Step 8 - Manage labels add your label using this it will identify and train the model accordingly so we are training model on basis of labels.
No issue
Burnt and Damage
Soldering issue
Manage Labels
Step 9 - Assigning label on the image so you might think 🤔 if i have 1000 image dataset how i can label them one by one it might be hectic. 😵💫 Don't worry we have a solution 😁
If you already have labels (e.g., in a CSV or Excel), you can convert them into a JSON manifest file.
Upload the manifest with your dataset to S3 and import it into Rekognition.
Step 10 - Assign the labels each i have small dataset so i am assigning manually
labeled image
Step 11 - let's train the model this will take some time depending upon the dataset you have provided.
train dataset
Step 12 - After your model gets train you can use it and you can also check the accuracy.
Accuracy Model
Step 13 - Your model is ready now you can utilise this Model using ARN.
Model ready ARN This was the part where we have train the model let's the automate the flow and get the s3 image data to dynomo DB whether it's damage or not and here we are creating lambda function let's Explore the lambda
What is lambda Function ?
Lambda runs your code on a high-availability compute infrastructure and performs all of the administration of the compute resources, including server and operating system maintenance, capacity provisioning and automatic scaling, and logging. With Lambda, all you need to do is supply your code in one of the language runtime that Lambda supports.
Create a new role of lambda this is the pre-requiste section
Create function
Step 15 - You need to create trigger whenever you upload new image this will trigger new lambda event function
Select source as a S3 bucket
Bucket name - pcb-defect-images-s3-buck0912
Event types - All object create events
All default
Add-trigger
Step 16 - Create a DynamoDB to store our image recognise data-information
What is DynamoDB?
Amazon DynamoDB is a serverless, NoSQL database service that allows you to develop modern applications at any scale. As a serverless database, you only pay for what you use and DynamoDB scales to zero, has no cold starts, no version upgrades, no maintenance windows, no patching, and no downtime maintenance. DynamoDB offers a broad set of security controls and compliance standards. For globally distributed applications, DynamoDB global tables is a multi-Region, multi-active database with a 99.999% availability SLA and increased resilience. DynamoDB reliability is supported with managed backups, point-in-time recovery, and more. With DynamoDB streams, you can build serverless event-driven applications.
You can also explore more about the service here is the link.
Why we are using DynamoDB here 💭 ?
DynamoDB is chosen over RDS because it aligns better with serverless, event-driven architectures. It offers scalability, low latency, and high throughput for handling large volumes of defect detection data from Rekognition, without the need for complex schema changes. Its flexible, schema-less design allows for easy adaptation to changing data, and it integrates seamlessly with Lambda for efficient, cost-effective data storage and retrieval. Additionally, DynamoDB's on-demand pricing is ideal for unpredictable workloads.
Step 17 - Creating a DynamoDB Table
DynamoDB Table creation
Step 18 - This is the lamda function code You need to
DYNAMODB_TABLE_NAME = "DefectDetectionResults"
PROJECT_VERSION_ARN = "arn:aws:rekognition:ap-southeast-1:123456789:project/AutomotiveSurfaceInspection/version/AutomotiveSurfaceInspection.2025-03-31T14.42.23/1743412343550" (ARN of your Custom Model)
Step 19 - run the lambda function also create a event
Event-trigger
Step 20 - You will see your Image is been scan and stored in DynamoDB Database.
Dynamodb Dataset store
Step 21 - Now the best part is i want this to be visualise and user can get more details easily via dashboard to get view easily which PCB is got damage and can be identify. To get data visualise i am using Quick-sight easy to integrate and let me Show you the step by step how we gonna implement.
What is Athena ?
Amazon Athena is an interactive query service in AWS that lets you analyze data directly in Amazon S3 using standard SQL. It's serverless, so there's no infrastructure to manage—you only pay for the queries you run. Athena supports various formats like CSV, JSON, ORC, Parquet, and Avro. It's great for quick, ad-hoc data analysis and integrates well with AWS Glue for data cataloging.
To know more about athena here is the link you can go through this.
Step 22 - Go to AWS Athena and in left hand there will be toggle and Administrator --> Datasource and Catlog and create data source
Choose the data-store - Amazon DynamoDB
Enter the Data Source details
Data source name - DefectDetection-ddb
spill location in Amazon S3 - select the bucket you have created for the athena in the pre-req section
Review and Create
Data-source and catlog
Select Datastore Dynamodb
Data-source Details
What is Glue?
AWS Glue is a fully managed, serverless ETL (Extract, Transform, Load) service that helps you prepare and transform data for analytics, machine learning, and application development. It automates tasks like data discovery, schema inference, and job scheduling, making the data integration process much easier. Glue includes a built-in Data Catalog that stores metadata, making your data easily searchable and accessible. It supports a wide range of data sources including Amazon S3, RDS, Redshift, and JDBC-compatible databases. Common use cases include building data lakes, feeding data into data warehouses, and setting up machine learning pipelines.
Step 23 - Go to the Athena page in setting section Manage add the bucket that you have created in pre-requiste and now in editor you need to run the Query and this Query will get data from the data source that is been associated to your DynamoDB.
Data source - DefectDetection-ddb
Database - default
Table - defectdetectionresults
Query Athena -
Add the bucket in Athena
Query RUN Athena
Step 24 - Now let's began with authenticate with the role and provide the permission Go to IAM section --> Roles
Search for the Role - Quicksight this have already created the ServiceAccount.
Add the permission
Create the Policy
Replace the Function that have been created automatically
This is the code - Specify the Function
Step 25 - Specify and add the permission in this role make sure to add baucket that you are using in data source
Step 26 - We are close to our step now let's get the data to Quick-sight
Go to Quicksight Add Dataset
Select Dataset Athena
Name of the Athena dataset
Choose the catlog datasource that you have created
Select the table
Finish Dataset Creation - Directly Query your data
Dataset ui Quicksight
Athena
Choose your table
Finish Dataset
Step 27 - Here we go this our last step adjust and create a chart and graph accordingly newsheet create and you can make more good visual add colour and create it 🥳
Graphs, charts table content
References:
Using an Amazon S3 trigger to invoke a Lambda function - [https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html]
Storing Amazon Rekognition Data with Amazon RDS and DynamoDB - [https://docs.aws.amazon.com/rekognition/latest/dg/storage-tutorial.html]
Amazon DynamoDB insights in Amazon QuickSight - [http://aws.amazon.com/blogs/big-data/visualize-amazon-dynamodb-insights-in-amazon-quicksight-using-the-amazon-athena-dynamodb-connector-and-aws-glue/]
Some of the YouTube content DynamoDB to Quicksight - [https://www.youtube.com/watch?v=d1ZsTwR7cB8]
🚀 This project demonstrated the power of combining AWS Rekognition, Lambda, and DynamoDB to build a smart, serverless defect detection system. 📸🛠️ Rekognition efficiently analyzed images for defects, while Lambda handled real-time processing and DynamoDB provided fast, flexible, and scalable storage. ⚡📊 Through this, we learned how a serverless, event-driven architecture simplifies operations and delivers high performance for dynamic workloads. ☁️💡 Choosing DynamoDB over traditional databases like RDS highlighted the benefits of schema flexibility, seamless integration, and cost-efficiency in modern cloud applications. ✅