--- library_name: pytorch pipeline_tag: image-segmentation tags: - image-segmentation - segmentation-models-pytorch - defect-detection --- # Industrial surface defect segmentation Pixel level segmentation of four surface defect classes on 128 x 800 grayscale inspection images. Exported from run `run_fold0_v16_5h`: variant `blend_mean`, validation score 0.7927 (0.7 x dice on defect pairs + 0.3 x empty accuracy), dice on defects 0.7245, empty accuracy 0.9518. On the earlier runs the public leaderboard score was about 0.045 below this validation score. ## Models | name | decoder | encoder | blend weight | validation score | |---|---|---|---|---| | fpn_convnext_small | FPN | tu-convnext_small.in12k_ft_in1k | 1.000 | 0.7813 | | fpn_convnext_small_hr | FPN | tu-convnext_small.in12k_ft_in1k | 1.000 | 0.7876 | | fpn_convnext_small_seed2 | FPN | tu-convnext_small.in12k_ft_in1k | 1.000 | 0.7856 | | unet_mambaout_tiny | Unet | tu-mambaout_tiny.in1k | 1.000 | 0.767 | ## Per class decision rule A class is predicted when the averaged classifier output is at least `cls_thr` and at least `area` pixels have probability above `det_thr`; the mask is then every pixel above `thr`. | class | thr | det_thr | area | cls_thr | validation dice | |---|---|---|---|---|---| | defect_a | 0.35 | 0.45 | 100 | 0.2 | 0.5435 | | defect_b | 0.6 | 0.6 | 400 | 0.0 | 0.5283 | | defect_c | 0.45 | 0.65 | 150 | 0.0 | 0.7524 | | defect_d | 0.4 | 0.5 | 200 | 0.0 | 0.8074 | ## Usage ```python from inference import DefectSegmenter, read_gray, mask_to_rle model = DefectSegmenter(".") masks = model.predict(read_gray("image.jpg")) print({k: mask_to_rle(v) for k, v in masks.items()}) ``` `python app.py` starts a Gradio demo. Test time flips: h, v, hv.