본문 바로가기
Tensorflow

[Tensorflow] Fashion MNIST 분류 연습문제 풀이

by LasBe 2021. 4. 16.
반응형

연습문제 1. For this first exercise run the below code: It creates a set of classifications for each of the test images, and then prints the first entry in the classifications. The output, af ter you run it is a list of numbers. Why do you think this is, and what do those numbers represent? 

odel.predict(test_images) 는 test_images에 대한 예측 값을 구하는 함수이다. print(classifications[0]) 를 통해 첫 번째 값에 대한 예측값을 출력하였다. 9번만 0.9 이상이고 나머지는 아주 낮은 숫자이기 때문에 굉장히 높은 확률로 첫 번째 값은 부츠라고 추측할 수 있다.

 


연습문제 2. Let's now look at the layers in your model. Experiment with different values f or the dense layer with 512 neurons. What different results do you get for loss, training ti me etc? Why do you think that's the case? 

뉴런을 추가할수록 더 많은 계산을 필요로 해 많은 시간과 자원을 소모하지만 모델이 고도화되 고 정교해진다. 그러나 무작정 양만 늘린다고 정확성이 높아지는데엔 한계가 있기 때문에 정확 성이 높아지는 한계치에서 가장 적은 시간으로 실행될 수 있게 횟수를 조절해주어야 한다

 


연습문제 3. What would happen if you remove the Flatten() layer. Why do you think that' s the case? 

Flatten()은 다차원 데이터를 1차원으로 정렬하는 역할을 한다. 원본은 28x28의 2차원의 배열이 기 떄문에 원본상태로는 현 상태의 1차원 레이어를 통과하지 못해 오류가 생긴다.

 


연습문제 4. Consider the final (output) layers. Why are there 10 of them? What would ha ppen if you had a different amount than 10? For example, try training the network with 5

 

마지막 레이어의 뉴런 수는 분류하는 범주의 수와 같아야한다. 이 데이터세트는 0번부터 9번까 지 10가지의 범주를 구분하고 있기 때문에 10개가 아닌 다른 개수의 뉴런이 오게되면 오류가 발생한다.

 


연습문제 5. Consider the effects of additional layers in the network. What will happen if y ou add another layer between the one with 512 and the final layer with 10. 

생각보다 큰 영향을 끼치지 않는다. 아마도 간단한 데이터세트기 때문에 뉴런과 레이어의 많은 수가 적을 경우보다 비교적 끼치는 영향이 적을 것이다. 만약 복잡한 데이터일 경우 정확도를 높이는데 큰 영향을 줄 것이다.

 


연습문제 6. Consider the impact of training for more or less epochs. Why do you think th at would be the case? 

련 데이터에 대한 loss는 굉장히 낮아졌지만 검증 데이터에 대한 loss값은 오히려 높아졌다. 그 이유는 네트워크가 훈련 데이터에 과적합되었기 때문이다. 이를 해결하기 위해서는 콜백 함 수를 사용 해 최적의 손실율을 기록할 때 학습을 멈추게 해야 한다.


연습문제 7. Before you trained, you normalized the data, going from values that were 0-2 55 to values that were 0-1. What would be the impact of removing that? Here's the com plete code to give it a try. Why do you think you get different results? 

정규화는 모든 데이터가 동일한 정도의 중요도로 반영되도록 해 좋은 학습 효율을 얻을 수 있 게 한다. 그렇기 때문에 정규화를 적용한 모델보다 첫 번째 값의 예측값이 많이 불안해 보이는 것을 알 수 있다.

 


연습문제 8. Earlier when you trained for extra epochs you had an issue where your loss m ight change. It might have taken a bit of time for you to wait for the training to do that, and you might have thought 'wouldn't it be nice if I could stop the training when I reach a desired value?' -- i.e. 95% accuracy might be enough for you, and if you reach that aft er 3 epochs, why sit around waiting for it to finish a lot more epochs....So how would yo u fix that? Like any other program...you have callbacks! Let's see them in action... 

학습 횟수를 10번으로 설정했음에도 불구하고 6번째 학습에서 정확도가 0.9를 넘어가자 학습을 종료하는 모습이다. 이번엔 다른 방식으로 콜백을 해보겠다.

다른 방식으로 콜백 함수를 사용해 훈련을 해보았다. 이번에는 훈련 데이터의 20%를 떼어내서 검증 데이터로 사용해 검증 데이터의 손실율이 3회의 에포크를 수행하는 동안 최고 기록을 갱 신하지 못한다면 학습을 멈추게 해보았다. 그 결과 14 에포크에서 11 에포크의 기록을 깨지 못해 학습을 멈춘 것을 볼 수 있다. 콜백 함수를 통해 과적합을 막을 수 있지만 그 간격이 너무 좁으면 충분한 학습이 되기 전에 학습을 종료킬 수 있고, 간격이 너무 넓으면 과적합이 이미 어느정도 진행된 상태에서 학습이 중단되어 버릴 수 있다. 그렇기 때문에 학습 수와 과적합 사이를 유연하게 조절할 수 있어야 한다.

반응형

댓글


오픈 채팅