Precision Lens is an end to end MLOps project for image anomaly detection in a manufacturing setting. 🏭
On the inference side, it utilizes an ML pipeline to classify an image as a particular product/part, and then selects a pre-trained model to detect anomalies in the image.
On the training side, new data captured from the manufacturing line is used to retrain the classification model and the anomaly detection models automatically.
The focus of this project is to provide a robust and scalable solution for image classification and anomaly detection in a production environment, leveraging modern MLOps practices. ⚙️ Ease of use, quality data collection, automation, auditability, and scalability are key design principles.
flowchart TD
A[Operator Web App - Inference] -->|Images| B[ML Pipeline]
A2[Operator Web App - Data Capture] -->|New data| C[S3 Storage]
B --> D[Classification & Anomaly Detection]
D -->|Results| A
C --> E[Retraining Pipeline]
E --> F[MLflow Tracking]
E -->|Updated models| B
- Image Classification 📸: Classifies images into different product categories.
- Anomaly Detection 🔍: Creates individual models for each product/part class.
- Automated Retraining 🔄: Automatically retrains models with new data.
- Kubernetes Deployment ☸️: Deploys the application on a Kubernetes cluster.
- S3 Storage 📦: Stores data and model artifacts in Amazon S3.
- MLflow Tracking 📊: Logs experiments, models, and metrics using MLflow.
- Operator Web App 🖥️: Provides a simple web interface for production line operators to inspect parts with the anomaly detection system, as well as capturing new data for retraining.
- Human-in-the-loop 👥: Integrate human feedback to confirm data quality and labeling.
- Model Drift Detection 📈: Monitor model performance and detect drift over time.
- apps/inspection-app: Contains the code for the operator web app (Plotly Dash).
- infrastructure/: Terraform IaC for deploying the complete stack to a Kubernetes cluster.
- models/: Contains the model training and inference code.
- pipelines/: Contains the ML pipelines for automated training. (Prefect)
See the project folders for additional details and documentation on each component.
- A Kubernetes cluster
- kubectl command-line tool
- Helm package manager
- Terraform command-line tool
-
Clone the repository:
git clone https://github.com/spencershepard/MLOps-Precision-Lens.git cd MLOps-Precision-Lens cp secrets.env.example secrets.env -
Configure your secrets/config:
- Update
secrets.envwith your AWS credentials and other necessary secrets. - Update
config.envwith your desired configuration settings.
- Update
-
Setup Hostnames:
- Update your
/etc/hostson linux, or run infrastructure\scripts\setup-local-domains.ps1 on Windows.
- Update your
-
Deploy the infrastructure:
- Navigate to the
infrastructure/terraformdirectory. - Run the following command to deploy the infrastructure:
terraform init terraform apply
Note: If apply fails, you may need to make the following changes in the Prefect UI under Blocks:
- Edit 'my-pool' and set the cluster_config to the automatically created 'my-cluster' block.
- Edit the
my-k8s-credsblock and set the `cluster_config' to the automatically created 'my-cluster' block. - Edit the
my-s3block and set theaws_credentialsto the automatically created 'my-aws' block. - terraform apply again.
- Navigate to the
-
Add the first model In MLFLow, create a new model for each product/part class you want to detect anomalies for.
Once the infrastructure is deployed and the hostname is set up, you can access the application at:
http://precision-lens.local:30080
- MLFlow UI: http://mlflow.local:30080
- Prefect UI: http://prefect.local:30080
- Grafana UI: http://grafana.local:30080 with the default credentials
admin/promoperator.

