Command로 Category 생성하기

작성자 이호영 수정일 2022-10-28 11:11

들어가며

  • Twinreader UI 없이 Command를 사용하여 문서 분류에 사용하는 카테고리를 생성하는 방법에 대해 알아봅니다.


사전 배경 지식

  • input : Twinreader에 요청된 이미지의 저장 경로
    /Data_Home/twinreader/data/input

  • convert : input에 저장된 요청 이미지를 png 로 인코딩하여 저장하는 경로

    /Data_Home/twinreader/data/convert


  • output : 요청 이미지에 대한 Twinreader 분석 결과를 저장하는 경로

    /Data_Home/twinreader/data/output



Category 생성하기

요청 이미지가 저장될 경로를 생성해줍니다.
cd /agilesoda/data/twinreader/input/
mkdir agileImg
  • agileImg : 이미지 분석 요청 ID로 중복되지 않도록 주의합니다.


분석에 사용 될 이미지를 input 경로에 넣어줍니다.
cd /agilesoda/twinreader/data/input/agileImg
ls -al
-rw-r--r--   1 root root 725571 Oct 12 11:32 image_1.jpg


curl을 사용하여 twinreader로 이미지 분석을 요청합니다.
curl http://10.1.1.70:8080/twinreader-mgr-service/api/v1/analysis/inference/reqId --request POST --header "Content-Type: application/json" --data '{"requestId":"agileImg", "images": ["/image_1.jpg"]}'
  • 분류하고자 할 문서의 대표적인 문서 형태를 twinreader에 등록하기 위한 과정 중 하나입니다.
  • requestId : 이미지 분석 요청 ID로 중복되지 않도록 변경하여 요청합니다.


Twinreader 경로에 convert, output 디렉터리가 생성되었는지 확인합니다.
cd /agilesoda/twinreader/data
ls -al
drwxr-xr-x. 10 twrd twrd 4096 Oct 12 13:18 convert
drwxr-xr-x. 13 twrd twrd 4096 Oct 12 11:32 input
drwxr-xr-x. 12 twrd twrd 4096 Oct 12 13:19 output


output 경로에 이미지 분석 요청 ID로 디렉터리가 생성되었는지 확인합니다.
cd /agilesoda/data/twinreader/output
ls -al 
drwxr-xr-x. 12 twrd twrd 4096 Oct 12 13:19 agileImg


이미지 분석 요청 ID로 생성된 디렉터리 내 combined.json 이 생성되었는지 확인합니다.
cd agileImg/image_1_png/image_1_png-1/json
ls -al
-rw-r--r--  1 twrd twrd 62554 Oct 12 13:19 image_1_png-1_combined.json



생성된 combined.json 을 Twinreader의 분류 모델이 참고하는 경로에 넣어줍니다.
cd /[Data_Home]/twinreader/model/model-classification/classification/
ls -al
drwxr-xr-x 5 root root 4096 Sep  9 20:55 1
drwxr-xr-x 3 root root 4096 Sep  9 20:55 2
drwxr-xr-x 6 root root 4096 Sep 26 17:50 4
cd 4
cp /[Data_Home]/twinreader/data/output/agileImg/image_1_png/image_1_png-1/json/image_1_png_1_combined.json ./


Twinreader 내 classification/[model_version]/asset 경로의 label.json을 수정해줍니다.
ls -al
-rw-r--r-- 1 twrd twrd  2047 Oct 12 13:25 label.json

vi label.json
{
     "image_1_png-1_combined.json" : "진료비영수증"
}


Twinreader 내 classification/detail_classification.json를 수정해 줍니다.

cd /[Data_Home]/twinreader/classification
ls -al
-rw-r--r--   1 twrd twrd 1044 Oct 12 14:09 Classification.json
-rw-r--r--.  1 twrd twrd 1545 Oct 12 14:12 detail_classification.json
vi detail_classification.json
[
    {
        "mainCategoryName": "진료비계산서",
        "subCategories": [
            {
                "subCategoryName": "진료비",
                "synonym": ["진료비영수증","진료비"]
            }
        ],
        "subCategorySearchArea": {
                "searchTop": 0,
                "searchBottom": 0
        }
    }
]
  • mainCategoryName
    - 분류하려고 하는 문서 서식으로 위에서 생성한 Category 이름을 넣어줍니다.

  • subCategories
    - Category가 세부적으로 참고할 사항을 정의합니다.

  • subCategorySearchArea
    - subCategory에서 정의한 단어를 문서에서 탐색할 범위를 지정합니다.


classification pod를 재 실행하여 변경한 값을 적용합니다.

kubectl get pod
NAME                                                     READY   STATUS   RESTARTS  AGE
core-server-classification-deployment-678dd7d488-vtzjl    1/1   Running      0      15d
kubectl delete pod core-server-classification-deployment-678dd7d488-vtzjl


마무리

  • 생성된 Category를 사용하여 문서 분류를 할 수 있습니다.
  • combined.json을 twinreader 내 classification 경로에 추가하여 Category를 생성할 수 있습니다.
  • twinreader 내 classification 하위의 폴더 이름이 높을 숫자 일수록 최신 버전입니다.

아티클이 유용했나요?

훌륭합니다!

피드백을 제공해 주셔서 감사합니다.

도움이 되지 못해 죄송합니다!

피드백을 제공해 주셔서 감사합니다.

아티클을 개선할 수 있는 방법을 알려주세요!

최소 하나의 이유를 선택하세요
CAPTCHA 확인이 필요합니다.

피드백 전송

소중한 의견을 수렴하여 아티클을 개선하도록 노력하겠습니다.

02-558-8300