2017년 1월 25일 수요일

caffe data augmentation

딥러닝할때 주어진 DATA의 량은 정합성을 좌우 하죠.. 때문에 DATA Augmentation 이 필요하죠.. Caffe 가 기본 제공 하는 augmentation은 random crop 과 mirror(flip vertical) 입니다. 그리고 Train Phase만 사용 가능하구요. 다른 사람들이 만들어 놓은것도 있는데, 추가로 더 필요한 것들이 많네요.

 가장 general 한 방법들이 많이 추가 된 곳이 https://github.com/kevinlin311tw/caffe-augmentation 여기인데 Train phase 만, Image Data Type만 지원합니다. 제 PC 환경에서는 Image Data Type 과 LMDB 로 Train 하는것은.. 약 3배 정도 차이납니다.


그래서 Data Augmentaion 을 추가로 만들어 보았습니다. https://github.com/ttagu99/caffe/tree/windows

 DATA AUGUMENTATION 을 추가합니다. 사용은 아래의 예처럼 쓰면되는데, 주의 할 점은 기존에는 crop_size에 값을 입력할 경우, ramdomly crop을 하게 되는데 변경된 코드에서는 crop_offset_rand를 true로 해줘야 합니다.

  1. layer {
  2. name: "train-data"
  3. type: "Data"
  4. top: "data"
  5. top: "label"
  6. include {
  7. phase: TRAIN
  8. }
  9. transform_param {
  10. mirror: true
  11. flip_hor: true
  12. crop_size: 300
  13. crop_offset_rand: true
  14. mean_file: "CAR_DISTANCE/train.binaryproto"
  15. contrast_adjustment: true
  16. smooth_filtering: true
  17. jpeg_compression: true
  18. rotation_angle_interval: 0
  19. display: false
  20. }
  21. data_param {
  22. source: "CAR_DISTANCE/Train_out/"
  23. batch_size: 10
  24. backend: LMDB
  25. }
  26. }
  27. layer {
  28. name: "val-data"
  29. type: "Data"
  30. top: "data"
  31. top: "label"
  32. include {
  33. phase: TEST
  34. }
  35. transform_param {
  36. mirror: true
  37. flip_hor: true
  38. crop_size: 300
  39.     crop_offset_rand: true
  40. mean_file: "CAR_DISTANCE/validation.binaryproto"
  41.     contrast_adjustment: true
  42. smooth_filtering: true
  43. jpeg_compression: true
  44.     rotation_angle_interval: 0
  45. display: false
  46. }
  47. data_param {
  48. source: "CAR_DISTANCE/Validation_out/"
  49. batch_size: 10
  50. backend: LMDB
  51. }
  52. }

  lmdb type 및 image data tpye 모두 가능합니다. train phase, test phase 모두 가능합니다. @kevinlin311tw/caffe-augmentation 를 기반으로 만들었습니다. Thank you for your inspiration!

댓글 2개:

  1. 글 잘보았습니다. 이미 컴파일된 caffe에다가 적용하려면 어떻게(컴파일)하면 되는지 알려주실수 있으세요?

    답글삭제
    답글
    1. 다른 코드로 이미 컴파일 된것이라면 안되구요. git에서 코드 받은 다음 컴파일 하시거나, augmentation 부분만 업데이트하고 컴파일 하시거나 해야합니다.

      삭제