{"id":25582464,"url":"https://github.com/andylee40/aoi_defect_detection","last_synced_at":"2026-05-01T04:35:28.280Z","repository":{"id":276733493,"uuid":"930092896","full_name":"andylee40/aoi_defect_detection","owner":"andylee40","description":"AOI 瑕疵分類","archived":false,"fork":false,"pushed_at":"2025-02-10T05:04:37.000Z","size":1675,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T06:19:58.996Z","etag":null,"topics":["cnn","imbalanced-data","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andylee40.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-10T03:53:35.000Z","updated_at":"2025-02-10T05:24:30.000Z","dependencies_parsed_at":"2025-02-10T06:20:01.179Z","dependency_job_id":"01074259-d778-41a6-b845-5ea44754a923","html_url":"https://github.com/andylee40/aoi_defect_detection","commit_stats":null,"previous_names":["andylee40/aoi_defect_detection"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andylee40%2Faoi_defect_detection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andylee40%2Faoi_defect_detection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andylee40%2Faoi_defect_detection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andylee40%2Faoi_defect_detection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andylee40","download_url":"https://codeload.github.com/andylee40/aoi_defect_detection/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239958315,"owners_count":19724927,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cnn","imbalanced-data","pytorch"],"created_at":"2025-02-21T05:16:32.721Z","updated_at":"2026-04-02T12:30:23.598Z","avatar_url":"https://github.com/andylee40.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\ntags: Aidea competition\n---\n\n# AOI 瑕疵分類\n\n\n## 比賽連結\nhttps://aidea-web.tw/topic/285ef3be-44eb-43dd-85cc-f0388bf85ea4\n\n## 簡介\n本專案目的為藉由AOI影像訓練深度學習模型辨識產品表面瑕疵。結果顯示，訓練後的預訓練DenseNet121模型的測試準確達到98.89%、ResNet50模型達到97.75%及EfficientNet-B0模型98.96%，最後我們透過投票的方式綜合三個模型的結果為最後的預測結果，綜合後的集成模型準確達到99.21%。(目前排行榜上最高分為99.8%) 未來有時間會再嘗試更大的模型架構(如DenseNet169、EfficientNet-B4)，相信能進一步提升測試準確率。\n\n## 資料說明\n訓練資料：2,528張(隨機抽取20%作為驗證資料)\n測試資料：10,142張\n影像類別：6 個類別(正常類別 + 5種瑕疵類別)\n影像尺寸：512x512\n\n\n## 瑕疵分類\n如下圖所示，除了Normal外，其餘皆屬於瑕疵影像。\n\n![image](https://github.com/andylee40/aoi_defect_detection/blob/main/dataset.png)\n\n\n## 資料不平衡處理\n下圖為訓練資料集中的標籤分佈，可看出在第二類與的資料比較少，存在資料不平衡的問題。因此使用Focal Loss作為本次所有模型使用的損失函數，並針對訓練資料集中的標籤分佈，給予不同標籤相異的權重（越多的標籤給予越小的權重，越少的標籤給予越大的權重），以增強模型對少數標籤樣本的判別能力。\n![image](https://github.com/andylee40/aoi_defect_detection/blob/main/label.png)\n\n\n## 影像增強\n為增強模型提取影像特徵能力，針對所有影像進行以下影像預處理與增強：\n* 高斯模糊\n* 自適應直方圖均衡化\n* Laplacian銳化\n\n下圖為影像增強前後對比，可發現影像增強後，影像細節更明顯。\n\n![image](https://github.com/andylee40/aoi_defect_detection/blob/main/enhanced.png)\n\n\n## 影像擴增\n* 影像隨機水平翻轉(p=0.5)\n* 影像隨機旋轉正負 15 度\n* 影像大小縮放成 224 x 224\n\n## 模型\n* DenseNet121 (pretrained)\n* ResNet50 (pretrained)\n* EfficientNet-B0 (pretrained)\n\n\n## 模型訓練設置\n我們所有模型訓練設置如下，當驗證損失訓練5次後未下降，調降學習率;當驗證損失訓練7次後未下降，停止訓練。儲存驗證損失最低的模型權重，當做後續預測測試資料之模型。\n* Epoch：50\n* Learning rate：0.001\n* Weight decay：0.00001\n* Optimizer：AdamW\n* Scheduler：ReduceLROnPlateau(patience=5)\n* Early stopping patience： 7 \n\n## 結果\n1. 下表為預測結果，原以為三個模型中最大的模型ResNet50預測結果會最好，但就單一模型來看，可看出以預訓練EfficientNet-B0輸入AOI影像訓練後的辨識結果最佳，對10,142張測試資料的準確度(Accuracy)已達到98.96%。\n1. 最終使用的集成投票預測，可以達到更好的準確率99.21%。\n1. 註：測試資料的準確度是將預測結果上傳Aidea平台，由Aidea平台評分而得。\n\n| 模型 | 訓練準確率 | 驗證準確率 |測試準確率 |\n|:------|:------:|:------:|:------:|\n| DenseNet121 | 99.8%  | 99.01% |98.89% |\n| ResNet50 | 99.1%  | 97.82% |97.75% |\n| EfficientNet-B0 | 99.01% | 98.61% |98.96% |\n| VOTE | - | - |99.21% |\n\n\n\n\n\n## 排行榜\n\n最終最優排名為100名，參賽人數有834組，排名為前12%。\n\n![image](https://github.com/andylee40/aoi_defect_detection/blob/main/leaderboard.png)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandylee40%2Faoi_defect_detection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandylee40%2Faoi_defect_detection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandylee40%2Faoi_defect_detection/lists"}