Skip to content

Commit ab9789e

Browse files
garlicvreadraymond
andauthored
beginner/saving_loading_models 추가 번역 (#609)
* saving_loading_models.py torchScript 미번역분 번역 ### Motivation - TorchScript 부분 미번역 문단 ### Key Changes - TorchScript 미번역 문단 국문 번역 - 코드 주석 번역 추가 ### To Reviewers - 오픈소스 첫 기여라 재밌습니다 ㅎㅎ * 오타 수정: Line 240, 기 -> 삭제 * 오타 수정: Line 21, 올 -> 위치 수정 Co-authored-by: raymond <try2quit@korea.ac.kr>
1 parent fa611a6 commit ab9789e

1 file changed

Lines changed: 27 additions & 29 deletions

File tree

beginner_source/saving_loading_models.py

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
1414
1) `torch.save <https://pytorch.org/docs/stable/torch.html?highlight=save#torch.save>`__:
1515
직렬화된 객체를 디스크에 저장합니다. 이 함수는 Python의
16-
`pickle <https://docs.python.org/3/library/pickle.html>`__ 을 사용하여 직렬화합니다
16+
`pickle <https://docs.python.org/3/library/pickle.html>`__ 을 사용하여 직렬화합니다.
1717
이 함수를 사용하여 모든 종류의 객체의 모델, Tensor 및 사전을 저장할 수 있습니다.
1818
1919
2) `torch.load <https://pytorch.org/docs/stable/torch.html?highlight=torch%20load#torch.load>`__:
2020
`pickle <https://docs.python.org/3/library/pickle.html>`__\ 을 사용하여
21-
저장된 객체 파일들을 역직렬화하여 메모리에 올립니다. 이 함수는 데이터를 장치에
22-
불러올 때도 사용합니다.
23-
(`장치간 모델 저장하기 & 불러오기 <#device>`__ 참고)
21+
저장된 객체 파일들을 역직렬화하여 메모리에 올립니다. 이 함수는 데이터를 장치에 불러올
22+
때에도 사용됩니다.
23+
(`장치 간 모델 저장하기 & 불러오기 <#device>`__ 참고)
2424
2525
3) `torch.nn.Module.load_state_dict <https://pytorch.org/docs/stable/generated/torch.nn.Module.html?highlight=load_state_dict#torch.nn.Module.load_state_dict>`__:
2626
역직렬화된 *state_dict* 를 사용하여 모델의 매개변수들을 불러옵니다.
@@ -145,29 +145,29 @@
145145
# model.eval()
146146
#
147147
# .. note::
148-
# PyTorch 버전 1.6에서는 새로운 Zip파일-기반의 파일 포맷을 사용하도록
149-
# ``torch.save`` 가 변경되었습니다. ``torch.load`` 는 예전 방식의 파일들을
148+
# PyTorch 버전 1.6에서는 ``torch.save`` 가 새로운 Zip파일-기반의 파일
149+
# 포맷을 사용하도록 변경되었습니다. ``torch.load`` 는 예전 방식의 파일들을
150150
# 읽어올 수 있도록 하고 있습니다. 어떤 이유에서든 ``torch.save`` 가 예전
151151
# 방식을 사용하도록 하고 싶다면, ``_use_new_zipfile_serialization=False`` 을
152152
# kwarg로 전달하세요.
153153
#
154-
# 추론을 위해 모델을 저장할 때는 학습된 모델의 학습된 매개변수만 저장하면 됩니다.
154+
# 추론을 위해 모델을 저장할 때는 모델의 학습된 매개변수만 저장하면 됩니다.
155155
# ``torch.save()`` 를 사용하여 모델의 *state_dict* 를 저장하는 것이 나중에 모델을
156156
# 사용할 때 가장 유연하게 사용할 수 있는, 모델 저장 시 권장하는 방법입니다.
157157
#
158158
# PyTorch에서는 모델을 저장할 때 ``.pt`` 또는 ``.pth`` 확장자를 사용하는 것이
159159
# 일반적인 규칙입니다.
160160
#
161-
# 추론을 실행하기 전에는 반드시 ``model.eval()`` 을 호출하여 드롭아웃 및 배치
162-
# 정규화를 평가 모드로 설정하여야 합니다. 이것을 하지 않으면 추론 결과가 일관성
163-
# 없게 출력됩니다.
161+
# 추론을 실행하기 전에 반드시 ``model.eval()`` 을 호출하여 드롭아웃 및 배치
162+
# 정규화를 평가 모드로 설정하여야 합니다. 이 과정을 거치지 않으면 일관성 없는
163+
# 추론 결과가 출력됩니다.
164164
#
165165
# .. Note ::
166166
#
167167
# ``load_state_dict()`` 함수에는 저장된 객체의 경로가 아닌, 사전 객체를
168168
# 전달해야 하는 것에 유의하세요. 따라서 저장된 *state_dict* 를 ``load_state_dict()``
169169
# 함수에 전달하기 전에 반드시 역직렬화를 해야 합니다. 예를 들어,
170-
# ``model.load_state_dict(PATH)`` 과 같은 식으로는 사용하면 안됩니다.
170+
# ``model.load_state_dict(PATH)`` 과 같은 식으로 사용하면 안됩니다.
171171
#
172172
# .. Note ::
173173
#
@@ -192,7 +192,7 @@
192192
#
193193
# .. code:: python
194194
#
195-
# # 모델 클래스는 어딘가에 반드시 선언되어 있어야 합니다
195+
# # 모델 클래스는 어딘가에 반드시 선언되어 있어야 합니다.
196196
# model = torch.load(PATH)
197197
# model.eval()
198198
#
@@ -213,25 +213,23 @@
213213
# 정규화를 평가 모드로 설정하여야 합니다. 이것을 하지 않으면 추론 결과가 일관성
214214
# 없게 출력됩니다.
215215
#
216-
# Export/Load Model in TorchScript Format
216+
# TorchScript 포맷으로 모델 내보내기/가져오기
217217
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
218218
#
219-
# One common way to do inference with a trained model is to use
220-
# `TorchScript <https://pytorch.org/docs/stable/jit.html>`__, an intermediate
221-
# representation of a PyTorch model that can be run in Python as well as in a
222-
# high performance environment like C++. TorchScript is actually the recommended model format
223-
# for scaled inference and deployment.
219+
# 훈련된 모델로 추론을 수행하는 일반적인 방법 중 하나는 `TorchScript <https://pytorch.org/docs/stable/jit.html>`__ 를 사용하는 것입니다.
220+
# TorchScript는 파이썬 환경이나 C++와 같은 고성능 환경에서 실행할 수 있는
221+
# 파이토치 모델의 중간 표현(IR; Intermediate Representation)입니다.
222+
# TorchScript는 확장된 추론 및 배포에 권장되는 모델 형식이기도 합니다.
224223
#
225224
# .. note::
226-
# Using the TorchScript format, you will be able to load the exported model and
227-
# run inference without defining the model class.
225+
# TorchScript 형식을 사용하면 모델 클래스를 정의하지 않고도 내보낸 모델을 읽어 오거나 추론을 실행할 수 있습니다.
228226
#
229227
# **Export:**
230228
#
231229
# .. code:: python
232230
#
233-
# model_scripted = torch.jit.script(model) # Export to TorchScript
234-
# model_scripted.save('model_scripted.pt') # Save
231+
# model_scripted = torch.jit.script(model) # TorchScript 형식으로 내보내기
232+
# model_scripted.save('model_scripted.pt') # 저장하기
235233
#
236234
# **Load:**
237235
#
@@ -240,14 +238,14 @@
240238
# model = torch.jit.load('model_scripted.pt')
241239
# model.eval()
242240
#
243-
# Remember that you must call ``model.eval()`` to set dropout and batch
244-
# normalization layers to evaluation mode before running inference.
245-
# Failing to do this will yield inconsistent inference results.
241+
# 추론 실행 전, 드롭아웃 및 배치(batch) 정규화 레이어를 평가 모드로 설정하기 위해 ``model.eval()`` 을 호출해야
242+
# 합니다. 이 호출 과정이 없으면 일관성 없는 추론 결과가 나타납니다.
246243
#
247-
# For more information on TorchScript, feel free to visit the dedicated
248-
# `tutorials <https://tutorials.pytorch.kr/beginner/Intro_to_TorchScript_tutorial.html>`__.
249-
# You will get familiar with the tracing conversion and learn how to
250-
# run a TorchScript module in a `C++ environment <https://tutorials.pytorch.kr/advanced/cpp_export.html>`__.
244+
# TorchScript에 대한 추가 정보는 전용
245+
# `자습서 <https://tutorials.pytorch.kr/beginner/Intro_to_TorchScript_tutorial.html>`__ 에서 찾을 수 있습니다.
246+
# `C++ 환경 <https://tutorials.pytorch.kr/advanced/cpp_export.html>`__ 문서를 참고하여 트레이싱(Tracing) 변환을
247+
# 수행하는 방법과 C++ 환경에서 TorchScript 모듈을 실행하는 방법을 익힐 수 있습니다.
248+
251249

252250

253251
######################################################################

0 commit comments

Comments
 (0)