quandao92 commited on
Commit
8b0ac60
·
verified ·
1 Parent(s): b91dc36

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +247 -5
README.md CHANGED
@@ -1,5 +1,247 @@
1
- ---
2
- license: other
3
- license_name: 4inlab
4
- license_link: LICENSE
5
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # CLIP 기반 제품 결함 탐지 모델 카드
3
+
4
+ ## 모델 세부사항
5
+
6
+ ### 모델 설명
7
+
8
+ 이 모델은 CLIP 기반의 이상 탐지 방법을 사용하여 제품 결함을 탐지합니다.
9
+ 사전 훈련된 CLIP 모델을 fine-tuning하여 제품 이미지에서 결함을 식별하고, 생산 라인에서 품질 관리 및 결함 감지를 자동화합니다.
10
+
11
+ - **Developed by:** 박진제
12
+ - **Funded by:** 4INLAB INC.
13
+ - **Shared by:** None
14
+ - **Model type:** YOLOv7 (Object Detection)
15
+ - **Language(s):** Python, PyTorch
16
+ - **License:** Apache 2.0, MIT, GPL-3.0
17
+
18
+ ### 기술적 제한사항
19
+
20
+ - 모델은 결함 탐지를 위한 충분하고 다양한 훈련 데이터를 필요로 합니다. 훈련 데이터셋이 부족하거나 불균형할 경우, 모델의 성능이 저하될 수 있습니다.
21
+ - 실시간 결함 감지 성능은 하드웨어 사양에 따라 달라질 수 있으며, 높은 해상도에서 결함을 탐지하는 정확도가 떨어질 수 있습니다.
22
+ - 결함이 미세하거나 제품 간 유사성이 매우 높은 경우, 모델이 결함을 정확하게 탐지하지 못할 수 있습니다.
23
+
24
+ ## 학습 세부사항
25
+
26
+ ### Hardware
27
+ - **CPU:** Intel Core i9-13900K (24 Cores, 32 Threads)
28
+ - **RAM:** 64GB DDR5
29
+ - **GPU:** NVIDIA RTX 4090Ti 24GB
30
+ - **Storage:** 1TB NVMe SSD + 2TB HDD
31
+ - **Operating System:** Windows 11 pro
32
+
33
+ ### 데이터셋 정보
34
+
35
+ 이 모델은 시계열 재고 데이터를 사용하여 훈련됩니다. 이 데이터는 재고 수준, 날짜 및 기타 관련 특성에 대한 정보를 포함하고 있습니다.
36
+ 데이터는 Conv1D와 BiLSTM 레이어에 적합하도록 MinMax 스케일링을 사용하여 전처리되고 정규화됩니다.
37
+
38
+
39
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/E8pMyLfUnlIQFCLbTiLba.png)
40
+
41
+ - **Data sources:** https://huggingface.co/datasets/quandao92/vision-inventory-prediction-data
42
+ - **Training size:**
43
+ - 1차 + 2차 + 3차 ~ 131,189 이미지지
44
+ - **Time-step:** 5~7초
45
+
46
+ - **Data Processing Techniques:**
47
+ - normalization:
48
+ description: "이미지 픽셀 값을 평균 및 표준편차로 표준화"
49
+ method: "'Normalize' from 'torchvision.transforms'"
50
+ - max_resize:
51
+ description: "이미지의 최대 크기를 유지하며, 비율을 맞추고 패딩을 추가하여 크기 조정"
52
+ method: "Custom 'ResizeMaxSize' class"
53
+ - random_resized_crop:
54
+ description: "훈련 중에 이미지를 랜덤으로 자르고 크기를 조정하여 변형을 추가"
55
+ method: "'RandomResizedCrop' from 'torchvision.transforms'"
56
+ - resize:
57
+ description: "모델 입력에 맞게 이미지를 고정된 크기로 조정"
58
+ method: "'Resize' with BICUBIC interpolation"
59
+ - center_crop:
60
+ description: "이미지의 중앙 부분을 지정된 크기로 자르기"
61
+ method: "'CenterCrop'"
62
+ - to_tensor:
63
+ description: "이미지를 PyTorch 텐서로 변환"
64
+ method: "'ToTensor'"
65
+ - augmentation (optional):
66
+ description: "데이터 증강을 위해 다양한 랜덤 변환 적용, 'AugmentationCfg'로 설정 가능"
67
+ method: "Uses 'timm' library if specified"
68
+
69
+
70
+ # AD-CLIP Model Architecture
71
+
72
+
73
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/1wFBzBCgF4sOefROGE7RO.png)
74
+
75
+ - **model:**
76
+ - input_layer:
77
+ - image_size: [640, 640, 3] # 표준 입력 이미지 크기
78
+ - backbone:
79
+ - name: CLIP (ViT-B-32) # CLIP 모델의 비전 트랜스포머를 백본으로 사용
80
+ - filters: [32, 64, 128, 256, 512] # 비전 트랜스포머의 각 레이어 필터 크기
81
+ - neck:
82
+ - name: Anomaly Detection Module # 결함 탐지를 위한 추가 모듈
83
+ - method: Contrastive Learning # CLIP 모델의 특징을 사용한 대조 학습 기법
84
+ - head:
85
+ - name: Anomaly Detection Head # 결함 탐지를 위한 최종 출력 레이어
86
+ - outputs:
87
+ - anomaly_score: 1 # 이상 탐지 점수 (비정상/정상 구분)
88
+ - class_probabilities: N # 각 클래스에 대한 확률 (결함 여부)
89
+
90
+ # Optimizer and Loss Function
91
+ - **training:**
92
+ - optimizer:
93
+ - name: AdamW # AdamW 옵티마이저 (가중치 감쇠 포함)
94
+ - lr: 0.0001 # 학습률
95
+ - loss:
96
+ - classification_loss: 1.0 # 분류 손실 (교차 엔트로피)
97
+ - anomaly_loss: 1.0 # 결함 탐지 손실 (이상 탐지 모델에 대한 손실)
98
+ - contrastive_loss: 1.0 # 대조 학습 손실 (유사도 기반 손실)
99
+
100
+ # Metrics
101
+ - **metrics:**
102
+ - Precision # 정밀도 (Precision)
103
+ - Recall # 재현율 (Recall)
104
+ - mAP # 평균 정밀도 (Mean Average Precision)
105
+ - F1-Score # F1-점수 (균형 잡힌 평가 지표)
106
+
107
+ # Training Parameters
108
+ **하이퍼파라미터 설정**
109
+ - Learning Rate: 0.001.
110
+ - Batch Size: 1.
111
+ - Epochs: 200.
112
+
113
+ # Data Parameters
114
+ **데이터 증강**
115
+ - 회전을 적용하여 모델의 일반화 성능 강화.
116
+
117
+ # Evaluation Parameters
118
+ - F1-score: 95%이상.
119
+
120
+
121
+ ### 학습 성능 및 테스트 결과
122
+
123
+ - **학습성능 테스트 결과과 그래프**:
124
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/RduhNlkWiyPXj-vbAkJga.png)
125
+
126
+
127
+
128
+ - **학습 결과표**:
129
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/kDxl9q6X2dxCRJm5nc7jR.png)
130
+
131
+ - **테스트 결과 그래프**:
132
+ <div style="display: flex; justify-content: space-between;">
133
+ <div style="text-align: center;">
134
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/FTqWPelFDZr3AVA6lD-du.png" height="1000" width="1000" style="margin-right:5px;">
135
+ <p>테스트 결과 1</p>
136
+ </div>
137
+ <div style="text-align: center;">
138
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/65e7d0935ea025ead9623dde/yOaCqdl12zCjmMLa8442F.png" height="1000" width="1000" style="margin-right:5px;">
139
+ <p>테스트 결과 2</p>
140
+ </div>
141
+ </div>
142
+
143
+
144
+
145
+ # 설치 및 실행 가이라인
146
+
147
+ 이 모델을 실행하려면 Python과 함께 다음 라이브러리가 필요합니다:
148
+
149
+ - **ftfy==6.2.0**: 텍스트 정규화 및 인코딩 문제를 해결하는 라이브러리.
150
+ - **matplotlib==3.9.0**: 데이터 시각화 및 그래프 생성을 위한 라이브러리.
151
+ - **numpy==1.24.3**: 수치 연산을 위한 핵심 라이브러리.
152
+ - **opencv_python==4.9.0.80**: 이미지 및 비디오 처리용 라이브러리.
153
+ - **pandas==2.2.2**: 데이터 분석 및 조작을 위한 라이브러리.
154
+ - **Pillow==10.3.0**: 이미지 파일 처리 및 변환을 위한 라이브러리.
155
+ - **PyQt5==5.15.10**: GUI 애플리케이션 개발을 위한 프레임워크.
156
+ - **PyQt5_sip==12.13.0**: PyQt5와 Python 간의 인터페이스를 제공하는 라이브러리.
157
+ - **regex==2024.5.15**: 정규 표현식 처리를 위한 라이브러리.
158
+ - **scikit_learn==1.2.2**: 기계 학습 및 데이터 분석을 위한 라이브러리.
159
+ - **scipy==1.9.1**: 과학 및 기술 계산을 위한 라이브러리.
160
+ - **setuptools==59.5.0**: Python 패키지 배포 및 설치를 위한 라이브러리.
161
+ - **scikit-image**: 이미지 처리 및 분석을 위한 라이브러리.
162
+ - **tabulate==0.9.0**: 표 형태로 데이터를 출력하는 라이브러리.
163
+ - **thop==0.1.1.post2209072238**: PyTorch 모델의 FLOP 수를 계산하는 도구.
164
+ - **timm==0.6.13**: 다양한 최신 이미지 분류 모델을 제공하는 라이브러리.
165
+ - **torch==2.0.0**: PyTorch 딥러닝 프레임워크.
166
+ - **torchvision==0.15.1**: 컴퓨터 비전 작업을 위한 PyTorch 확장 라이브러리.
167
+ - **tqdm==4.65.0**: 진행 상황을 시각적으로 표시하는 라이브러리.
168
+ - **pyautogui**: GUI 자동화를 위한 라이브러리.
169
+
170
+
171
+
172
+
173
+ ### 모델 실행 단계:
174
+
175
+ ### ✅ Prompt generating
176
+ ```ruby
177
+ training_lib/prompt_ensemble.py
178
+ ```
179
+ 👍 **Prompts Built in the Code**
180
+ 1. Normal Prompt: *'["{ }"]'*
181
+ → Normal Prompt Example: "object"
182
+ 2. Anomaly Prompt: *'["damaged { }"]'*
183
+ → Anomaly Prompt Example: "damaged object"
184
+
185
+ 👍 **Construction Process**
186
+ 1. *'prompts_pos (Normal)'*: Combines the class name with the normal template
187
+ 2. *'prompts_neg (Anomaly)'*: Combines the class name with the anomaly template
188
+
189
+ ### ✅ Initial setting for training
190
+
191
+ - Define the path to the training dataset and model checkpoint saving
192
+ ```ruby
193
+ parser.add_argument("--train_data_path", type=str, default="./data/", help="train dataset path")
194
+ parser.add_argument("--dataset", type=str, default='smoke_cloud', help="train dataset name")
195
+ parser.add_argument("--save_path", type=str, default='./checkpoint/', help='path to save results')
196
+ ```
197
+
198
+ ### ✅ Hyper parameters setting
199
+
200
+ - Set the depth parameter: depth of the embedding learned during prompt training. This affects the model's ability to learn complex features from the data
201
+ ```ruby
202
+ parser.add_argument("--depth", type=int, default=9, help="image size")
203
+ ```
204
+
205
+ - Define the size of input images used for training (pixel)
206
+ ```ruby
207
+ parser.add_argument("--image_size", type=int, default=518, help="image size")
208
+ ```
209
+
210
+ - Setting parameters for training
211
+ ```ruby
212
+ parser.add_argument("--epoch", type=int, default=500, help="epochs")
213
+ parser.add_argument("--learning_rate", type=float, default=0.0001, help="learning rate")
214
+ parser.add_argument("--batch_size", type=int, default=8, help="batch size")
215
+ ```
216
+
217
+ - Size/depth parameter for the DPAM (Deep Prompt Attention Mechanism)
218
+ ```ruby
219
+ parser.add_argument("--dpam", type=int, default=20, help="dpam size")
220
+
221
+ 1. ViT-B/32 and ViT-B/16: --dpam should be around 10-13
222
+ 2. ViT-L/14 and ViT-L/14@336px: --dpam should be around 20-24
223
+ ```
224
+ ```ruby
225
+ → DPAM is used to refine and enhance specific layers of a model, particularly in Vision Transformers (ViT).
226
+ → Helps the model focus on important features within each layer through an attention mechanism
227
+ → Layers: DPAM is applied across multiple layers, allowing deeper and more detailed feature extraction
228
+ → Number of layers DPAM influences is adjustable (--dpam), controlling how much of the model is fine-tuned.
229
+ → If you want to refine the entire model, you can set --dpam to the number of layers in the model (e.g., 12 for ViT-B and 24 for ViT-L).
230
+ → If you want to focus only on the final layers (where the model usually learns complex features), you can choose fewer DPAM layers.
231
+ ```
232
+
233
+ ### ✅ Test process
234
+
235
+ 👍 **Load pre-trained and Fine tuned (Checkpoints) models**
236
+ 1. Pre-trained mode (./pre-trained model/):
237
+ ```ruby
238
+ → Contains the pre-trained model (ViT-B, ViT-L,....)
239
+ → Used as the starting point for training the CLIP model
240
+ → Pre-trained model helps speed up and improve training by leveraging previously learned features
241
+ ```
242
+ 2. Fine-tuned models (./checkpoint/):
243
+ ```ruby
244
+ → "epoch_N.pth" files in this folder store the model's states during the fine-tuning process.
245
+ → Each ".pth" file represents a version of the model fine-tuned from the pre-trained model
246
+ → These checkpoints can be used to resume fine-tuning, evaluate the model at different stages, or select the best-performing version
247
+ ```