# 2.3 Fine-tuning images

기존의 데이터셋 외에 다른 데이터셋을 넣고, Fine tuning을 통해 이미지 분류를 해보도록 하겠습니다.

<figure><img src="/files/8Sa4v7uaP3NSFJrxN3Us" alt=""><figcaption></figcaption></figure>

사용 될 이미지는, 어떤 제조 데이터를 활용해, 해당 데이터가 정상 제품인지 불량제품인지 학습시키고 분류하는 모델을 활용토록 하겠습니다.

Fine Tuning을 위해서는, 학습을 위한 폴더의 구조를 다음과 같이 설정해야합니다.\
폴더 디렉토리 이름은 해당되는 분류 카테고리에 맞는 이름을 지정합니다.

```
input_directory
    |--Ok_image
        |--abc.jpg
        |--def.jpg
    |--Def_image
        |--ghi.jpg
        |--jkl.jpg
    
```

1. 모델 페이지의 아래에 Train Model 항목에 Traning data set 입력란에 아래 주소를 입력합니다.\
   Hyper-parameters는 원하는 만큼 지정하여 학습 할 수 있습니다.&#x20;

```
s3://imagedataset0413/inspection/
```

<figure><img src="/files/Z8xx4pBpur6LRYnCO78b" alt=""><figcaption></figcaption></figure>

2. 세팅이 되었다면 Train버튼을 눌러 학습을 진행해보겠습니다. 학습에는 약 10\~20분의 시간이 소요됩니다.

<figure><img src="/files/Ld4QgCIiAJvgaZUYlTLa" alt=""><figcaption></figcaption></figure>

3. 학습이 완료되었다면, Deploy 버튼을눌러 모델을 배포합니다.
4. 배포가 완료되면, open Notebook 버튼을 눌러 노트북 인스턴스를 활성화 시킵니다.

{% file src="/files/20IsLyY1cJoL8LO5Wli1" %}

{% file src="/files/6lCPHeZewFpB6DS5d86X" %}

&#x20;5\. 위의 두 파일을 다운로드 받은 뒤, 왼쪽의 폴더 버튼을 눌러 파일창을 활성화 시킨 후, 파일을 Drag\&Drop 또는 업로드를 통해 파일을 추가합니다.

<figure><img src="/files/OhSRswxhAzwjsLQWuEHF" alt="" width="361"><figcaption></figcaption></figure>

6. 첫번째 셀과, 두번째 셀의 내용을 다음과 같이 바꾼후, 각 셀을 실행시켜줍니다.

```python
import boto3
from IPython.core.display import HTML

ok_jpg, def_jpg = "ok.jpeg", "def.jpeg"

HTML('<table><tr><td> <img src="ok.jpeg" alt="ok" style="height: 250px;"/> <figcaption>ok.jpeg</figcaption>'
     '</td><td> <img src="def.jpeg" alt="def" style="height: 250px;"/> <figcaption>def.jpeg</figcaption>'
     '</td></tr></table>')
```

```python
images = {}
with open(ok_jpg, 'rb') as file: images[ok_jpg] = file.read()
with open(def_jpg, 'rb') as file: images[def_jpg] = file.read()
```

7. 세번째 셀을 실행하게 되면, 다음과 같은 결과가 나오는 것을 확인 하실 수 있습니다.

<figure><img src="/files/jEFWoXMObgBrV5OQrl9i" alt=""><figcaption></figcaption></figure>

8. 실습이 완료 되었다면, 기존의 모델 페이지로 돌아가 엔드포인트를 삭제합니다.

<figure><img src="/files/S4uRL3mEpmhfEqrxf17U" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cheolmin-ki.gitbook.io/sagemaker-image-workshop/lab2.-image-classification-with-no-code/2.3-fine-tuning-images.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
