challenges
image classifier
일반적인 형태
def predict(image):
'''???'''
return class_label
라벨과 그에 따른 이미지 데이터셋 구축
머신러닝을 통해 이미지 분류기를 학습시킴
테스트 이미지들로 이미지 분류기를 evaluate 함
def train(train_images, train_labels):
# build a model for images -> labels...
return model
def predict(model, test_images):
# predict test_labels using the model...
return test_labels
첫 번째 분류기 : Nearest Neighbor Classifier
거리 (L1 distance)
I1과 I2 사이의 차이에 절댓값 기호를 씌워준 것.
distances = np.sum(np.abs(self.Xtr = X[i, :], axis = 1)
Q. what is the accuracy of the nearest neighbor classifier on the training data, when using the euclidean distanch?
A. 100%. 우리가 테스트한 트레이닝 데이터가 이미 트레이닝 데이터셋에 존재하기 때문이다.
L2든 L1이든 마찬가지
Q. what is the accuracy of the k-nearest neighbor classifier on the training data?
A. k가 1일 때는 무조건 정확한 클래스를 예측하겠지만 2 ~부터 어떤 클래스를 예측하냐에 따라 (다수결에 의해) 결정되기 때문에 정확하게 알 수 없다.
Q. what is the best distance to use?
Q. what is the best value of k to use?
i.e. how do we set the hyperparameters?
→ Very problem-dependent. Must try them all out and see what works best.
Q. hyperparameters를 바꾸면 test data에 적용해보면 될까?
A. 절대 안됨. test dataset은 최후의 보루. 성능 평가를 위해 끝까지 남겨놔야 할 데이터.
→ Validation data (20% of train data)
use to tune hyperparameters
→ Cross-validation(train data가 적을 때)
cycle through the choice of which fold is the validation fold, average results.
1,2,3,4 : train - 5 : validation
2,3,4,5 : train - 1 : validation
linear classifier
CNN으로 가는 길
parametric approach
Q. what does the linear classifier do?
A1. just a weighted sum of all the pixel values in the image.
A2. counting colors at different spatial position.
기본적으로 한계점이 있다.
Q. what would be a very hard set of classes for a linear classifier to distinguish?
A. 노랑 자동차, gray한 이미지들, 텍스쳐는 다르지만 색상이 동일한 경우, 강아지는 어디에 있던 잘 구별할 것이다.
점수를 기반으로 loss function을 정의해야함
점수에 따라 성능이 좋은지 나쁜지 정량화.