import{s as ss,o as ls,n as as}from"../chunks/scheduler.bdbef820.js";import{S as ns,i as ps,g as p,s as a,r,m as is,A as rs,h as i,f as s,c as n,j as ts,u as M,x as f,n as Ms,k as Ct,y as ms,a as l,v as m,d as o,t as c,w as y}from"../chunks/index.33f81d56.js";import{T as os}from"../chunks/Tip.34194030.js";import{C as d}from"../chunks/CodeBlock.3bad7fc9.js";import{D as cs}from"../chunks/DocNotebookDropdown.339158fb.js";import{H as Te,E as ys}from"../chunks/index.e01163b6.js";function fs(je){let J,h=`많은 이미지 캡션 데이터세트에는 이미지당 여러 개의 캡션이 포함되어 있습니다.
이러한 경우, 일반적으로 학습 중에 사용 가능한 캡션 중에서 무작위로 샘플을 추출합니다.`;return{c(){J=p("p"),J.textContent=h},l(w){J=i(w,"P",{"data-svelte-h":!0}),f(J)!=="svelte-82zair"&&(J.textContent=h)},m(w,he){l(w,J,he)},p:as,d(w){w&&s(J)}}}function ds(je){let J,h,w,he,U,ge,j,$e,g,_t=`이미지 캡셔닝(Image captioning)은 주어진 이미지에 대한 캡션을 예측하는 작업입니다.
이미지 캡셔닝은 시각 장애인이 다양한 상황을 탐색하는 데 도움을 줄 수 있도록 시각 장애인을 보조하는 등 실생활에서 흔히 활용됩니다.
따라서 이미지 캡셔닝은 이미지를 설명함으로써 사람들의 콘텐츠 접근성을 개선하는 데 도움이 됩니다.`,Ce,$,kt="이 가이드에서는 소개할 내용은 아래와 같습니다:",_e,C,It="<li>이미지 캡셔닝 모델을 파인튜닝합니다.</li> <li>파인튜닝된 모델을 추론에 사용합니다.</li>",ke,_,Bt="시작하기 전에 필요한 모든 라이브러리가 설치되어 있는지 확인하세요:",Ie,k,Be,I,Wt=`Hugging Face 계정에 로그인하면 모델을 업로드하고 커뮤니티에 공유할 수 있습니다.
토큰을 입력하여 로그인하세요.`,We,B,Ze,W,ve,Z,Zt=`{이미지-캡션} 쌍으로 구성된 데이터세트를 가져오려면 🤗 Dataset 라이브러리를 사용합니다.
PyTorch에서 자신만의 이미지 캡션 데이터세트를 만들려면 <a href="https://github.com/NielsRogge/Transformers-Tutorials/blob/master/GIT/Fine_tune_GIT_on_an_image_captioning_dataset.ipynb" rel="nofollow">이 노트북</a>을 참조하세요.`,Ge,v,xe,G,Re,x,vt="이 데이터세트는 <code>image</code>와 <code>text</code>라는 두 특성을 가지고 있습니다.",He,u,Xe,R,Gt="<code>train_test_split</code> 메소드를 사용하여 데이터세트의 학습 분할을 학습 및 테스트 세트로 나눕니다:",Ve,H,Ye,X,xt=`학습 세트의 샘플 몇 개를 시각화해 봅시다.
Let’s visualize a couple of samples from the training set.`,Ee,V,Qe,b,Rt='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/sample_training_images_image_cap.png" alt="Sample training images"/>',ze,Y,Ne,E,Ht="데이터세트에는 이미지와 텍스트라는 두 가지 양식이 있기 때문에, 전처리 파이프라인에서 이미지와 캡션을 모두 전처리합니다.",Fe,Q,Xt="전처리 작업을 위해, 파인튜닝하려는 모델에 연결된 프로세서 클래스를 가져옵니다.",Ae,z,Se,N,Vt="프로세서는 내부적으로 크기 조정 및 픽셀 크기 조정을 포함한 이미지 전처리를 수행하고 캡션을 토큰화합니다.",qe,F,Le,A,Yt="데이터세트가 준비되었으니 이제 파인튜닝을 위해 모델을 설정할 수 있습니다.",Pe,S,Ke,q,Et='<a href="https://huggingface.co/microsoft/git-base" rel="nofollow">“microsoft/git-base”</a>를 <a href="https://huggingface.co/docs/transformers/model_doc/auto#transformers.AutoModelForCausalLM" rel="nofollow"><code>AutoModelForCausalLM</code></a> 객체로 가져옵니다.',De,L,Oe,P,et,K,Qt=`이미지 캡션 모델은 일반적으로 <a href="https://huggingface.co/spaces/evaluate-metric/rouge" rel="nofollow">Rouge 점수</a> 또는 <a href="https://huggingface.co/spaces/evaluate-metric/wer" rel="nofollow">단어 오류율(Word Error Rate)</a>로 평가합니다.
이 가이드에서는 단어 오류율(WER)을 사용합니다.`,tt,D,zt=`이를 위해 🤗 Evaluate 라이브러리를 사용합니다.
WER의 잠재적 제한 사항 및 기타 문제점은 <a href="https://huggingface.co/spaces/evaluate-metric/wer" rel="nofollow">이 가이드</a>를 참조하세요.`,st,O,lt,ee,at,te,Nt='이제 모델 파인튜닝을 시작할 준비가 되었습니다. 이를 위해 🤗 <a href="/docs/transformers/main/ko/main_classes/trainer#transformers.Trainer">Trainer</a>를 사용합니다.',nt,se,Ft='먼저, <a href="/docs/transformers/main/ko/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a>를 사용하여 학습 인수를 정의합니다.',pt,le,it,ae,At="학습 인수를 데이터세트, 모델과 함께 🤗 Trainer에 전달합니다.",rt,ne,Mt,pe,St='학습을 시작하려면 <a href="/docs/transformers/main/ko/main_classes/trainer#transformers.Trainer">Trainer</a> 객체에서 <a href="/docs/transformers/main/ko/main_classes/trainer#transformers.Trainer.train">train()</a>을 호출하기만 하면 됩니다.',mt,ie,ot,re,qt="학습이 진행되면서 학습 손실이 원활하게 감소하는 것을 볼 수 있습니다.",ct,Me,Lt='학습이 완료되면 모든 사람이 모델을 사용할 수 있도록 <a href="/docs/transformers/main/ko/main_classes/trainer#transformers.Trainer.push_to_hub">push_to_hub()</a> 메소드를 사용하여 모델을 허브에 공유하세요:',yt,me,ft,oe,dt,ce,Pt="<code>test_ds</code>에서 샘플 이미지를 가져와 모델을 테스트합니다.",Jt,ye,wt,T,Kt='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/test_image_image_cap.png" alt="Test image"/>',ut,fe,bt,de,Dt="<code>generate</code>를 호출하고 예측을 디코딩합니다.",Tt,Je,ht,we,Ut,ue,Ot="파인튜닝된 모델이 꽤 괜찮은 캡션을 생성한 것 같습니다!",jt,be,gt,Ue,$t;return U=new Te({props:{title:"이미지 캡셔닝",local:"image-captioning",headingTag:"h1"}}),j=new cs({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/ko/image_captioning.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/ko/pytorch/image_captioning.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/ko/tensorflow/image_captioning.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/ko/image_captioning.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/ko/pytorch/image_captioning.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/ko/tensorflow/image_captioning.ipynb"}]}}),k=new d({props:{code:"cGlwJTIwaW5zdGFsbCUyMHRyYW5zZm9ybWVycyUyMGRhdGFzZXRzJTIwZXZhbHVhdGUlMjAtcSUwQXBpcCUyMGluc3RhbGwlMjBqaXdlciUyMC1x",highlighted:`pip install transformers datasets evaluate -q
pip install jiwer -q`,wrap:!1}}),B=new d({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

notebook_login()`,wrap:!1}}),W=new Te({props:{title:"포켓몬 BLIP 캡션 데이터세트 가져오기",local:"load-the-pokmon-blip-captions-dataset",headingTag:"h2"}}),v=new d({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBZHMlMjAlM0QlMjBsb2FkX2RhdGFzZXQoJTIybGFtYmRhbGFicyUyRnBva2Vtb24tYmxpcC1jYXB0aW9ucyUyMiklMEFkcw==",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

ds = load_dataset(<span class="hljs-string">&quot;lambdalabs/pokemon-blip-captions&quot;</span>)
ds`,wrap:!1}}),G=new d({props:{code:"RGF0YXNldERpY3QoJTdCJTBBJTIwJTIwJTIwJTIwdHJhaW4lM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ2ltYWdlJyUyQyUyMCd0ZXh0JyU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwODMzJTBBJTIwJTIwJTIwJTIwJTdEKSUwQSU3RCk=",highlighted:`DatasetDict({
    train: Dataset({
        features: [<span class="hljs-string">&#x27;image&#x27;</span>, <span class="hljs-string">&#x27;text&#x27;</span>],
        num_rows: 833
    })
})`,wrap:!1}}),u=new os({props:{$$slots:{default:[fs]},$$scope:{ctx:je}}}),H=new d({props:{code:"ZHMlMjAlM0QlMjBkcyU1QiUyMnRyYWluJTIyJTVELnRyYWluX3Rlc3Rfc3BsaXQodGVzdF9zaXplJTNEMC4xKSUwQXRyYWluX2RzJTIwJTNEJTIwZHMlNUIlMjJ0cmFpbiUyMiU1RCUwQXRlc3RfZHMlMjAlM0QlMjBkcyU1QiUyMnRlc3QlMjIlNUQ=",highlighted:`ds = ds[<span class="hljs-string">&quot;train&quot;</span>].train_test_split(test_size=<span class="hljs-number">0.1</span>)
train_ds = ds[<span class="hljs-string">&quot;train&quot;</span>]
test_ds = ds[<span class="hljs-string">&quot;test&quot;</span>]`,wrap:!1}}),V=new d({props:{code:"ZnJvbSUyMHRleHR3cmFwJTIwaW1wb3J0JTIwd3JhcCUwQWltcG9ydCUyMG1hdHBsb3RsaWIucHlwbG90JTIwYXMlMjBwbHQlMEFpbXBvcnQlMjBudW1weSUyMGFzJTIwbnAlMEElMEElMEFkZWYlMjBwbG90X2ltYWdlcyhpbWFnZXMlMkMlMjBjYXB0aW9ucyklM0ElMEElMjAlMjAlMjAlMjBwbHQuZmlndXJlKGZpZ3NpemUlM0QoMjAlMkMlMjAyMCkpJTBBJTIwJTIwJTIwJTIwZm9yJTIwaSUyMGluJTIwcmFuZ2UobGVuKGltYWdlcykpJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYXglMjAlM0QlMjBwbHQuc3VicGxvdCgxJTJDJTIwbGVuKGltYWdlcyklMkMlMjBpJTIwJTJCJTIwMSklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBjYXB0aW9uJTIwJTNEJTIwY2FwdGlvbnMlNUJpJTVEJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwY2FwdGlvbiUyMCUzRCUyMCUyMiU1Q24lMjIuam9pbih3cmFwKGNhcHRpb24lMkMlMjAxMikpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcGx0LnRpdGxlKGNhcHRpb24pJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcGx0Lmltc2hvdyhpbWFnZXMlNUJpJTVEKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHBsdC5heGlzKCUyMm9mZiUyMiklMEElMEElMEFzYW1wbGVfaW1hZ2VzX3RvX3Zpc3VhbGl6ZSUyMCUzRCUyMCU1Qm5wLmFycmF5KHRyYWluX2RzJTVCaSU1RCU1QiUyMmltYWdlJTIyJTVEKSUyMGZvciUyMGklMjBpbiUyMHJhbmdlKDUpJTVEJTBBc2FtcGxlX2NhcHRpb25zJTIwJTNEJTIwJTVCdHJhaW5fZHMlNUJpJTVEJTVCJTIydGV4dCUyMiU1RCUyMGZvciUyMGklMjBpbiUyMHJhbmdlKDUpJTVEJTBBcGxvdF9pbWFnZXMoc2FtcGxlX2ltYWdlc190b192aXN1YWxpemUlMkMlMjBzYW1wbGVfY2FwdGlvbnMp",highlighted:`<span class="hljs-keyword">from</span> textwrap <span class="hljs-keyword">import</span> wrap
<span class="hljs-keyword">import</span> matplotlib.pyplot <span class="hljs-keyword">as</span> plt
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np


<span class="hljs-keyword">def</span> <span class="hljs-title function_">plot_images</span>(<span class="hljs-params">images, captions</span>):
    plt.figure(figsize=(<span class="hljs-number">20</span>, <span class="hljs-number">20</span>))
    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(images)):
        ax = plt.subplot(<span class="hljs-number">1</span>, <span class="hljs-built_in">len</span>(images), i + <span class="hljs-number">1</span>)
        caption = captions[i]
        caption = <span class="hljs-string">&quot;\\n&quot;</span>.join(wrap(caption, <span class="hljs-number">12</span>))
        plt.title(caption)
        plt.imshow(images[i])
        plt.axis(<span class="hljs-string">&quot;off&quot;</span>)


sample_images_to_visualize = [np.array(train_ds[i][<span class="hljs-string">&quot;image&quot;</span>]) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">5</span>)]
sample_captions = [train_ds[i][<span class="hljs-string">&quot;text&quot;</span>] <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">5</span>)]
plot_images(sample_images_to_visualize, sample_captions)`,wrap:!1}}),Y=new Te({props:{title:"데이터세트 전처리",local:"preprocess-the-dataset",headingTag:"h2"}}),z=new d({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Qcm9jZXNzb3IlMEElMEFjaGVja3BvaW50JTIwJTNEJTIwJTIybWljcm9zb2Z0JTJGZ2l0LWJhc2UlMjIlMEFwcm9jZXNzb3IlMjAlM0QlMjBBdXRvUHJvY2Vzc29yLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoProcessor

checkpoint = <span class="hljs-string">&quot;microsoft/git-base&quot;</span>
processor = AutoProcessor.from_pretrained(checkpoint)`,wrap:!1}}),F=new d({props:{code:"ZGVmJTIwdHJhbnNmb3JtcyhleGFtcGxlX2JhdGNoKSUzQSUwQSUyMCUyMCUyMCUyMGltYWdlcyUyMCUzRCUyMCU1QnglMjBmb3IlMjB4JTIwaW4lMjBleGFtcGxlX2JhdGNoJTVCJTIyaW1hZ2UlMjIlNUQlNUQlMEElMjAlMjAlMjAlMjBjYXB0aW9ucyUyMCUzRCUyMCU1QnglMjBmb3IlMjB4JTIwaW4lMjBleGFtcGxlX2JhdGNoJTVCJTIydGV4dCUyMiU1RCU1RCUwQSUyMCUyMCUyMCUyMGlucHV0cyUyMCUzRCUyMHByb2Nlc3NvcihpbWFnZXMlM0RpbWFnZXMlMkMlMjB0ZXh0JTNEY2FwdGlvbnMlMkMlMjBwYWRkaW5nJTNEJTIybWF4X2xlbmd0aCUyMiklMEElMjAlMjAlMjAlMjBpbnB1dHMudXBkYXRlKCU3QiUyMmxhYmVscyUyMiUzQSUyMGlucHV0cyU1QiUyMmlucHV0X2lkcyUyMiU1RCU3RCklMEElMjAlMjAlMjAlMjByZXR1cm4lMjBpbnB1dHMlMEElMEElMEF0cmFpbl9kcy5zZXRfdHJhbnNmb3JtKHRyYW5zZm9ybXMpJTBBdGVzdF9kcy5zZXRfdHJhbnNmb3JtKHRyYW5zZm9ybXMp",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">transforms</span>(<span class="hljs-params">example_batch</span>):
    images = [x <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> example_batch[<span class="hljs-string">&quot;image&quot;</span>]]
    captions = [x <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> example_batch[<span class="hljs-string">&quot;text&quot;</span>]]
    inputs = processor(images=images, text=captions, padding=<span class="hljs-string">&quot;max_length&quot;</span>)
    inputs.update({<span class="hljs-string">&quot;labels&quot;</span>: inputs[<span class="hljs-string">&quot;input_ids&quot;</span>]})
    <span class="hljs-keyword">return</span> inputs


train_ds.set_transform(transforms)
test_ds.set_transform(transforms)`,wrap:!1}}),S=new Te({props:{title:"기본 모델 가져오기",local:"load-a-base-model",headingTag:"h2"}}),L=new d({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTBBJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained(checkpoint)`,wrap:!1}}),P=new Te({props:{title:"평가",local:"evaluate",headingTag:"h2"}}),O=new d({props:{code:"ZnJvbSUyMGV2YWx1YXRlJTIwaW1wb3J0JTIwbG9hZCUwQWltcG9ydCUyMHRvcmNoJTBBJTBBd2VyJTIwJTNEJTIwbG9hZCglMjJ3ZXIlMjIpJTBBJTBBJTBBZGVmJTIwY29tcHV0ZV9tZXRyaWNzKGV2YWxfcHJlZCklM0ElMEElMjAlMjAlMjAlMjBsb2dpdHMlMkMlMjBsYWJlbHMlMjAlM0QlMjBldmFsX3ByZWQlMEElMjAlMjAlMjAlMjBwcmVkaWN0ZWQlMjAlM0QlMjBsb2dpdHMuYXJnbWF4KC0xKSUwQSUyMCUyMCUyMCUyMGRlY29kZWRfbGFiZWxzJTIwJTNEJTIwcHJvY2Vzc29yLmJhdGNoX2RlY29kZShsYWJlbHMlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSklMEElMjAlMjAlMjAlMjBkZWNvZGVkX3ByZWRpY3Rpb25zJTIwJTNEJTIwcHJvY2Vzc29yLmJhdGNoX2RlY29kZShwcmVkaWN0ZWQlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSklMEElMjAlMjAlMjAlMjB3ZXJfc2NvcmUlMjAlM0QlMjB3ZXIuY29tcHV0ZShwcmVkaWN0aW9ucyUzRGRlY29kZWRfcHJlZGljdGlvbnMlMkMlMjByZWZlcmVuY2VzJTNEZGVjb2RlZF9sYWJlbHMpJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwJTdCJTIyd2VyX3Njb3JlJTIyJTNBJTIwd2VyX3Njb3JlJTdE",highlighted:`<span class="hljs-keyword">from</span> evaluate <span class="hljs-keyword">import</span> load
<span class="hljs-keyword">import</span> torch

wer = load(<span class="hljs-string">&quot;wer&quot;</span>)


<span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_metrics</span>(<span class="hljs-params">eval_pred</span>):
    logits, labels = eval_pred
    predicted = logits.argmax(-<span class="hljs-number">1</span>)
    decoded_labels = processor.batch_decode(labels, skip_special_tokens=<span class="hljs-literal">True</span>)
    decoded_predictions = processor.batch_decode(predicted, skip_special_tokens=<span class="hljs-literal">True</span>)
    wer_score = wer.compute(predictions=decoded_predictions, references=decoded_labels)
    <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;wer_score&quot;</span>: wer_score}`,wrap:!1}}),ee=new Te({props:{title:"학습!",local:"train!",headingTag:"h2"}}),le=new d({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluaW5nQXJndW1lbnRzJTJDJTIwVHJhaW5lciUwQSUwQW1vZGVsX25hbWUlMjAlM0QlMjBjaGVja3BvaW50LnNwbGl0KCUyMiUyRiUyMiklNUIxJTVEJTBBJTBBdHJhaW5pbmdfYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKCUwQSUyMCUyMCUyMCUyMG91dHB1dF9kaXIlM0RmJTIyJTdCbW9kZWxfbmFtZSU3RC1wb2tlbW9uJTIyJTJDJTBBJTIwJTIwJTIwJTIwbGVhcm5pbmdfcmF0ZSUzRDVlLTUlMkMlMEElMjAlMjAlMjAlMjBudW1fdHJhaW5fZXBvY2hzJTNENTAlMkMlMEElMjAlMjAlMjAlMjBmcDE2JTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMHBlcl9kZXZpY2VfdHJhaW5fYmF0Y2hfc2l6ZSUzRDMyJTJDJTBBJTIwJTIwJTIwJTIwcGVyX2RldmljZV9ldmFsX2JhdGNoX3NpemUlM0QzMiUyQyUwQSUyMCUyMCUyMCUyMGdyYWRpZW50X2FjY3VtdWxhdGlvbl9zdGVwcyUzRDIlMkMlMEElMjAlMjAlMjAlMjBzYXZlX3RvdGFsX2xpbWl0JTNEMyUyQyUwQSUyMCUyMCUyMCUyMGV2YWxfc3RyYXRlZ3klM0QlMjJzdGVwcyUyMiUyQyUwQSUyMCUyMCUyMCUyMGV2YWxfc3RlcHMlM0Q1MCUyQyUwQSUyMCUyMCUyMCUyMHNhdmVfc3RyYXRlZ3klM0QlMjJzdGVwcyUyMiUyQyUwQSUyMCUyMCUyMCUyMHNhdmVfc3RlcHMlM0Q1MCUyQyUwQSUyMCUyMCUyMCUyMGxvZ2dpbmdfc3RlcHMlM0Q1MCUyQyUwQSUyMCUyMCUyMCUyMHJlbW92ZV91bnVzZWRfY29sdW1ucyUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwcHVzaF90b19odWIlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwbGFiZWxfbmFtZXMlM0QlNUIlMjJsYWJlbHMlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBsb2FkX2Jlc3RfbW9kZWxfYXRfZW5kJTNEVHJ1ZSUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments, Trainer

model_name = checkpoint.split(<span class="hljs-string">&quot;/&quot;</span>)[<span class="hljs-number">1</span>]

training_args = TrainingArguments(
    output_dir=<span class="hljs-string">f&quot;<span class="hljs-subst">{model_name}</span>-pokemon&quot;</span>,
    learning_rate=<span class="hljs-number">5e-5</span>,
    num_train_epochs=<span class="hljs-number">50</span>,
    fp16=<span class="hljs-literal">True</span>,
    per_device_train_batch_size=<span class="hljs-number">32</span>,
    per_device_eval_batch_size=<span class="hljs-number">32</span>,
    gradient_accumulation_steps=<span class="hljs-number">2</span>,
    save_total_limit=<span class="hljs-number">3</span>,
    eval_strategy=<span class="hljs-string">&quot;steps&quot;</span>,
    eval_steps=<span class="hljs-number">50</span>,
    save_strategy=<span class="hljs-string">&quot;steps&quot;</span>,
    save_steps=<span class="hljs-number">50</span>,
    logging_steps=<span class="hljs-number">50</span>,
    remove_unused_columns=<span class="hljs-literal">False</span>,
    push_to_hub=<span class="hljs-literal">True</span>,
    label_names=[<span class="hljs-string">&quot;labels&quot;</span>],
    load_best_model_at_end=<span class="hljs-literal">True</span>,
)`,wrap:!1}}),ne=new d({props:{code:"dHJhaW5lciUyMCUzRCUyMFRyYWluZXIoJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0Rtb2RlbCUyQyUwQSUyMCUyMCUyMCUyMGFyZ3MlM0R0cmFpbmluZ19hcmdzJTJDJTBBJTIwJTIwJTIwJTIwdHJhaW5fZGF0YXNldCUzRHRyYWluX2RzJTJDJTBBJTIwJTIwJTIwJTIwZXZhbF9kYXRhc2V0JTNEdGVzdF9kcyUyQyUwQSUyMCUyMCUyMCUyMGNvbXB1dGVfbWV0cmljcyUzRGNvbXB1dGVfbWV0cmljcyUyQyUwQSk=",highlighted:`trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=train_ds,
    eval_dataset=test_ds,
    compute_metrics=compute_metrics,
)`,wrap:!1}}),ie=new d({props:{code:"dHJhaW5lci50cmFpbigp",highlighted:"trainer.train()",wrap:!1}}),me=new d({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yigp",highlighted:"trainer.push_to_hub()",wrap:!1}}),oe=new Te({props:{title:"추론",local:"inference",headingTag:"h2"}}),ye=new d({props:{code:"ZnJvbSUyMFBJTCUyMGltcG9ydCUyMEltYWdlJTBBaW1wb3J0JTIwcmVxdWVzdHMlMEElMEF1cmwlMjAlM0QlMjAlMjJodHRwcyUzQSUyRiUyRmh1Z2dpbmdmYWNlLmNvJTJGZGF0YXNldHMlMkZzYXlha3BhdWwlMkZzYW1wbGUtZGF0YXNldHMlMkZyZXNvbHZlJTJGbWFpbiUyRnBva2Vtb24ucG5nJTIyJTBBaW1hZ2UlMjAlM0QlMjBJbWFnZS5vcGVuKHJlcXVlc3RzLmdldCh1cmwlMkMlMjBzdHJlYW0lM0RUcnVlKS5yYXcpJTBBaW1hZ2U=",highlighted:`<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
<span class="hljs-keyword">import</span> requests

url = <span class="hljs-string">&quot;https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png&quot;</span>
image = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw)
image`,wrap:!1}}),fe=new d({props:{code:"ZGV2aWNlJTIwJTNEJTIwJTIyY3VkYSUyMiUyMGlmJTIwdG9yY2guY3VkYS5pc19hdmFpbGFibGUoKSUyMGVsc2UlMjAlMjJjcHUlMjIlMEElMEFpbnB1dHMlMjAlM0QlMjBwcm9jZXNzb3IoaW1hZ2VzJTNEaW1hZ2UlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKS50byhkZXZpY2UpJTBBcGl4ZWxfdmFsdWVzJTIwJTNEJTIwaW5wdXRzLnBpeGVsX3ZhbHVlcw==",highlighted:`device = <span class="hljs-string">&quot;cuda&quot;</span> <span class="hljs-keyword">if</span> torch.cuda.is_available() <span class="hljs-keyword">else</span> <span class="hljs-string">&quot;cpu&quot;</span>

inputs = processor(images=image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(device)
pixel_values = inputs.pixel_values`,wrap:!1}}),Je=new d({props:{code:"Z2VuZXJhdGVkX2lkcyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKHBpeGVsX3ZhbHVlcyUzRHBpeGVsX3ZhbHVlcyUyQyUyMG1heF9sZW5ndGglM0Q1MCklMEFnZW5lcmF0ZWRfY2FwdGlvbiUyMCUzRCUyMHByb2Nlc3Nvci5iYXRjaF9kZWNvZGUoZ2VuZXJhdGVkX2lkcyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSU1QjAlNUQlMEFwcmludChnZW5lcmF0ZWRfY2FwdGlvbik=",highlighted:`generated_ids = model.generate(pixel_values=pixel_values, max_length=<span class="hljs-number">50</span>)
generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>]
<span class="hljs-built_in">print</span>(generated_caption)`,wrap:!1}}),we=new d({props:{code:"YSUyMGRyYXdpbmclMjBvZiUyMGElMjBwaW5rJTIwYW5kJTIwYmx1ZSUyMHBva2Vtb24=",highlighted:"a drawing of a pink and blue pokemon",wrap:!1}}),be=new ys({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/ko/tasks/image_captioning.md"}}),{c(){J=p("meta"),h=a(),w=p("p"),he=a(),r(U.$$.fragment),ge=a(),r(j.$$.fragment),$e=a(),g=p("p"),g.textContent=_t,Ce=a(),$=p("p"),$.textContent=kt,_e=a(),C=p("ul"),C.innerHTML=It,ke=a(),_=p("p"),_.textContent=Bt,Ie=a(),r(k.$$.fragment),Be=a(),I=p("p"),I.textContent=Wt,We=a(),r(B.$$.fragment),Ze=a(),r(W.$$.fragment),ve=a(),Z=p("p"),Z.innerHTML=Zt,Ge=a(),r(v.$$.fragment),xe=a(),r(G.$$.fragment),Re=a(),x=p("p"),x.innerHTML=vt,He=a(),r(u.$$.fragment),Xe=a(),R=p("p"),R.innerHTML=Gt,Ve=a(),r(H.$$.fragment),Ye=a(),X=p("p"),X.textContent=xt,Ee=a(),r(V.$$.fragment),Qe=a(),b=p("div"),b.innerHTML=Rt,ze=a(),r(Y.$$.fragment),Ne=a(),E=p("p"),E.textContent=Ht,Fe=a(),Q=p("p"),Q.textContent=Xt,Ae=a(),r(z.$$.fragment),Se=a(),N=p("p"),N.textContent=Vt,qe=a(),r(F.$$.fragment),Le=a(),A=p("p"),A.textContent=Yt,Pe=a(),r(S.$$.fragment),Ke=a(),q=p("p"),q.innerHTML=Et,De=a(),r(L.$$.fragment),Oe=a(),r(P.$$.fragment),et=a(),K=p("p"),K.innerHTML=Qt,tt=a(),D=p("p"),D.innerHTML=zt,st=a(),r(O.$$.fragment),lt=a(),r(ee.$$.fragment),at=a(),te=p("p"),te.innerHTML=Nt,nt=a(),se=p("p"),se.innerHTML=Ft,pt=a(),r(le.$$.fragment),it=a(),ae=p("p"),ae.textContent=At,rt=a(),r(ne.$$.fragment),Mt=a(),pe=p("p"),pe.innerHTML=St,mt=a(),r(ie.$$.fragment),ot=a(),re=p("p"),re.textContent=qt,ct=a(),Me=p("p"),Me.innerHTML=Lt,yt=a(),r(me.$$.fragment),ft=a(),r(oe.$$.fragment),dt=a(),ce=p("p"),ce.innerHTML=Pt,Jt=a(),r(ye.$$.fragment),wt=a(),T=p("div"),T.innerHTML=Kt,ut=is(`
    
모델에 사용할 이미지를 준비합니다.

	`),r(fe.$$.fragment),bt=a(),de=p("p"),de.innerHTML=Dt,Tt=a(),r(Je.$$.fragment),ht=a(),r(we.$$.fragment),Ut=a(),ue=p("p"),ue.textContent=Ot,jt=a(),r(be.$$.fragment),gt=a(),Ue=p("p"),this.h()},l(e){const t=rs("svelte-u9bgzb",document.head);J=i(t,"META",{name:!0,content:!0}),t.forEach(s),h=n(e),w=i(e,"P",{}),ts(w).forEach(s),he=n(e),M(U.$$.fragment,e),ge=n(e),M(j.$$.fragment,e),$e=n(e),g=i(e,"P",{"data-svelte-h":!0}),f(g)!=="svelte-1sz2sm4"&&(g.textContent=_t),Ce=n(e),$=i(e,"P",{"data-svelte-h":!0}),f($)!=="svelte-tq3033"&&($.textContent=kt),_e=n(e),C=i(e,"UL",{"data-svelte-h":!0}),f(C)!=="svelte-htt0z1"&&(C.innerHTML=It),ke=n(e),_=i(e,"P",{"data-svelte-h":!0}),f(_)!=="svelte-18iigii"&&(_.textContent=Bt),Ie=n(e),M(k.$$.fragment,e),Be=n(e),I=i(e,"P",{"data-svelte-h":!0}),f(I)!=="svelte-9xxxb4"&&(I.textContent=Wt),We=n(e),M(B.$$.fragment,e),Ze=n(e),M(W.$$.fragment,e),ve=n(e),Z=i(e,"P",{"data-svelte-h":!0}),f(Z)!=="svelte-fdtyxx"&&(Z.innerHTML=Zt),Ge=n(e),M(v.$$.fragment,e),xe=n(e),M(G.$$.fragment,e),Re=n(e),x=i(e,"P",{"data-svelte-h":!0}),f(x)!=="svelte-1ff7g97"&&(x.innerHTML=vt),He=n(e),M(u.$$.fragment,e),Xe=n(e),R=i(e,"P",{"data-svelte-h":!0}),f(R)!=="svelte-1pxdo64"&&(R.innerHTML=Gt),Ve=n(e),M(H.$$.fragment,e),Ye=n(e),X=i(e,"P",{"data-svelte-h":!0}),f(X)!=="svelte-1xgsiym"&&(X.textContent=xt),Ee=n(e),M(V.$$.fragment,e),Qe=n(e),b=i(e,"DIV",{class:!0,"data-svelte-h":!0}),f(b)!=="svelte-1qemygy"&&(b.innerHTML=Rt),ze=n(e),M(Y.$$.fragment,e),Ne=n(e),E=i(e,"P",{"data-svelte-h":!0}),f(E)!=="svelte-15c40fh"&&(E.textContent=Ht),Fe=n(e),Q=i(e,"P",{"data-svelte-h":!0}),f(Q)!=="svelte-aj1022"&&(Q.textContent=Xt),Ae=n(e),M(z.$$.fragment,e),Se=n(e),N=i(e,"P",{"data-svelte-h":!0}),f(N)!=="svelte-lek9ik"&&(N.textContent=Vt),qe=n(e),M(F.$$.fragment,e),Le=n(e),A=i(e,"P",{"data-svelte-h":!0}),f(A)!=="svelte-x9apz1"&&(A.textContent=Yt),Pe=n(e),M(S.$$.fragment,e),Ke=n(e),q=i(e,"P",{"data-svelte-h":!0}),f(q)!=="svelte-1ifqfke"&&(q.innerHTML=Et),De=n(e),M(L.$$.fragment,e),Oe=n(e),M(P.$$.fragment,e),et=n(e),K=i(e,"P",{"data-svelte-h":!0}),f(K)!=="svelte-1i0maa4"&&(K.innerHTML=Qt),tt=n(e),D=i(e,"P",{"data-svelte-h":!0}),f(D)!=="svelte-gcfhpv"&&(D.innerHTML=zt),st=n(e),M(O.$$.fragment,e),lt=n(e),M(ee.$$.fragment,e),at=n(e),te=i(e,"P",{"data-svelte-h":!0}),f(te)!=="svelte-p56w9f"&&(te.innerHTML=Nt),nt=n(e),se=i(e,"P",{"data-svelte-h":!0}),f(se)!=="svelte-1o8u57q"&&(se.innerHTML=Ft),pt=n(e),M(le.$$.fragment,e),it=n(e),ae=i(e,"P",{"data-svelte-h":!0}),f(ae)!=="svelte-14i42sb"&&(ae.textContent=At),rt=n(e),M(ne.$$.fragment,e),Mt=n(e),pe=i(e,"P",{"data-svelte-h":!0}),f(pe)!=="svelte-1b8l5lh"&&(pe.innerHTML=St),mt=n(e),M(ie.$$.fragment,e),ot=n(e),re=i(e,"P",{"data-svelte-h":!0}),f(re)!=="svelte-cnq009"&&(re.textContent=qt),ct=n(e),Me=i(e,"P",{"data-svelte-h":!0}),f(Me)!=="svelte-2xjidf"&&(Me.innerHTML=Lt),yt=n(e),M(me.$$.fragment,e),ft=n(e),M(oe.$$.fragment,e),dt=n(e),ce=i(e,"P",{"data-svelte-h":!0}),f(ce)!=="svelte-noj8gs"&&(ce.innerHTML=Pt),Jt=n(e),M(ye.$$.fragment,e),wt=n(e),T=i(e,"DIV",{class:!0,"data-svelte-h":!0}),f(T)!=="svelte-yvzmn4"&&(T.innerHTML=Kt),ut=Ms(e,`
    
모델에 사용할 이미지를 준비합니다.

	`),M(fe.$$.fragment,e),bt=n(e),de=i(e,"P",{"data-svelte-h":!0}),f(de)!=="svelte-1o736s1"&&(de.innerHTML=Dt),Tt=n(e),M(Je.$$.fragment,e),ht=n(e),M(we.$$.fragment,e),Ut=n(e),ue=i(e,"P",{"data-svelte-h":!0}),f(ue)!=="svelte-1ye6o6q"&&(ue.textContent=Ot),jt=n(e),M(be.$$.fragment,e),gt=n(e),Ue=i(e,"P",{}),ts(Ue).forEach(s),this.h()},h(){Ct(J,"name","hf:doc:metadata"),Ct(J,"content",Js),Ct(b,"class","flex justify-center"),Ct(T,"class","flex justify-center")},m(e,t){ms(document.head,J),l(e,h,t),l(e,w,t),l(e,he,t),m(U,e,t),l(e,ge,t),m(j,e,t),l(e,$e,t),l(e,g,t),l(e,Ce,t),l(e,$,t),l(e,_e,t),l(e,C,t),l(e,ke,t),l(e,_,t),l(e,Ie,t),m(k,e,t),l(e,Be,t),l(e,I,t),l(e,We,t),m(B,e,t),l(e,Ze,t),m(W,e,t),l(e,ve,t),l(e,Z,t),l(e,Ge,t),m(v,e,t),l(e,xe,t),m(G,e,t),l(e,Re,t),l(e,x,t),l(e,He,t),m(u,e,t),l(e,Xe,t),l(e,R,t),l(e,Ve,t),m(H,e,t),l(e,Ye,t),l(e,X,t),l(e,Ee,t),m(V,e,t),l(e,Qe,t),l(e,b,t),l(e,ze,t),m(Y,e,t),l(e,Ne,t),l(e,E,t),l(e,Fe,t),l(e,Q,t),l(e,Ae,t),m(z,e,t),l(e,Se,t),l(e,N,t),l(e,qe,t),m(F,e,t),l(e,Le,t),l(e,A,t),l(e,Pe,t),m(S,e,t),l(e,Ke,t),l(e,q,t),l(e,De,t),m(L,e,t),l(e,Oe,t),m(P,e,t),l(e,et,t),l(e,K,t),l(e,tt,t),l(e,D,t),l(e,st,t),m(O,e,t),l(e,lt,t),m(ee,e,t),l(e,at,t),l(e,te,t),l(e,nt,t),l(e,se,t),l(e,pt,t),m(le,e,t),l(e,it,t),l(e,ae,t),l(e,rt,t),m(ne,e,t),l(e,Mt,t),l(e,pe,t),l(e,mt,t),m(ie,e,t),l(e,ot,t),l(e,re,t),l(e,ct,t),l(e,Me,t),l(e,yt,t),m(me,e,t),l(e,ft,t),m(oe,e,t),l(e,dt,t),l(e,ce,t),l(e,Jt,t),m(ye,e,t),l(e,wt,t),l(e,T,t),l(e,ut,t),m(fe,e,t),l(e,bt,t),l(e,de,t),l(e,Tt,t),m(Je,e,t),l(e,ht,t),m(we,e,t),l(e,Ut,t),l(e,ue,t),l(e,jt,t),m(be,e,t),l(e,gt,t),l(e,Ue,t),$t=!0},p(e,[t]){const es={};t&2&&(es.$$scope={dirty:t,ctx:e}),u.$set(es)},i(e){$t||(o(U.$$.fragment,e),o(j.$$.fragment,e),o(k.$$.fragment,e),o(B.$$.fragment,e),o(W.$$.fragment,e),o(v.$$.fragment,e),o(G.$$.fragment,e),o(u.$$.fragment,e),o(H.$$.fragment,e),o(V.$$.fragment,e),o(Y.$$.fragment,e),o(z.$$.fragment,e),o(F.$$.fragment,e),o(S.$$.fragment,e),o(L.$$.fragment,e),o(P.$$.fragment,e),o(O.$$.fragment,e),o(ee.$$.fragment,e),o(le.$$.fragment,e),o(ne.$$.fragment,e),o(ie.$$.fragment,e),o(me.$$.fragment,e),o(oe.$$.fragment,e),o(ye.$$.fragment,e),o(fe.$$.fragment,e),o(Je.$$.fragment,e),o(we.$$.fragment,e),o(be.$$.fragment,e),$t=!0)},o(e){c(U.$$.fragment,e),c(j.$$.fragment,e),c(k.$$.fragment,e),c(B.$$.fragment,e),c(W.$$.fragment,e),c(v.$$.fragment,e),c(G.$$.fragment,e),c(u.$$.fragment,e),c(H.$$.fragment,e),c(V.$$.fragment,e),c(Y.$$.fragment,e),c(z.$$.fragment,e),c(F.$$.fragment,e),c(S.$$.fragment,e),c(L.$$.fragment,e),c(P.$$.fragment,e),c(O.$$.fragment,e),c(ee.$$.fragment,e),c(le.$$.fragment,e),c(ne.$$.fragment,e),c(ie.$$.fragment,e),c(me.$$.fragment,e),c(oe.$$.fragment,e),c(ye.$$.fragment,e),c(fe.$$.fragment,e),c(Je.$$.fragment,e),c(we.$$.fragment,e),c(be.$$.fragment,e),$t=!1},d(e){e&&(s(h),s(w),s(he),s(ge),s($e),s(g),s(Ce),s($),s(_e),s(C),s(ke),s(_),s(Ie),s(Be),s(I),s(We),s(Ze),s(ve),s(Z),s(Ge),s(xe),s(Re),s(x),s(He),s(Xe),s(R),s(Ve),s(Ye),s(X),s(Ee),s(Qe),s(b),s(ze),s(Ne),s(E),s(Fe),s(Q),s(Ae),s(Se),s(N),s(qe),s(Le),s(A),s(Pe),s(Ke),s(q),s(De),s(Oe),s(et),s(K),s(tt),s(D),s(st),s(lt),s(at),s(te),s(nt),s(se),s(pt),s(it),s(ae),s(rt),s(Mt),s(pe),s(mt),s(ot),s(re),s(ct),s(Me),s(yt),s(ft),s(dt),s(ce),s(Jt),s(wt),s(T),s(ut),s(bt),s(de),s(Tt),s(ht),s(Ut),s(ue),s(jt),s(gt),s(Ue)),s(J),y(U,e),y(j,e),y(k,e),y(B,e),y(W,e),y(v,e),y(G,e),y(u,e),y(H,e),y(V,e),y(Y,e),y(z,e),y(F,e),y(S,e),y(L,e),y(P,e),y(O,e),y(ee,e),y(le,e),y(ne,e),y(ie,e),y(me,e),y(oe,e),y(ye,e),y(fe,e),y(Je,e),y(we,e),y(be,e)}}}const Js='{"title":"이미지 캡셔닝","local":"image-captioning","sections":[{"title":"포켓몬 BLIP 캡션 데이터세트 가져오기","local":"load-the-pokmon-blip-captions-dataset","sections":[],"depth":2},{"title":"데이터세트 전처리","local":"preprocess-the-dataset","sections":[],"depth":2},{"title":"기본 모델 가져오기","local":"load-a-base-model","sections":[],"depth":2},{"title":"평가","local":"evaluate","sections":[],"depth":2},{"title":"학습!","local":"train!","sections":[],"depth":2},{"title":"추론","local":"inference","sections":[],"depth":2}],"depth":1}';function ws(je){return ls(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class gs extends ns{constructor(J){super(),ps(this,J,ws,ds,ss,{})}}export{gs as component};
