This project implements a deep learning pipeline to detect scratches in semiconductor wafers using a custom U-Net model with fixed coordinate image generation and flexible training/prediction flows.
The model class is designed to be simple to use, encapsulated in a single Python class named Model, located in Model/model.py.
from Model.model import Modelmodel = Model(df_train=df_wafers)model.makeData() # Converts tabular data into 256x256 fixed-coordinate .pt imagesmodel.train(epoch=10)IsScratchDie = model.predict(df_wafers_test, yield_threshold=0.7)
df_wafers_test['IsScratchDie'] = IsScratchDiemodel.evaluate_die_level(df_wafers['IsScratchDie'].values, IsScratchDie)project_root/
├── Model/
│ ├── model.py # Model class with training and inference logic
│ ├── SaveModel/ # Stores best_model.pth, optimizer, val loss
├── datamap/
│ ├── Waferclass.py # Dataset and caching logic
│ └── data/cache/ # Cached training images and labels
│ └── data/test/ # Cached test images
- Each wafer is converted to a 256x256 tensor.
- Coordinates are mapped directly based on
DieX,DieYoffset. - This improves stability and removes ambiguity when mapping predictions back to wafer-level CSV.
- Saves best model, loss, and optimizer states.
- Early stopping with patience.
- Automatically resumes training if
continue_training=True.
- Removes low-yield wafers (e.g., yield < 0.7) before predicting.
- Loads preprocessed images.
- Uses the trained model to predict per-die scratch detection.
- Maps prediction back to CSV coordinates.
Model evaluation is performed at the die level:
- Accuracy
- Precision
- Recall
- F1-score
Results are printed and also saved to a CSV:
model.evaluate_die_level(true_labels, pred_labels, save_path="metrics.csv")- Original attempts used stretched resized 256x256 images.
- This introduced distortions during back-conversion to die coordinates.
- 🔁 Final solution uses fixed coordinate grid: a pixel is drawn only if a die exists in that coordinate.
- Prediction results in a [2, 256, 256] tensor (2 channels: [prob_not_scratch, prob_scratch]).
- Argmax is applied along channel dim to extract final binary scratch mask.
- CrossEntropyLoss with weighting improves imbalance.
- Batch size and DataLoader optimizations improve GPU utilization.
- Patience-based early stopping prevents overfitting.
