From b5582f8623329d089983f5c9cc7aa17823d17d66 Mon Sep 17 00:00:00 2001 From: totuta Date: Sun, 5 Jun 2016 21:10:56 -0400 Subject: [PATCH 01/63] working on variables/index.. --- g3doc/how_tos/variables/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 9a36cc3..7dba189 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -160,8 +160,8 @@ library, and in particular, the `print_tensors_in_checkpoint_file` function. ### 변수 저장 -Create a `Saver` with `tf.train.Saver()` to manage all variables in -the model. +모델안의 모든 변수를 관리하기 위하여, `tf.train.Saver()`를 사용해 `Saver`를 만드십시요. + ```python # Create some variables. From 05e151918fd49de14dcbe0923878f81ef29e19d4 Mon Sep 17 00:00:00 2001 From: totuta Date: Sun, 5 Jun 2016 22:56:53 -0400 Subject: [PATCH 02/63] working on variables/index.. --- g3doc/how_tos/variables/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 7dba189..0bc6b47 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -187,8 +187,8 @@ with tf.Session() as sess: ### 변수 복구 -The same `Saver` object is used to restore variables. Note that when you -restore variables from a file you do not have to initialize them beforehand. +변수를 복구하는 데에 위의 `Saver` 객체가 사용됩니다. 화일로부터 변수들을 복구하는 경우에는, 그 변수들을 미리 초기화 할 필요가 없습니다. + ```python # Create some variables. From db7b64e6d9d6e08607212bf03316f894c2826682 Mon Sep 17 00:00:00 2001 From: totuta Date: Sun, 5 Jun 2016 23:04:58 -0400 Subject: [PATCH 03/63] working on variables/index.. --- g3doc/how_tos/variables/index.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 0bc6b47..e370c74 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -1,5 +1,7 @@ # 변수: 생성, 초기화, 저장, 복구 +모델을 학습시키는 경우에, 파라미터를 저장하고 업데이트 하기 위하여 [variables](../../api_docs/python/state_ops.md)를 사용합니다. 변수들(variables)는 텐서들을 저장하는 메모리상의 버퍼들입니다. + When you train a model, you use [variables](../../api_docs/python/state_ops.md) to hold and update parameters. Variables are in-memory buffers containing tensors. They must be explicitly initialized and can be saved to disk during From 75aa63dfd3d816bd35aec97afe5b466e02b6f2e5 Mon Sep 17 00:00:00 2001 From: totuta Date: Sun, 5 Jun 2016 23:05:17 -0400 Subject: [PATCH 04/63] working on variables/index.. --- g3doc/how_tos/variables/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index e370c74..d83d54b 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -1,6 +1,6 @@ # 변수: 생성, 초기화, 저장, 복구 -모델을 학습시키는 경우에, 파라미터를 저장하고 업데이트 하기 위하여 [variables](../../api_docs/python/state_ops.md)를 사용합니다. 변수들(variables)는 텐서들을 저장하는 메모리상의 버퍼들입니다. +모델을 학습시키는 경우에, 파라미터를 저장하고 업데이트 하기 위하여 변수들([variables](../../api_docs/python/state_ops.md))를 사용합니다. 변수들(variables)는 텐서들을 저장하는 메모리상의 버퍼들입니다. When you train a model, you use [variables](../../api_docs/python/state_ops.md) to hold and update parameters. Variables are in-memory buffers containing From b1138e5ff515414acf434d0e50bc6e42d9d8a99a Mon Sep 17 00:00:00 2001 From: totuta Date: Sun, 5 Jun 2016 23:07:38 -0400 Subject: [PATCH 05/63] working on variables/index.. --- g3doc/how_tos/variables/index.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index d83d54b..6d5e16a 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -1,12 +1,6 @@ # 변수: 생성, 초기화, 저장, 복구 -모델을 학습시키는 경우에, 파라미터를 저장하고 업데이트 하기 위하여 변수들([variables](../../api_docs/python/state_ops.md))를 사용합니다. 변수들(variables)는 텐서들을 저장하는 메모리상의 버퍼들입니다. - -When you train a model, you use [variables](../../api_docs/python/state_ops.md) -to hold and update parameters. Variables are in-memory buffers containing -tensors. They must be explicitly initialized and can be saved to disk during -and after training. You can later restore saved values to exercise or analyse -the model. +모델을 학습시키는 경우에, 파라미터를 저장하고 업데이트 하기 위하여 변수들([variables](../../api_docs/python/state_ops.md))를 사용합니다. 변수들은 텐서들을 저장하는 메모리상의 버퍼들입니다. 명확하게 초기화 되어야 하며, 학습이 진행되는 동안과 끝난 후에 디스크에 저장될 수 있습니다. 나중에 모델을 사용하거나 분석하기 위하여 저장된 값들을 복구할 수 있습니다. This document references the following TensorFlow classes. Follow the links to their reference manual for a complete description of their API: From cd65345769f33ac32196bd92d4e241baa81455cd Mon Sep 17 00:00:00 2001 From: totuta Date: Sun, 5 Jun 2016 23:10:47 -0400 Subject: [PATCH 06/63] working on variables/index.. --- g3doc/how_tos/variables/index.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 6d5e16a..466ce0d 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -1,12 +1,11 @@ # 변수: 생성, 초기화, 저장, 복구 -모델을 학습시키는 경우에, 파라미터를 저장하고 업데이트 하기 위하여 변수들([variables](../../api_docs/python/state_ops.md))를 사용합니다. 변수들은 텐서들을 저장하는 메모리상의 버퍼들입니다. 명확하게 초기화 되어야 하며, 학습이 진행되는 동안과 끝난 후에 디스크에 저장될 수 있습니다. 나중에 모델을 사용하거나 분석하기 위하여 저장된 값들을 복구할 수 있습니다. +모델을 학습시키는 경우에, 파라미터를 저장하고 업데이트 하기 위하여 변수들([variables](../../api_docs/python/state_ops.md))를 사용합니다. 변수들은 텐서들을 저장하는 메모리상의 버퍼들입니다. 명확하게 초기화 되어야 하며, 학습이 진행되는 동안이나 끝난 후에 디스크에 저장될 수 있습니다. 나중에 모델을 사용하거나 분석하기 위하여 저장된 값들을 복구할 수 있습니다. -This document references the following TensorFlow classes. Follow the links to -their reference manual for a complete description of their API: +이 문서는 다음의 텐서플로우 클래스들을 이용하여 설명을 진행합니다. API에 대한 완전한 설명을 담고 있는 레퍼런스 매뉴얼을 보려면 링크를 참조하십시요. -* The [`tf.Variable`](../../api_docs/python/state_ops.md#Variable) class. -* The [`tf.train.Saver`](../../api_docs/python/state_ops.md#Saver) class. +* [`tf.Variable`](../../api_docs/python/state_ops.md#Variable) 클래스. +* [`tf.train.Saver`](../../api_docs/python/state_ops.md#Saver) 클래스. ## 생성 From 51cd5b3de7721b643e9f509a4586001ce00060b5 Mon Sep 17 00:00:00 2001 From: totuta Date: Sun, 5 Jun 2016 23:12:18 -0400 Subject: [PATCH 07/63] working on variables/index.. --- g3doc/how_tos/variables/index.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 466ce0d..ed5ba52 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -38,7 +38,10 @@ Calling `tf.Variable()` adds several ops to the graph: The value returned by `tf.Variable()` value is an instance of the Python class `tf.Variable`. -### Device placement +### 디바이스 지정 + +변수가 생성될 때, 특정 디바이스를 사용하도록 지정할 수 있습니다. [`with tf.device(...):`](../../api_docs/python/framework.md#device) 블럭을 사용하면 됩니다: + A variable can be pinned to a particular device when it is created, using a [`with tf.device(...):`](../../api_docs/python/framework.md#device) block: From 90975f839072d289d36d8ac5091e6cf2534e61a4 Mon Sep 17 00:00:00 2001 From: totuta Date: Sun, 5 Jun 2016 23:12:38 -0400 Subject: [PATCH 08/63] working on variables/index.. --- g3doc/how_tos/variables/index.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index ed5ba52..0a187d2 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -40,11 +40,7 @@ The value returned by `tf.Variable()` value is an instance of the Python class ### 디바이스 지정 -변수가 생성될 때, 특정 디바이스를 사용하도록 지정할 수 있습니다. [`with tf.device(...):`](../../api_docs/python/framework.md#device) 블럭을 사용하면 됩니다: - - -A variable can be pinned to a particular device when it is created, using a -[`with tf.device(...):`](../../api_docs/python/framework.md#device) block: +변수가 생성될 때, 특정 디바이스를 사용하도록 지정할 수 있습니다. [`with tf.device(...):`](../../api_docs/python/framework.md#device) 블럭을 사용하십시요: ```python # Pin a variable to CPU. From e74be2ed367fa7c7bdb8a7de94f203e84dcaac24 Mon Sep 17 00:00:00 2001 From: totuta Date: Mon, 6 Jun 2016 11:49:13 -0400 Subject: [PATCH 09/63] Update index.md --- g3doc/how_tos/variables/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 0a187d2..f77752c 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -10,6 +10,7 @@ ## 생성 +변수([Variable](../../api_docs/python/state_ops.md))를 생성하는 경우, `Tensor` When you create a [Variable](../../api_docs/python/state_ops.md) you pass a `Tensor` as its initial value to the `Variable()` constructor. TensorFlow provides a collection of ops that produce tensors often used for initialization From fc77402c7a5a6981062182865902246aa33b819f Mon Sep 17 00:00:00 2001 From: totuta Date: Mon, 6 Jun 2016 14:16:32 -0400 Subject: [PATCH 10/63] Update index.md --- g3doc/how_tos/variables/index.md | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index f77752c..8dc0075 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -10,16 +10,9 @@ ## 생성 -변수([Variable](../../api_docs/python/state_ops.md))를 생성하는 경우, `Tensor` -When you create a [Variable](../../api_docs/python/state_ops.md) you pass a -`Tensor` as its initial value to the `Variable()` constructor. TensorFlow -provides a collection of ops that produce tensors often used for initialization -from [constants or random values](../../api_docs/python/constant_op.md). - -Note that all these ops require you to specify the shape of the tensors. That -shape automatically becomes the shape of the variable. Variables generally -have a fixed shape, but TensorFlow provides advanced mechanisms to reshape -variables. +변수([Variable](../../api_docs/python/state_ops.md))를 생성하는 경우, 초기값으로서 `Tensor`값을 `Variable()` 생성자에 전달하게 됩니다. 텐서플로우가 제공하는 여러가지 연산자들인 [constants or random values](../../api_docs/python/constant_op.md)을 이용하여 초기화에 사용되는 텐서들을 만드는 경우가 많습니다. + +이 연산자들을 사용할 때에는, 텐서의 형태를 지정해 주어야 합니다. 그렇게 지정된 텐서의 형태가 자동적으로 해당 변수의 형태가 됩니다. 변수들은 일반적으로 고정된 형태를 갖습니다만, 텐서플로우에서는 변수의 형태를 변경할 수 있는 고급 기능도 제공됩니다. ```python # Create two variables. From 4b85817da7a58f098406dcc2feed5d864dadb915 Mon Sep 17 00:00:00 2001 From: totuta Date: Mon, 6 Jun 2016 14:21:40 -0400 Subject: [PATCH 11/63] Update index.md --- g3doc/how_tos/variables/index.md | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 8dc0075..e591987 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -21,16 +21,13 @@ weights = tf.Variable(tf.random_normal([784, 200], stddev=0.35), biases = tf.Variable(tf.zeros([200]), name="biases") ``` -Calling `tf.Variable()` adds several ops to the graph: +`tf.Variable()`를 호출하면 다음 몇가지의 연산자가 그래프에 추가됩니다: -* A `variable` op that holds the variable value. -* An initializer op that sets the variable to its initial value. This is - actually a `tf.assign` op. -* The ops for the initial value, such as the `zeros` op for the `biases` - variable in the example are also added to the graph. +* 변수 값을 저장하는 `variable` 연산자. +* 변수를 초기값으로 세팅하는 초기화 연산자인 `tf.assign`. +* 초기값을 위한 연산자들. 예제에 설명된 `biases` 변수를 위한 `zeros` 연산자같은 것도 그래프에 추가됨. -The value returned by `tf.Variable()` value is an instance of the Python class -`tf.Variable`. +`tf.Variable()` 가 리턴하는 값은 파이썬 클래스 `tf.Variable`의 인스턴스. ### 디바이스 지정 From 4acf48a132ed86313d46d912779ea5ea42dc1f01 Mon Sep 17 00:00:00 2001 From: totuta Date: Mon, 6 Jun 2016 14:22:15 -0400 Subject: [PATCH 12/63] Update index.md --- g3doc/how_tos/variables/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index e591987..50562ca 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -25,9 +25,9 @@ biases = tf.Variable(tf.zeros([200]), name="biases") * 변수 값을 저장하는 `variable` 연산자. * 변수를 초기값으로 세팅하는 초기화 연산자인 `tf.assign`. -* 초기값을 위한 연산자들. 예제에 설명된 `biases` 변수를 위한 `zeros` 연산자같은 것도 그래프에 추가됨. +* 초기값을 위한 연산자들. 예제에 설명된 `biases` 변수를 위한 `zeros` 연산자 같은 것도 그래프에 추가됨. -`tf.Variable()` 가 리턴하는 값은 파이썬 클래스 `tf.Variable`의 인스턴스. +`tf.Variable()` 가 리턴하는 값은 파이썬 클래스 `tf.Variable`의 인스턴스입니다. ### 디바이스 지정 From 1eccb092fea78bb74e9264e371b177b427769e48 Mon Sep 17 00:00:00 2001 From: totuta Date: Tue, 7 Jun 2016 14:46:08 -0400 Subject: [PATCH 13/63] Update index.md --- g3doc/how_tos/variables/index.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 50562ca..e57d0e4 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -47,12 +47,7 @@ with tf.device("/job:ps/task:7"): v = tf.Variable(...) ``` -**N.B.** Operations that mutate a variable, such as -[`v.assign()`](../../api_docs/python/state.md#Variable.assign) and the parameter -update operations in a -[`tf.train.Optimizer`](../../api_docs/python/train.md#Optimizer) *must* run on -the same device as the variable. Incompatible device placement directives will -be ignored when creating these operations. +**주의** [`v.assign()`](../../api_docs/python/state.md#Variable.assign) 처럼 변수를 변경(mutate)하는 오퍼레이션과, [`tf.train.Optimizer`](../../api_docs/python/train.md#Optimizer) 의 파라미터 업데이트 오퍼레이션들은, *반드시* 변수들과 같은 디바이스상에서 실행되어야 합니다. 위의 오퍼레이션들을 생성할 때, 잘못된 디바이스 지시자(directive)는 무시됩니다. Device placement is particularly important when running in a replicated setting. See From ef8da8c08b9211bc7dd1073209532428133c3c8c Mon Sep 17 00:00:00 2001 From: totuta Date: Tue, 7 Jun 2016 14:49:58 -0400 Subject: [PATCH 14/63] Update index.md --- g3doc/how_tos/variables/index.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index e57d0e4..8bc10db 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -49,11 +49,7 @@ with tf.device("/job:ps/task:7"): **주의** [`v.assign()`](../../api_docs/python/state.md#Variable.assign) 처럼 변수를 변경(mutate)하는 오퍼레이션과, [`tf.train.Optimizer`](../../api_docs/python/train.md#Optimizer) 의 파라미터 업데이트 오퍼레이션들은, *반드시* 변수들과 같은 디바이스상에서 실행되어야 합니다. 위의 오퍼레이션들을 생성할 때, 잘못된 디바이스 지시자(directive)는 무시됩니다. -Device placement is particularly important when running in a replicated -setting. See -[`tf.train.replica_device_setter()`](../../api_docs/python/train.md#replica_device_setter) -for details of a device function that can simplify the configuration for devices -for a replicated model. +복제된 세팅에서 실행하는 경우, 디바이스 지정은 특히 중요합니다. 복제된 세팅에서 디바이스 설정을 심플하게 하는 디바이스 함수들에 대해서는 [`tf.train.replica_device_setter()`](../../api_docs/python/train.md#replica_device_setter)를 참조하십시요. ## 초기화 From 1d1d5cfe93baa70a2deaf47526b03a85196dfe05 Mon Sep 17 00:00:00 2001 From: totuta Date: Tue, 7 Jun 2016 14:51:39 -0400 Subject: [PATCH 15/63] Update index.md --- g3doc/how_tos/variables/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 8bc10db..75a3cf8 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -49,7 +49,7 @@ with tf.device("/job:ps/task:7"): **주의** [`v.assign()`](../../api_docs/python/state.md#Variable.assign) 처럼 변수를 변경(mutate)하는 오퍼레이션과, [`tf.train.Optimizer`](../../api_docs/python/train.md#Optimizer) 의 파라미터 업데이트 오퍼레이션들은, *반드시* 변수들과 같은 디바이스상에서 실행되어야 합니다. 위의 오퍼레이션들을 생성할 때, 잘못된 디바이스 지시자(directive)는 무시됩니다. -복제된 세팅에서 실행하는 경우, 디바이스 지정은 특히 중요합니다. 복제된 세팅에서 디바이스 설정을 심플하게 하는 디바이스 함수들에 대해서는 [`tf.train.replica_device_setter()`](../../api_docs/python/train.md#replica_device_setter)를 참조하십시요. +디바이스를 정확히 지정하는 것은 복제된 세팅에서 실행하는 경우에 특히 중요합니다. 복제된 세팅에서 디바이스 설정을 심플하게 해주는 함수들에 대해서는 [`tf.train.는replica_device_setter()`](../../api_docs/python/train.md#replica_device_setter)를 참조하십시요. ## 초기화 From 5e4addafd287458dcf53cc381193ea2a27a1da0b Mon Sep 17 00:00:00 2001 From: totuta Date: Tue, 7 Jun 2016 15:04:57 -0400 Subject: [PATCH 16/63] Update index.md --- g3doc/how_tos/variables/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 75a3cf8..f58bbe0 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -49,7 +49,7 @@ with tf.device("/job:ps/task:7"): **주의** [`v.assign()`](../../api_docs/python/state.md#Variable.assign) 처럼 변수를 변경(mutate)하는 오퍼레이션과, [`tf.train.Optimizer`](../../api_docs/python/train.md#Optimizer) 의 파라미터 업데이트 오퍼레이션들은, *반드시* 변수들과 같은 디바이스상에서 실행되어야 합니다. 위의 오퍼레이션들을 생성할 때, 잘못된 디바이스 지시자(directive)는 무시됩니다. -디바이스를 정확히 지정하는 것은 복제된 세팅에서 실행하는 경우에 특히 중요합니다. 복제된 세팅에서 디바이스 설정을 심플하게 해주는 함수들에 대해서는 [`tf.train.는replica_device_setter()`](../../api_docs/python/train.md#replica_device_setter)를 참조하십시요. +디바이스를 정확히 지정하는 것은 복제된 세팅에서 실행하는 경우에 특히 중요합니다. 복제된 세팅에서 디바이스 설정을 심플하게 해주는 함수들에 대해서는 [`tf.train.replica_device_setter()`](../../api_docs/python/train.md#replica_device_setter)를 참조하십시요. ## 초기화 From 6b7b2766b19edb24bbd3e71990527a13249e6c2e Mon Sep 17 00:00:00 2001 From: totuta Date: Wed, 8 Jun 2016 21:58:16 -0400 Subject: [PATCH 17/63] working on variables/index.. --- g3doc/how_tos/variables/index.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index f58bbe0..2a17b7e 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -53,6 +53,8 @@ with tf.device("/job:ps/task:7"): ## 초기화 +변수의 초기화는 모델상의 어떤 오퍼레이션보다도 분명하게 먼저 실행되어야 합니다. 가장 쉬운 방법은 모든 변수 초기화 동작을 실행하는 오퍼레이션을 + Variable initializers must be run explicitly before other ops in your model can be run. The easiest way to do that is to add an op that runs all the variable initializers, and run that op before using the model. From 7568752bb901934c7bb9a0935aa1412981656aa3 Mon Sep 17 00:00:00 2001 From: totuta Date: Wed, 8 Jun 2016 23:44:36 -0400 Subject: [PATCH 18/63] working on variables/index.. --- g3doc/how_tos/variables/index.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 2a17b7e..da37c5a 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -53,14 +53,10 @@ with tf.device("/job:ps/task:7"): ## 초기화 -변수의 초기화는 모델상의 어떤 오퍼레이션보다도 분명하게 먼저 실행되어야 합니다. 가장 쉬운 방법은 모든 변수 초기화 동작을 실행하는 오퍼레이션을 +변수의 초기화는 모델상의 어떤 오퍼레이션보다도 분명하게 먼저 실행되어야 합니다. 가장 쉬운 방법은 모든 변수의 초기화 동작을 모아서 실행하는 오퍼레이션을 만들어서, 모델을 사용하기 전에 그 오퍼레이션을 실행하는 것입니다. -Variable initializers must be run explicitly before other ops in your model can -be run. The easiest way to do that is to add an op that runs all the variable -initializers, and run that op before using the model. +또는 체크포인트 화일로부터 변수의 값을 복구하는 방법을 사용할 수도 있습니다. 아래를 참조하십시요. -You can alternatively restore variable values from a checkpoint file, see -below. Use `tf.initialize_all_variables()` to add an op to run variable initializers. Only run that op after you have fully constructed your model and launched it in From f16594ea94b4d0d249758a5f6632646d1b575bde Mon Sep 17 00:00:00 2001 From: totuta Date: Wed, 8 Jun 2016 23:47:23 -0400 Subject: [PATCH 19/63] working on variables/index.. --- g3doc/how_tos/variables/index.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index da37c5a..1130bc1 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -57,10 +57,7 @@ with tf.device("/job:ps/task:7"): 또는 체크포인트 화일로부터 변수의 값을 복구하는 방법을 사용할 수도 있습니다. 아래를 참조하십시요. - -Use `tf.initialize_all_variables()` to add an op to run variable initializers. -Only run that op after you have fully constructed your model and launched it in -a session. +`tf.initialize_all_variables()` 를 사용하여 변수들의 초기화를 실행하는 오퍼레이션을 추가합니다. 모델을 완전하게 구축하고서 세션에서 띄운(launch) 후에 그 오퍼레이션을 실행시키십시요. ```python # Create two variables. From 19557740096136c7745b77561eb10de47f7524b2 Mon Sep 17 00:00:00 2001 From: totuta Date: Fri, 17 Jun 2016 00:57:32 -0400 Subject: [PATCH 20/63] working on variables/index.md --- g3doc/how_tos/variables/index.md | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 1130bc1..7950726 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -79,15 +79,9 @@ with tf.Session() as sess: ### 다른 변수값을 참조하여 초기화 하기 -You sometimes need to initialize a variable from the initial value of another -variable. As the op added by `tf.initialize_all_variables()` initializes all -variables in parallel you have to be careful when this is needed. - -To initialize a new variable from the value of another variable use the other -variable's `initialized_value()` property. You can use the initialized value -directly as the initial value for the new variable, or you can use it as any -other tensor to compute a value for the new variable. +다른 변수의 값을 이용하여 어떤 변수를 초기화 해야하는 경우가 있습니다. `tf.initialize_all_variables()` 를 통해서 추가된 op는 모든 변수들을 한꺼번에 병렬적으로 초기화 하므로, 이 기능을 이용하는 경우에는 주의해야 합니다. +다른 변수의 값을 이용하여 새로운 변수를 초기화 하는 경우, 그 다른 변수의 `initialized_value()` 프로퍼티를 사용합니다. 그 초기화된 값을 그대로 새로운 변수의 초기값으로 사용하거나, 초기값을 계산하는 데에 필요한 텐서로 사용할 수 있습니다. ```python # Create a variable with a random value. From 1d0a67bf50a8f5ad8b28dba86621baa1a4149bd4 Mon Sep 17 00:00:00 2001 From: totuta Date: Fri, 17 Jun 2016 01:07:45 -0400 Subject: [PATCH 21/63] working on variables/index.md --- g3doc/how_tos/variables/index.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 7950726..91efcc8 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -79,7 +79,7 @@ with tf.Session() as sess: ### 다른 변수값을 참조하여 초기화 하기 -다른 변수의 값을 이용하여 어떤 변수를 초기화 해야하는 경우가 있습니다. `tf.initialize_all_variables()` 를 통해서 추가된 op는 모든 변수들을 한꺼번에 병렬적으로 초기화 하므로, 이 기능을 이용하는 경우에는 주의해야 합니다. +다른 변수의 값을 이용하여 어떤 변수를 초기화 해야 하는 경우가 있습니다. `tf.initialize_all_variables()` 를 통해서 추가된 op는 모든 변수들을 한꺼번에 병렬적으로 초기화 하므로, 이 기능을 이용하는 경우에는 주의해야 합니다. 다른 변수의 값을 이용하여 새로운 변수를 초기화 하는 경우, 그 다른 변수의 `initialized_value()` 프로퍼티를 사용합니다. 그 초기화된 값을 그대로 새로운 변수의 초기값으로 사용하거나, 초기값을 계산하는 데에 필요한 텐서로 사용할 수 있습니다. @@ -95,11 +95,7 @@ w_twice = tf.Variable(weights.initialized_value() * 2.0, name="w_twice") ### 커스텀 초기화 -The convenience function `tf.initialize_all_variables()` adds an op to -initialize *all variables* in the model. You can also pass it an explicit list -of variables to initialize. See the -[Variables Documentation](../../api_docs/python/state_ops.md) for more options, -including checking if variables are initialized. +컨비니언스 함수인 `tf.initialize_all_variables()` 는 모델상의 *모든 변수*를 초기화 하는 op를 추가합니다. 초기화가 필요한 변수들만을 리스트로 넘기는 방법도 가능합니다. 변수들이 초기화 되어있는지를 체크하는 방법을 포함한 자세한 옵션들에 대해서는 [변수](../../api_docs/python/state_ops.md) 문서를 참조하십시요. ## 저장과 복구 From 46fce901a1e8ef3027a5f92cfef8ad5cdc1eeef4 Mon Sep 17 00:00:00 2001 From: totuta Date: Fri, 17 Jun 2016 01:20:49 -0400 Subject: [PATCH 22/63] working on variables/index.md --- g3doc/how_tos/variables/index.md | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 91efcc8..17d4711 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -1,6 +1,6 @@ # 변수: 생성, 초기화, 저장, 복구 -모델을 학습시키는 경우에, 파라미터를 저장하고 업데이트 하기 위하여 변수들([variables](../../api_docs/python/state_ops.md))를 사용합니다. 변수들은 텐서들을 저장하는 메모리상의 버퍼들입니다. 명확하게 초기화 되어야 하며, 학습이 진행되는 동안이나 끝난 후에 디스크에 저장될 수 있습니다. 나중에 모델을 사용하거나 분석하기 위하여 저장된 값들을 복구할 수 있습니다. +모델을 학습시키는 경우에, 파라미터를 저장하고 업데이트 하기 위하여 변수들([variables](../../api_docs/python/state_ops.md))를 사용합니다. 변수들은 텐서들을 저장하는 메모리상의 버퍼들입니다. 명확하게 초기화되어야 하며, 학습이 진행되는 동안이나 끝난 후에 디스크에 저장될 수 있습니다. 나중에 모델을 사용하거나 분석하기 위하여 저장된 값들을 복구할 수 있습니다. 이 문서는 다음의 텐서플로우 클래스들을 이용하여 설명을 진행합니다. API에 대한 완전한 설명을 담고 있는 레퍼런스 매뉴얼을 보려면 링크를 참조하십시요. @@ -79,9 +79,9 @@ with tf.Session() as sess: ### 다른 변수값을 참조하여 초기화 하기 -다른 변수의 값을 이용하여 어떤 변수를 초기화 해야 하는 경우가 있습니다. `tf.initialize_all_variables()` 를 통해서 추가된 op는 모든 변수들을 한꺼번에 병렬적으로 초기화 하므로, 이 기능을 이용하는 경우에는 주의해야 합니다. +다른 변수의 값을 이용하여 어떤 변수를 초기화해야 하는 경우가 있습니다. `tf.initialize_all_variables()` 를 통해서 추가된 op는 모든 변수들을 한꺼번에 병렬적으로 초기화 하므로, 이 기능을 이용하는 경우에는 주의해야 합니다. -다른 변수의 값을 이용하여 새로운 변수를 초기화 하는 경우, 그 다른 변수의 `initialized_value()` 프로퍼티를 사용합니다. 그 초기화된 값을 그대로 새로운 변수의 초기값으로 사용하거나, 초기값을 계산하는 데에 필요한 텐서로 사용할 수 있습니다. +다른 변수의 값을 이용하여 새로운 변수를 초기화하는 경우, 그 다른 변수의 `initialized_value()` 프로퍼티를 사용합니다. 그 초기화된 값을 그대로 새로운 변수의 초기값으로 사용하거나, 초기값을 계산하는 데에 필요한 텐서로 사용할 수 있습니다. ```python # Create a variable with a random value. @@ -95,17 +95,13 @@ w_twice = tf.Variable(weights.initialized_value() * 2.0, name="w_twice") ### 커스텀 초기화 -컨비니언스 함수인 `tf.initialize_all_variables()` 는 모델상의 *모든 변수*를 초기화 하는 op를 추가합니다. 초기화가 필요한 변수들만을 리스트로 넘기는 방법도 가능합니다. 변수들이 초기화 되어있는지를 체크하는 방법을 포함한 자세한 옵션들에 대해서는 [변수](../../api_docs/python/state_ops.md) 문서를 참조하십시요. +컨비니언스 함수인 `tf.initialize_all_variables()` 는 모델상의 *모든 변수*를 초기화 하는 op를 추가합니다. 초기화가 필요한 변수들만을 리스트로 넘기는 것도 가능합니다. 변수들이 초기화 되어있는지를 체크하는 방법을 포함한 자세한 옵션들에 대해서는 [변수](../../api_docs/python/state_ops.md) 문서를 참조하십시요. ## 저장과 복구 -The easiest way to save and restore a model is to use a `tf.train.Saver` object. -The constructor adds `save` and `restore` ops to the graph for all, or a -specified list, of the variables in the graph. The saver object provides -methods to run these ops, specifying paths for the checkpoint files to write to -or read from. +모델을 저장하고 복구하는 가장 쉬운 방법은 `tf.train.Saver` 객체를 사용하는 것입니다. `save` 와 `restore` op 들이 그래프에 추가되어, 모든 변수들 또는 리스트로 정리된 특정 변수들을 저장하고 복구할 수 있게 됩니다. 체크포인트 화일들을 읽고 쓸 경로를 지정하여 이 op 들을 실행시키는 메쏘드는 saver 객체가 제공합니다. -### 체크 포인트 화일 Checkpoint Files +### 체크포인트 화일 Variables are saved in binary files that, roughly, contain a map from variable names to tensor values. From 9d76c68283ffcecff6dc503113e928f8f7df550c Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:15:02 -0400 Subject: [PATCH 23/63] working on variables/index.md --- g3doc/how_tos/variables/index.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 17d4711..7182bfd 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -103,8 +103,9 @@ w_twice = tf.Variable(weights.initialized_value() * 2.0, name="w_twice") ### 체크포인트 화일 -Variables are saved in binary files that, roughly, contain a map from variable -names to tensor values. +변수들은 바이너리 화일에 저장되는데, 대략적으로 변수명과 텐서 값을 매핑하는 구조로 되어 있습니다. + +`Saver` 객체를 생성할 때, 체크포인트 화일에 들어갈 변수의 이름들을 지정하는 것도 가능합니다. 특별히 지정하지 않는 경우에는, 각 변수들의 [`Variable.name`](../../api_docs/python/state_ops.md#Variable.name) 프로퍼티 값들이 사용됩니다. When you create a `Saver` object, you can optionally choose names for the variables in the checkpoint files. By default, it uses the value of the From 1573905cd139ff73a184a992b934102bfa2d881a Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:17:47 -0400 Subject: [PATCH 24/63] working on variables/index.md --- g3doc/how_tos/variables/index.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 7182bfd..0b215df 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -105,12 +105,9 @@ w_twice = tf.Variable(weights.initialized_value() * 2.0, name="w_twice") 변수들은 바이너리 화일에 저장되는데, 대략적으로 변수명과 텐서 값을 매핑하는 구조로 되어 있습니다. -`Saver` 객체를 생성할 때, 체크포인트 화일에 들어갈 변수의 이름들을 지정하는 것도 가능합니다. 특별히 지정하지 않는 경우에는, 각 변수들의 [`Variable.name`](../../api_docs/python/state_ops.md#Variable.name) 프로퍼티 값들이 사용됩니다. +`Saver` 객체를 생성할 때, 체크포인트 화일에 들어갈 변수들의 이름을 지정하는 것도 가능합니다. 특별히 지정하지 않는 경우에는, 각 변수들의 [`Variable.name`](../../api_docs/python/state_ops.md#Variable.name) 프로퍼티 값들이 사용됩니다. -When you create a `Saver` object, you can optionally choose names for the -variables in the checkpoint files. By default, it uses the value of the -[`Variable.name`](../../api_docs/python/state_ops.md#Variable.name) property for -each variable. +[`inspect_checkpoint`](https://www.tensorflow.org/code/tensorflow/python/tools/inspect_checkpoint.py) 라이브러리, 좀 더 자세하게는 `print_tensors_in_checkpoint_file` 함수를 사용하여, 체크포인트에 어떤 변수들이 들어있는지를 알아볼 수 있습니다. To understand what variables are in a checkpoint, you can use the [`inspect_checkpoint`](https://www.tensorflow.org/code/tensorflow/python/tools/inspect_checkpoint.py) From 18dba0df1525e017d0f1dc99c1e6721b27d162ad Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:18:10 -0400 Subject: [PATCH 25/63] working on variables/index.md --- g3doc/how_tos/variables/index.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 0b215df..4fd40cd 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -109,10 +109,6 @@ w_twice = tf.Variable(weights.initialized_value() * 2.0, name="w_twice") [`inspect_checkpoint`](https://www.tensorflow.org/code/tensorflow/python/tools/inspect_checkpoint.py) 라이브러리, 좀 더 자세하게는 `print_tensors_in_checkpoint_file` 함수를 사용하여, 체크포인트에 어떤 변수들이 들어있는지를 알아볼 수 있습니다. -To understand what variables are in a checkpoint, you can use the -[`inspect_checkpoint`](https://www.tensorflow.org/code/tensorflow/python/tools/inspect_checkpoint.py) -library, and in particular, the `print_tensors_in_checkpoint_file` function. - ### 변수 저장 모델안의 모든 변수를 관리하기 위하여, `tf.train.Saver()`를 사용해 `Saver`를 만드십시요. From 982c2d60a9fc34c993b751563692897b1e2d2556 Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:21:29 -0400 Subject: [PATCH 26/63] working on variables/index.md --- g3doc/how_tos/variables/index.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 4fd40cd..8d92917 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -161,9 +161,8 @@ with tf.Session() as sess: ### 저장 및 복구할 변수들의 선택 -If you do not pass any argument to `tf.train.Saver()` the saver handles all -variables in the graph. Each one of them is saved under the name that was -passed when the variable was created. +`tf.train.Saver()` 에 아무 인자도 넘겨주지 않으면, saver 는 그래프에 있는 모든 변수들을 처리 대상으로 가집니다. 각각의 변수들은 생성된 시점에 넘겨받은 이름으로 저장됩니다. + It is sometimes useful to explicitly specify names for variables in the checkpoint files. For example, you may have trained a model with a variable From 5adbebdb6f1ffd3ad7631e9cfb85d502685bbf9a Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:25:09 -0400 Subject: [PATCH 27/63] working on variables/index.md --- g3doc/how_tos/variables/index.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 8d92917..d5a3fc9 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -179,13 +179,15 @@ You can easily specify the names and variables to save by passing to the `tf.train.Saver()` constructor a Python dictionary: keys are the names to use, values are the variables to manage. -Notes: +주: * You can create as many saver objects as you want if you need to save and restore different subsets of the model variables. The same variable can be listed in multiple saver objects, its value is only changed when the saver `restore()` method is run. +* 세션을 시작할 때 모델 변수들의 일부만을 복구하는 경우에는, 나머지 변수들의 초기화 op 를 반드시 실행해야 합니다. 자세한 내용은 [`tf.initialize_variables()`](../../api_docs/python/state_ops.md#initialize_variables) 를 보십시요. + * If you only restore a subset of the model variables at the start of a session, you have to run an initialize op for the other variables. See [`tf.initialize_variables()`](../../api_docs/python/state_ops.md#initialize_variables) From e8f707e8ee10a105dbd1a13271486916df6baa5f Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:25:33 -0400 Subject: [PATCH 28/63] working on variables/index.md --- g3doc/how_tos/variables/index.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index d5a3fc9..83d2b8f 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -188,11 +188,6 @@ names to use, values are the variables to manage. * 세션을 시작할 때 모델 변수들의 일부만을 복구하는 경우에는, 나머지 변수들의 초기화 op 를 반드시 실행해야 합니다. 자세한 내용은 [`tf.initialize_variables()`](../../api_docs/python/state_ops.md#initialize_variables) 를 보십시요. -* If you only restore a subset of the model variables at the start - of a session, you have to run an initialize op for the other variables. See - [`tf.initialize_variables()`](../../api_docs/python/state_ops.md#initialize_variables) - for more information. - ```python # Create some variables. v1 = tf.Variable(..., name="v1") From e4952a64ec394043695999618da8f85b11ca3da5 Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:30:01 -0400 Subject: [PATCH 29/63] working on variables/index.md --- g3doc/how_tos/variables/index.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 83d2b8f..cdd5fd2 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -181,10 +181,7 @@ names to use, values are the variables to manage. 주: -* You can create as many saver objects as you want if you need to save and - restore different subsets of the model variables. The same variable can be - listed in multiple saver objects, its value is only changed when the saver - `restore()` method is run. +* 모델 변수들의 여러가지 부분집합들을 저장하고 복구할 필요가 있는 경우, 원하는 만큼의 saver 객체를 생성할 수 있습니다. 같은 변수를 복수의 saver 객체들에 포함해도 되며, 이 경우에 그 변수의 값은 saver의 `restore()` 메소드가 실행될 때에만 변경됩니다. * 세션을 시작할 때 모델 변수들의 일부만을 복구하는 경우에는, 나머지 변수들의 초기화 op 를 반드시 실행해야 합니다. 자세한 내용은 [`tf.initialize_variables()`](../../api_docs/python/state_ops.md#initialize_variables) 를 보십시요. From f6c0fcbc5a5eeadcdb73aecff829fdae7adeec17 Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:34:03 -0400 Subject: [PATCH 30/63] working on variables/index.md --- g3doc/how_tos/variables/index.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index cdd5fd2..679b00d 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -175,9 +175,7 @@ and you now want to train a new model with 6 layers, restoring the parameters from the 5 layers of the previously trained model into the first 5 layers of the new model. -You can easily specify the names and variables to save by passing to the -`tf.train.Saver()` constructor a Python dictionary: keys are the -names to use, values are the variables to manage. +`tf.train.Saver()` 생성자에 파이썬 딕셔너리를 전달함으로서, 어떤 변수들을 어떤 이름으로 저장할 것인지 간편하게 정할 수 있습니다: 저장시에 사용할 이름들을 key 로 하고, 저장될 변수들을 값으로 하는 딕셔너리를 전달합니다. 주: From a69266596cb98f4bf9c3dd097a7c1930706668bd Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:36:54 -0400 Subject: [PATCH 31/63] working on variables/index.md --- g3doc/how_tos/variables/index.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 679b00d..03d4bd3 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -163,6 +163,8 @@ with tf.Session() as sess: `tf.train.Saver()` 에 아무 인자도 넘겨주지 않으면, saver 는 그래프에 있는 모든 변수들을 처리 대상으로 가집니다. 각각의 변수들은 생성된 시점에 넘겨받은 이름으로 저장됩니다. +체크포인트 화일에 저장될 변수들에 구체적인 이름을 붙이는 것이 유용할 때가 있습니다. 예를 들어, `"weights"` 라는 이름의 변수를 가지는 모델을 학습시켜서, `"params"` 라는 이름을 가진 새 변수의 값으로 복구하는 경우가 있습니다. + It is sometimes useful to explicitly specify names for variables in the checkpoint files. For example, you may have trained a model with a variable @@ -175,7 +177,7 @@ and you now want to train a new model with 6 layers, restoring the parameters from the 5 layers of the previously trained model into the first 5 layers of the new model. -`tf.train.Saver()` 생성자에 파이썬 딕셔너리를 전달함으로서, 어떤 변수들을 어떤 이름으로 저장할 것인지 간편하게 정할 수 있습니다: 저장시에 사용할 이름들을 key 로 하고, 저장될 변수들을 값으로 하는 딕셔너리를 전달합니다. +`tf.train.Saver()` 생성자에 파이썬 딕셔너리를 전달함으로서, 어떤 변수들을 어떤 이름으로 저장할 것인지 간편하게 정할 수 있습니다: 저장시에 사용할 이름들을 key 로 하고, 저장될 변수들을 값으로 하는 딕셔너리를 전달하면 됩니다. 주: From 0b1b71b7b658c9873b6d668e7e00903104605601 Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:38:13 -0400 Subject: [PATCH 32/63] working on variables/index.md --- g3doc/how_tos/variables/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 03d4bd3..b89c321 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -163,7 +163,7 @@ with tf.Session() as sess: `tf.train.Saver()` 에 아무 인자도 넘겨주지 않으면, saver 는 그래프에 있는 모든 변수들을 처리 대상으로 가집니다. 각각의 변수들은 생성된 시점에 넘겨받은 이름으로 저장됩니다. -체크포인트 화일에 저장될 변수들에 구체적인 이름을 붙이는 것이 유용할 때가 있습니다. 예를 들어, `"weights"` 라는 이름의 변수를 가지는 모델을 학습시켜서, `"params"` 라는 이름을 가진 새 변수의 값으로 복구하는 경우가 있습니다. +체크포인트 화일에 저장될 변수들에 구체적인 이름을 붙이는 것이 유용할 때가 있습니다. 예를 들어, 학습된 모델이 `"weights"` 라는 이름의 변수를 가지고 있는데, 그 변수의 값을 `"params"` 라는 이름의 새 변수의 값으로 복구하는 경우가 있습니다. It is sometimes useful to explicitly specify names for variables in the From 72be5cbd44828b539f5ef51d42c9488f687d4068 Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:41:34 -0400 Subject: [PATCH 33/63] working on variables/index.md --- g3doc/how_tos/variables/index.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index b89c321..66ffac5 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -163,13 +163,9 @@ with tf.Session() as sess: `tf.train.Saver()` 에 아무 인자도 넘겨주지 않으면, saver 는 그래프에 있는 모든 변수들을 처리 대상으로 가집니다. 각각의 변수들은 생성된 시점에 넘겨받은 이름으로 저장됩니다. -체크포인트 화일에 저장될 변수들에 구체적인 이름을 붙이는 것이 유용할 때가 있습니다. 예를 들어, 학습된 모델이 `"weights"` 라는 이름의 변수를 가지고 있는데, 그 변수의 값을 `"params"` 라는 이름의 새 변수의 값으로 복구하는 경우가 있습니다. +체크포인트 화일에 저장될 변수들에 구체적인 이름을 붙이는 것이 유용할 때가 있습니다. 예를 들어, 학습된 모델이 `"weights"` 라는 이름의 변수를 가지고 있는데, 그 변수의 값을 복구하여 `"params"` 라는 이름의 새 변수의 값으로 넣는 경우가 있습니다. - -It is sometimes useful to explicitly specify names for variables in the -checkpoint files. For example, you may have trained a model with a variable -named `"weights"` whose value you want to restore in a new variable named -`"params"`. +또한, 모델에 사용되는 변수들의 부분집합만을 저장하고 복구하는 것이 유용한 경우가 있습니다. 예컨대, 5개의 레이어를 가지는 뉴럴넷을 학습시켰는데, 6개의 레이어를 가지는 새 모델을 학습시킨다고 합시다. 이 경우, 첫 5개 레이어의 파라미터느 이미 학습된 모델의 파라미터들을 복구하여 사용할 수 있습니다. It is also sometimes useful to only save or restore a subset of the variables used by a model. For example, you may have trained a neural net with 5 layers, From c42a01a6beecb0401a4afd7edfbf6a3b73ab05c4 Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:41:57 -0400 Subject: [PATCH 34/63] working on variables/index.md --- g3doc/how_tos/variables/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index 66ffac5..e960e73 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -165,7 +165,7 @@ with tf.Session() as sess: 체크포인트 화일에 저장될 변수들에 구체적인 이름을 붙이는 것이 유용할 때가 있습니다. 예를 들어, 학습된 모델이 `"weights"` 라는 이름의 변수를 가지고 있는데, 그 변수의 값을 복구하여 `"params"` 라는 이름의 새 변수의 값으로 넣는 경우가 있습니다. -또한, 모델에 사용되는 변수들의 부분집합만을 저장하고 복구하는 것이 유용한 경우가 있습니다. 예컨대, 5개의 레이어를 가지는 뉴럴넷을 학습시켰는데, 6개의 레이어를 가지는 새 모델을 학습시킨다고 합시다. 이 경우, 첫 5개 레이어의 파라미터느 이미 학습된 모델의 파라미터들을 복구하여 사용할 수 있습니다. +또한, 모델에 사용되는 변수들의 부분집합만을 저장하고 복구하는 것이 유용한 경우가 있습니다. 예컨대, 5개의 레이어를 가지는 뉴럴넷을 학습시켰는데, 6개의 레이어를 가지는 새 모델을 학습시키고 싶다고 합시다. 이 경우, 첫 5개 레이어의 파라미터느 이미 학습된 모델의 파라미터들을 복구하여 사용할 수 있습니다. It is also sometimes useful to only save or restore a subset of the variables used by a model. For example, you may have trained a neural net with 5 layers, From 49f7311280568bc0b04ea3a1a216482500b55102 Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:42:26 -0400 Subject: [PATCH 35/63] working on variables/index.md --- g3doc/how_tos/variables/index.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md index e960e73..49f3fb4 100644 --- a/g3doc/how_tos/variables/index.md +++ b/g3doc/how_tos/variables/index.md @@ -165,13 +165,7 @@ with tf.Session() as sess: 체크포인트 화일에 저장될 변수들에 구체적인 이름을 붙이는 것이 유용할 때가 있습니다. 예를 들어, 학습된 모델이 `"weights"` 라는 이름의 변수를 가지고 있는데, 그 변수의 값을 복구하여 `"params"` 라는 이름의 새 변수의 값으로 넣는 경우가 있습니다. -또한, 모델에 사용되는 변수들의 부분집합만을 저장하고 복구하는 것이 유용한 경우가 있습니다. 예컨대, 5개의 레이어를 가지는 뉴럴넷을 학습시켰는데, 6개의 레이어를 가지는 새 모델을 학습시키고 싶다고 합시다. 이 경우, 첫 5개 레이어의 파라미터느 이미 학습된 모델의 파라미터들을 복구하여 사용할 수 있습니다. - -It is also sometimes useful to only save or restore a subset of the variables -used by a model. For example, you may have trained a neural net with 5 layers, -and you now want to train a new model with 6 layers, restoring the parameters -from the 5 layers of the previously trained model into the first 5 layers of -the new model. +또한, 모델에 사용되는 변수들의 부분집합만을 저장하고 복구하는 것이 유용한 경우가 있습니다. 예컨대, 5개의 레이어를 가지는 뉴럴넷을 학습시켰는데, 6개의 레이어를 가지는 새 모델을 학습시키고 싶다고 합시다. 이 경우, 첫 5개 레이어의 파라미터는 이미 학습된 모델의 파라미터들을 복구하여 사용할 수 있다는 것입니다. `tf.train.Saver()` 생성자에 파이썬 딕셔너리를 전달함으로서, 어떤 변수들을 어떤 이름으로 저장할 것인지 간편하게 정할 수 있습니다: 저장시에 사용할 이름들을 key 로 하고, 저장될 변수들을 값으로 하는 딕셔너리를 전달하면 됩니다. From 3faa7d42083111e37c1e55e7830bc2573a345395 Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:45:37 -0400 Subject: [PATCH 36/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index e3b0214..75ee010 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -1,4 +1,4 @@ -# Sharing Variables +# 변수 공유 You can create, initialize, save and load single variables in the way described in the [Variables HowTo](../../how_tos/variables/index.md). From 02b39b65f91491fb53fc2aa0b0ae20acc46c6ba0 Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:50:39 -0400 Subject: [PATCH 37/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index 75ee010..db57646 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -7,7 +7,7 @@ variables and you might want to initialize all of them in one place. This tutorial shows how this can be done using `tf.variable_scope()` and the `tf.get_variable()`. -## The Problem +## 문제 Imagine you create a simple model for image filters, similar to our [Convolutional Neural Networks Tutorial](../../tutorials/deep_cnn/index.md) @@ -88,7 +88,7 @@ For a lighter solution, not involving classes, TensorFlow provides a *Variable Scope* mechanism that allows to easily share named variables while constructing a graph. -## Variable Scope Example +## 변수 범위 예 Variable Scope mechanism in TensorFlow consists of 2 main functions: @@ -162,9 +162,9 @@ with tf.variable_scope("image_filters") as scope: This is a good way to share variables, lightweight and safe. -## How Does Variable Scope Work? +## How Does Variable Scope Work? 변수 범위가 어떤 기능을 갖는가? -### Understanding `tf.get_variable()` +### `tf.get_variable()` 이해하기 To understand variable scope it is necessary to first fully understand how `tf.get_variable()` works. @@ -210,7 +210,7 @@ with tf.variable_scope("foo", reuse=True): assert v1 == v ``` -### Basics of `tf.variable_scope()` +### `tf.variable_scope()` 의 기초 Knowing how `tf.get_variable()` works makes it easy to understand variable scope. The primary function of variable scope is to carry a name that will @@ -329,7 +329,7 @@ with tf.variable_scope("foo", initializer=tf.constant_initializer(0.4)): assert v.eval() == 0.2 # Changed default initializer. ``` -### Names of ops in `tf.variable_scope()` +### `tf.variable_scope()` 의 op 명칭들 We discussed how `tf.variable_scope` governs the names of variables. But how does it influence the names of other ops in the scope? @@ -359,13 +359,13 @@ When opening a variable scope using a captured object instead of a string, we do not alter the current name scope for ops. -## Examples of Use +## 사용 예 Here are pointers to a few files that make use of variable scope. In particular, it is heavily used for recurrent neural networks and sequence-to-sequence models. -File | What's in it? +화일 | 화일 내용 --- | --- `models/image/cifar10.py` | Model for detecting objects in images. `models/rnn/rnn_cell.py` | Cell functions for recurrent neural networks. From b11f6a27d0718ea57e1b51331d2ebbd7eafa8f41 Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:52:30 -0400 Subject: [PATCH 38/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index db57646..31fe1ed 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -365,8 +365,8 @@ Here are pointers to a few files that make use of variable scope. In particular, it is heavily used for recurrent neural networks and sequence-to-sequence models. -화일 | 화일 내용 +화일 | 내용 --- | --- -`models/image/cifar10.py` | Model for detecting objects in images. -`models/rnn/rnn_cell.py` | Cell functions for recurrent neural networks. -`models/rnn/seq2seq.py` | Functions for building sequence-to-sequence models. +`models/image/cifar10.py` | 이미지내의 대상을 인식하는 모델. +`models/rnn/rnn_cell.py` | RNN(recurrent neural networks) 의 셀 함수들. +`models/rnn/seq2seq.py` | sequence-to-sequence 모델들을 구축하는 데에 필요한 함수들. From 3c61888a723abc8558a0ba54d2fe6d51089c713d Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:53:04 -0400 Subject: [PATCH 39/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index 31fe1ed..6d4e98c 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -367,6 +367,6 @@ and sequence-to-sequence models. 화일 | 내용 --- | --- -`models/image/cifar10.py` | 이미지내의 대상을 인식하는 모델. +`models/image/cifar10.py` | 이미지상의 대상 인식용 모델. `models/rnn/rnn_cell.py` | RNN(recurrent neural networks) 의 셀 함수들. `models/rnn/seq2seq.py` | sequence-to-sequence 모델들을 구축하는 데에 필요한 함수들. From 5d54cec15547ae0c8b178959d38105cc25d536e5 Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:55:27 -0400 Subject: [PATCH 40/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index 6d4e98c..7b64e7e 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -361,9 +361,7 @@ we do not alter the current name scope for ops. ## 사용 예 -Here are pointers to a few files that make use of variable scope. -In particular, it is heavily used for recurrent neural networks -and sequence-to-sequence models. +변수 범위를 사용하는 몇 가지 화일들을 소개합니다. 특히, RNN(recurrent neural networks) 과 sequence-to-sequence 모델들에 매우 많이 사용됩니다. 화일 | 내용 --- | --- From 4b0ed7a8b0f770e366d0b8500060a2b84bbc106e Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:55:44 -0400 Subject: [PATCH 41/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index 7b64e7e..1e0e45f 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -361,7 +361,7 @@ we do not alter the current name scope for ops. ## 사용 예 -변수 범위를 사용하는 몇 가지 화일들을 소개합니다. 특히, RNN(recurrent neural networks) 과 sequence-to-sequence 모델들에 매우 많이 사용됩니다. +변수 범위를 사용하는 화일들을 소개합니다. 특히, RNN(recurrent neural networks) 과 sequence-to-sequence 모델들에 매우 많이 사용됩니다. 화일 | 내용 --- | --- From 2802f7279970341091c946a001c995607200252d Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:55:59 -0400 Subject: [PATCH 42/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index 1e0e45f..b00a1af 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -361,7 +361,7 @@ we do not alter the current name scope for ops. ## 사용 예 -변수 범위를 사용하는 화일들을 소개합니다. 특히, RNN(recurrent neural networks) 과 sequence-to-sequence 모델들에 매우 많이 사용됩니다. +변수 범위를 사용하는 화일들을 몇 개 소개합니다. 특히, RNN(recurrent neural networks) 과 sequence-to-sequence 모델들에 매우 많이 사용됩니다. 화일 | 내용 --- | --- From 84d23fa8c44f18b47a879c7d15cd3b13d4420468 Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 00:56:28 -0400 Subject: [PATCH 43/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index b00a1af..9882f13 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -361,7 +361,7 @@ we do not alter the current name scope for ops. ## 사용 예 -변수 범위를 사용하는 화일들을 몇 개 소개합니다. 특히, RNN(recurrent neural networks) 과 sequence-to-sequence 모델들에 매우 많이 사용됩니다. +변수 범위를 사용하는 화일들을 몇 개 소개합니다. RNN(recurrent neural networks) 과 sequence-to-sequence 모델들에 특히 많이 사용됩니다. 화일 | 내용 --- | --- From 2d2581abc42113c3075c14a03ca452a417d71c3b Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 10:14:55 -0400 Subject: [PATCH 44/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index 9882f13..f72f1b4 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -1,11 +1,6 @@ # 변수 공유 -You can create, initialize, save and load single variables -in the way described in the [Variables HowTo](../../how_tos/variables/index.md). -But when building complex models you often need to share large sets of -variables and you might want to initialize all of them in one place. -This tutorial shows how this can be done using `tf.variable_scope()` and -the `tf.get_variable()`. +[Variables HowTo](../../how_tos/variables/index.md) 에 적혀있는 설명을 따라, 개별 변수들을 생성하고, 초기화하며, 저장 및 읽어들이기를 할 수 있습니다. 하지만 복잡도가 높은 모델을 구축하는 경우에는, 종종 많은 수의 변수들을 공유하거나 변수들 전체를 한번에 초기화 할 필요가 생깁니다. 이 튜토리얼에서 `tf.variable_scope()` 와 `tf.get_variable()` 를 이용하여 어떻게 그런 작업들을 하는지 알 수 있습니다. ## 문제 From 7c15155d92d1a4292e058744e537770300bebbbb Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 12:02:40 -0400 Subject: [PATCH 45/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index f72f1b4..c8ba91f 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -4,11 +4,7 @@ ## 문제 -Imagine you create a simple model for image filters, similar to our -[Convolutional Neural Networks Tutorial](../../tutorials/deep_cnn/index.md) -model but with only 2 convolutions (for simplicity of this example). If you use -just `tf.Variable`, as explained in [Variables HowTo](../../how_tos/variables/index.md), -your model might look like this. +(간단한 예로서) 기존의 [Convolutional Neural Networks Tutorial](../../tutorials/deep_cnn/index.md) 모델과 비슷하지만 컨볼루션 레이어를 2개만 가지는 심플한 이미지 필터링 모델을 만든다고 가정합니다. [Variables HowTo](../../how_tos/variables/index.md) 에 설명되어 있는 것처럼 `tf.Variable` 만을 사용한다면, 다음과 비슷한 모델이 될 것입니다. ```python def my_image_filter(input_images): From e20daf0bf37292f1e680180ac791218691aa69c9 Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 12:07:30 -0400 Subject: [PATCH 46/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index c8ba91f..25a20b6 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -23,9 +23,8 @@ def my_image_filter(input_images): return tf.nn.relu(conv2 + conv2_biases) ``` -As you can easily imagine, models quickly get much more complicated than -this one, and even here we already have 4 different variables: `conv1_weights`, -`conv1_biases`, `conv2_weights`, and `conv2_biases`. +짐작 가능하듯이, 모델들은 금방 이보다 훨씬 복잡해집니다. 이 모델에조차도 벌써 4개의 변수가 있습니다: `conv1_weights`, +`conv1_biases`, `conv2_weights`, `conv2_biases` The problem arises when you want to reuse this model. Assume you want to apply your image filter to 2 different images, `image1` and `image2`. From 389d7b1e162d1edfe6690133a3cce6d5c7b3703c Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 12:08:20 -0400 Subject: [PATCH 47/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index 25a20b6..a616801 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -23,7 +23,7 @@ def my_image_filter(input_images): return tf.nn.relu(conv2 + conv2_biases) ``` -짐작 가능하듯이, 모델들은 금방 이보다 훨씬 복잡해집니다. 이 모델에조차도 벌써 4개의 변수가 있습니다: `conv1_weights`, +짐작 가능하듯이, 모델들은 쉽게 이보다 훨씬 복잡해집니다. 이 모델조차도 벌써 변수가 4개입니다: `conv1_weights`, `conv1_biases`, `conv2_weights`, `conv2_biases` The problem arises when you want to reuse this model. Assume you want to From 796d75300b02ad7366cf54bf02013e50c713c931 Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 13:46:51 -0400 Subject: [PATCH 48/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index a616801..a82b7c6 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -26,6 +26,7 @@ def my_image_filter(input_images): 짐작 가능하듯이, 모델들은 쉽게 이보다 훨씬 복잡해집니다. 이 모델조차도 벌써 변수가 4개입니다: `conv1_weights`, `conv1_biases`, `conv2_weights`, `conv2_biases` +문제는 이 모델을 재사용하고자 할 때 생깁니다. 예를 들어, 이 필터링 모델을 `image1` 과 `image2` 라는 2개의 다른 이미지에 적용하는 경우입니다. 두 이미지 모두를 같은 파라미터를 가지는 같은 모델로 처리하고자 하는 것입니다. `my_image_filter()`를 두번 호출하면 되지만, 이렇게 하면 변수를 두 세트를 만들게 됩니다. The problem arises when you want to reuse this model. Assume you want to apply your image filter to 2 different images, `image1` and `image2`. You want both images processed by the same filter with the same parameters. From 73064fb9d8ec4f98e32c7e91ffeefeebe6179d6d Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 19:41:56 -0400 Subject: [PATCH 49/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index a82b7c6..f1b2415 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -27,11 +27,6 @@ def my_image_filter(input_images): `conv1_biases`, `conv2_weights`, `conv2_biases` 문제는 이 모델을 재사용하고자 할 때 생깁니다. 예를 들어, 이 필터링 모델을 `image1` 과 `image2` 라는 2개의 다른 이미지에 적용하는 경우입니다. 두 이미지 모두를 같은 파라미터를 가지는 같은 모델로 처리하고자 하는 것입니다. `my_image_filter()`를 두번 호출하면 되지만, 이렇게 하면 변수를 두 세트를 만들게 됩니다. -The problem arises when you want to reuse this model. Assume you want to -apply your image filter to 2 different images, `image1` and `image2`. -You want both images processed by the same filter with the same parameters. -You can call `my_image_filter()` twice, but this will create two sets -of variables: ```python # First call creates one set of variables. @@ -40,6 +35,7 @@ result1 = my_image_filter(image1) result2 = my_image_filter(image2) ``` +변수를 공유하는 일반적인 방법은 A common way to share variables is to create them in a separate piece of code and pass them to functions that use them. For example by using a dictionary: From 135bc791ec615c6ca1a2806ca76f2989d09511c3 Mon Sep 17 00:00:00 2001 From: totuta Date: Sat, 18 Jun 2016 20:45:12 -0400 Subject: [PATCH 50/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index f1b2415..a8a02c6 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -35,9 +35,7 @@ result1 = my_image_filter(image1) result2 = my_image_filter(image2) ``` -변수를 공유하는 일반적인 방법은 -A common way to share variables is to create them in a separate piece of code -and pass them to functions that use them. For example by using a dictionary: +변수를 공유하는 일반적인 방법은, 변수들을 따로 먼저 생성하여 그것들을 사용하게 될 함수들에 넘겨주는 것입니다. 예컨대 딕셔너리를 사용하여 다음과 같이 합니다: ```python variables_dict = { From db2ad6c4f5af92be7a33529032f5c4f038d49d35 Mon Sep 17 00:00:00 2001 From: totuta Date: Sun, 19 Jun 2016 00:08:16 -0400 Subject: [PATCH 51/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index a8a02c6..b04c81a 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -1,6 +1,6 @@ # 변수 공유 -[Variables HowTo](../../how_tos/variables/index.md) 에 적혀있는 설명을 따라, 개별 변수들을 생성하고, 초기화하며, 저장 및 읽어들이기를 할 수 있습니다. 하지만 복잡도가 높은 모델을 구축하는 경우에는, 종종 많은 수의 변수들을 공유하거나 변수들 전체를 한번에 초기화 할 필요가 생깁니다. 이 튜토리얼에서 `tf.variable_scope()` 와 `tf.get_variable()` 를 이용하여 어떻게 그런 작업들을 하는지 알 수 있습니다. +[Variables HowTo](../../how_tos/variables/index.md) 에 적혀있는 설명대로, 개별 변수들을 생성하고, 초기화하며, 저장 및 읽어들이기를 할 수 있습니다. 하지만 복잡도가 높은 모델을 구축하는 경우에는, 종종 많은 수의 변수들을 공유하거나 변수들 전체를 한번에 초기화 할 필요가 생깁니다. 이 튜토리얼에서 `tf.variable_scope()` 와 `tf.get_variable()` 를 이용하여 어떻게 그런 작업들을 하는지 알 수 있습니다. ## 문제 From 3f274e7f71789f3535fa0e25bb572251cdb61384 Mon Sep 17 00:00:00 2001 From: totuta Date: Sun, 19 Jun 2016 00:18:56 -0400 Subject: [PATCH 52/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index b04c81a..0bf05f1 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -59,13 +59,10 @@ result1 = my_image_filter(image1, variables_dict) result2 = my_image_filter(image2, variables_dict) ``` -While convenient, creating variables like above, -outside of the code, breaks encapsulation: +간편하기는 하지만, 위의 예처럼 변수를 코드 바깥에서 만들어서 사용하면, 캡슐화(encapsulation)를 못하게 됩니다: -* The code that builds the graph must document the names, types, - and shapes of variables to create. -* When the code changes, the callers may have to create more, or less, - or different variables. +* 생성될 변수들의 형태, 타입, 명칭들은 반드시 그래프를 구축하는 코드안에 명기되어야 한다. +* 코드가 변경되는 경우, 호출자는 변수들을 더 많거나 적게 생성하거나, 또는 다른 변수들을 생성해야 하는 경우가 있다. One way to address the problem is to use classes to create a model, where the classes take care of managing the variables they need. From f7a7c5eebf5d31aad2061f8532b0e2463bcd2f90 Mon Sep 17 00:00:00 2001 From: totuta Date: Sun, 19 Jun 2016 00:24:43 -0400 Subject: [PATCH 53/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index 0bf05f1..ec3d76c 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -64,15 +64,11 @@ result2 = my_image_filter(image2, variables_dict) * 생성될 변수들의 형태, 타입, 명칭들은 반드시 그래프를 구축하는 코드안에 명기되어야 한다. * 코드가 변경되는 경우, 호출자는 변수들을 더 많거나 적게 생성하거나, 또는 다른 변수들을 생성해야 하는 경우가 있다. -One way to address the problem is to use classes to create a model, -where the classes take care of managing the variables they need. -For a lighter solution, not involving classes, TensorFlow provides -a *Variable Scope* mechanism that allows to easily share named variables -while constructing a graph. +이 문제에 대한 하나의 해결책은 클래스를 이용하여 모델을 생성하는 것입니다. 이 경우, 클래스가 변수들을 관리합니다. 클래스를 사용하지 않는 라이트한(간결한) 해결책으로써, 텐서플로우에서는 *변수 범위* 라는 메커니즘이 제공됩니다. 이것을 사용하면 그래프를 만들면서 (이름을 가진) 변수들을 쉽게 공유할 수 있습니다. ## 변수 범위 예 -Variable Scope mechanism in TensorFlow consists of 2 main functions: +텐서플로우의 변수 범위 메커니즘은 2개의 메인 함수로 이루어집니다: * `tf.get_variable(, , )`: Creates or returns a variable with a given name. From 5435670b00c3c80297a5a2b725dc554104cf8054 Mon Sep 17 00:00:00 2001 From: totuta Date: Sun, 19 Jun 2016 00:27:31 -0400 Subject: [PATCH 54/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index ec3d76c..b3505a0 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -71,9 +71,9 @@ result2 = my_image_filter(image2, variables_dict) 텐서플로우의 변수 범위 메커니즘은 2개의 메인 함수로 이루어집니다: * `tf.get_variable(, , )`: - Creates or returns a variable with a given name. + 주어진 이름을 가진 변수를 만들거나 리턴합니다. * `tf.variable_scope()`: - Manages namespaces for names passed to `tf.get_variable()`. + `tf.get_variable()` 에 넘겨주는 명칭들의 네임스페이스를 관리합니다. The function `tf.get_variable()` is used to get or create a variable instead of a direct call to `tf.Variable`. It uses an *initializer* instead of passing From c2e02df445dc8eb83a069c89e39d88cab73f1eee Mon Sep 17 00:00:00 2001 From: totuta Date: Sun, 19 Jun 2016 00:28:43 -0400 Subject: [PATCH 55/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index b3505a0..9e4437f 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -64,9 +64,9 @@ result2 = my_image_filter(image2, variables_dict) * 생성될 변수들의 형태, 타입, 명칭들은 반드시 그래프를 구축하는 코드안에 명기되어야 한다. * 코드가 변경되는 경우, 호출자는 변수들을 더 많거나 적게 생성하거나, 또는 다른 변수들을 생성해야 하는 경우가 있다. -이 문제에 대한 하나의 해결책은 클래스를 이용하여 모델을 생성하는 것입니다. 이 경우, 클래스가 변수들을 관리합니다. 클래스를 사용하지 않는 라이트한(간결한) 해결책으로써, 텐서플로우에서는 *변수 범위* 라는 메커니즘이 제공됩니다. 이것을 사용하면 그래프를 만들면서 (이름을 가진) 변수들을 쉽게 공유할 수 있습니다. +이 문제에 대한 하나의 해결책은 클래스를 이용하여 모델을 생성하는 것입니다. 이 경우, 클래스가 변수들을 관리합니다. 클래스를 사용하지 않는 라이트한(간결한) 해결책으로써, 텐서플로우에서는 *변수 범위(Variable scope)* 라는 메커니즘이 제공됩니다. 이것을 사용하면 그래프를 만들면서 (이름을 가진) 변수들을 쉽게 공유할 수 있습니다. -## 변수 범위 예 +## 변수 범위(Variable Scope) 예 텐서플로우의 변수 범위 메커니즘은 2개의 메인 함수로 이루어집니다: From 07108068aa289b995206822a0a83ee1ea9bb3a1b Mon Sep 17 00:00:00 2001 From: totuta Date: Sun, 19 Jun 2016 00:31:07 -0400 Subject: [PATCH 56/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index 9e4437f..f4571b3 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -73,7 +73,7 @@ result2 = my_image_filter(image2, variables_dict) * `tf.get_variable(, , )`: 주어진 이름을 가진 변수를 만들거나 리턴합니다. * `tf.variable_scope()`: - `tf.get_variable()` 에 넘겨주는 명칭들의 네임스페이스를 관리합니다. + `tf.get_variable()` 에 넘겨주는 이름들의 이름공간(namespace)를 관리합니다. The function `tf.get_variable()` is used to get or create a variable instead of a direct call to `tf.Variable`. It uses an *initializer* instead of passing From 515e1496d715d118ca342f3c108bab7c59df4200 Mon Sep 17 00:00:00 2001 From: totuta Date: Sun, 19 Jun 2016 00:31:27 -0400 Subject: [PATCH 57/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index f4571b3..dbcaf81 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -73,7 +73,7 @@ result2 = my_image_filter(image2, variables_dict) * `tf.get_variable(, , )`: 주어진 이름을 가진 변수를 만들거나 리턴합니다. * `tf.variable_scope()`: - `tf.get_variable()` 에 넘겨주는 이름들의 이름공간(namespace)를 관리합니다. + `tf.get_variable()` 에 넘겨주는 이름들의 이름공간(namespace)을 관리합니다. The function `tf.get_variable()` is used to get or create a variable instead of a direct call to `tf.Variable`. It uses an *initializer* instead of passing From e38bb8d7e283c38b6e622d6f68bc0793e3b3c545 Mon Sep 17 00:00:00 2001 From: totuta Date: Sun, 19 Jun 2016 11:02:40 -0400 Subject: [PATCH 58/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index dbcaf81..062d2c2 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -75,11 +75,7 @@ result2 = my_image_filter(image2, variables_dict) * `tf.variable_scope()`: `tf.get_variable()` 에 넘겨주는 이름들의 이름공간(namespace)을 관리합니다. -The function `tf.get_variable()` is used to get or create a variable instead -of a direct call to `tf.Variable`. It uses an *initializer* instead of passing -the value directly, as in `tf.Variable`. An initializer is a function that -takes the shape and provides a tensor with that shape. Here are some -initializers available in TensorFlow: +`tf.Variable` 를 직접 호출하지 않고, `tf.get_variable()` 함수를 사용하여 변수를 생성하거나 얻습니다(get). `tf.Variable` 처럼 값을 직접 넘겨주는 것이 아니라 *initializer* 를 사용합니다. initializer 는 형태를 입력으로 받아서 그 형태를 가진 텐서를 돌려주는 함수입니다. 텐서플로우에서 사용가능한 initializer 의 예들은 다음과 같습니다: * `tf.constant_initializer(value)` initializes everything to the provided value, * `tf.random_uniform_initializer(a, b)` initializes uniformly from [a, b], From 8851b8e75b69a549421e9b7d3c94025d9b2580e3 Mon Sep 17 00:00:00 2001 From: totuta Date: Sun, 19 Jun 2016 11:16:17 -0400 Subject: [PATCH 59/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index 062d2c2..3f5e56b 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -77,10 +77,10 @@ result2 = my_image_filter(image2, variables_dict) `tf.Variable` 를 직접 호출하지 않고, `tf.get_variable()` 함수를 사용하여 변수를 생성하거나 얻습니다(get). `tf.Variable` 처럼 값을 직접 넘겨주는 것이 아니라 *initializer* 를 사용합니다. initializer 는 형태를 입력으로 받아서 그 형태를 가진 텐서를 돌려주는 함수입니다. 텐서플로우에서 사용가능한 initializer 의 예들은 다음과 같습니다: -* `tf.constant_initializer(value)` initializes everything to the provided value, -* `tf.random_uniform_initializer(a, b)` initializes uniformly from [a, b], -* `tf.random_normal_initializer(mean, stddev)` initializes from the normal - distribution with the given mean and standard deviation. +* `tf.constant_initializer(value)` (어떤 변수라도) 주어진 값으로 초기화, +* `tf.random_uniform_initializer(a, b)` [a, b] 범위의 연속균등분포(uniform distribution)로 초기화, +* `tf.random_normal_initializer(mean, stddev)` 주어진 평균과 표준편차를 갖는 정규분포(normal + distribution)로 초기화. To see how `tf.get_variable()` solves the problem discussed before, let's refactor the code that created one convolution into From 2e0ec727fb4d95195e63d0985d541396cb7419cc Mon Sep 17 00:00:00 2001 From: totuta Date: Sun, 19 Jun 2016 11:17:23 -0400 Subject: [PATCH 60/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index 3f5e56b..18af233 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -82,6 +82,7 @@ result2 = my_image_filter(image2, variables_dict) * `tf.random_normal_initializer(mean, stddev)` 주어진 평균과 표준편차를 갖는 정규분포(normal distribution)로 초기화. +위에서 설명한 문제를 `tf.get_variable()` 함수가 어떻게 해결하는지 알아보기 위하여, To see how `tf.get_variable()` solves the problem discussed before, let's refactor the code that created one convolution into a separate function, named `conv_relu`: From 03d5af5d0b867f82c5683a503c838f418921707e Mon Sep 17 00:00:00 2001 From: totuta Date: Sun, 19 Jun 2016 11:19:02 -0400 Subject: [PATCH 61/63] working on variable_scope/index.md --- g3doc/how_tos/variable_scope/index.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index 18af233..d584c15 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -82,10 +82,7 @@ result2 = my_image_filter(image2, variables_dict) * `tf.random_normal_initializer(mean, stddev)` 주어진 평균과 표준편차를 갖는 정규분포(normal distribution)로 초기화. -위에서 설명한 문제를 `tf.get_variable()` 함수가 어떻게 해결하는지 알아보기 위하여, -To see how `tf.get_variable()` solves the problem discussed -before, let's refactor the code that created one convolution into -a separate function, named `conv_relu`: +위에서 설명한 문제를 `tf.get_variable()` 함수가 어떻게 해결하는지 알아보기 위하여, 하나의 컨볼루션을 생성했던 코드를 `conv_relu` 라는 이름을 갖는 별도의 함수로 분해하여 봅시다. ```python def conv_relu(input, kernel_shape, bias_shape): From d0051212ee6037dccbe84d09be333433207cc77b Mon Sep 17 00:00:00 2001 From: SanggiHong Date: Sat, 15 Oct 2016 20:38:26 +0900 Subject: [PATCH 62/63] Translate g3doc/how_tos/variable_scope/index.md Modify some missed things Final works --- g3doc/how_tos/variable_scope/index.md | 245 +++++++++++--------------- 1 file changed, 106 insertions(+), 139 deletions(-) diff --git a/g3doc/how_tos/variable_scope/index.md b/g3doc/how_tos/variable_scope/index.md index e3b0214..61266ff 100644 --- a/g3doc/how_tos/variable_scope/index.md +++ b/g3doc/how_tos/variable_scope/index.md @@ -1,19 +1,18 @@ -# Sharing Variables +# 변수 공유 -You can create, initialize, save and load single variables -in the way described in the [Variables HowTo](../../how_tos/variables/index.md). -But when building complex models you often need to share large sets of -variables and you might want to initialize all of them in one place. -This tutorial shows how this can be done using `tf.variable_scope()` and -the `tf.get_variable()`. +여러분은 다음과 같은 방법으로 변수를 생성, 초기화, 저장, 복구할 수 있습니다. +[Variables HowTo](../../how_tos/variables/index.md). +하지만 더욱 복잡한 모델을 설계할 때에, 여러분은 종종 거대한 변수 set을 공유하거나, +해당 변수들을 한곳에서 초기화할 필요가 있습니다. +이 튜토리얼은 여러분이 `tf.variable_scope()`와 `tf.get_variable()`를 어떻게 사용하는 지 보여줍니다. -## The Problem +## 문제 -Imagine you create a simple model for image filters, similar to our +이미지 필터를 위한 간단한 모델을 하나 만든다고 생각해봅시다. [Convolutional Neural Networks Tutorial](../../tutorials/deep_cnn/index.md) -model but with only 2 convolutions (for simplicity of this example). If you use -just `tf.Variable`, as explained in [Variables HowTo](../../how_tos/variables/index.md), -your model might look like this. +모델과 비슷하지만 (예시를 간단하게 하기 위해) 오직 2개의 convolution을 갖는 모델일 때, 여러분이 +[Variables HowTo](../../how_tos/variables/index.md)에서 봤던 `tf.Variable`만을 사용한다면, +모델은 이렇게 만들어질 것입니다. ```python def my_image_filter(input_images): @@ -32,15 +31,13 @@ def my_image_filter(input_images): return tf.nn.relu(conv2 + conv2_biases) ``` -As you can easily imagine, models quickly get much more complicated than -this one, and even here we already have 4 different variables: `conv1_weights`, -`conv1_biases`, `conv2_weights`, and `conv2_biases`. +여러분의 생각과 같이, 모델은 이보다 더 복잡해질 것입니다. +게다가 우리는 이미 4개의 다른 변수: `conv1_weights`, `conv1_biases`, `conv2_weights`, `conv2_biases`를 가지고있습니다 -The problem arises when you want to reuse this model. Assume you want to -apply your image filter to 2 different images, `image1` and `image2`. -You want both images processed by the same filter with the same parameters. -You can call `my_image_filter()` twice, but this will create two sets -of variables: +이제 문제는 우리가 이 모델을 재사용할 때 발생합니다. +이미지 필터를 두개의 다른 이미지 `image1`와 `image2`에 적용한다고 가정합시다. +두 이미지에 같은 필터로 같은 parameters값을 적용하고 싶다면, +다음과 같이 `my_image_filter()` 를 두번 호출하면 됩니다. 다만 이것은 두 개의 변수 set을 생성하게 될 것입니다: ```python # First call creates one set of variables. @@ -49,8 +46,8 @@ result1 = my_image_filter(image1) result2 = my_image_filter(image2) ``` -A common way to share variables is to create them in a separate piece of code -and pass them to functions that use them. For example by using a dictionary: +변수를 공유하는 가장 일반적인 방법은 변수 선언을 다른 조각으로 분리하고, 함수에 전달하여 사용하는것입니다. +dictionary를 사용한 예: ```python variables_dict = { @@ -74,43 +71,35 @@ result1 = my_image_filter(image1, variables_dict) result2 = my_image_filter(image2, variables_dict) ``` -While convenient, creating variables like above, -outside of the code, breaks encapsulation: +변수들을 위처럼 코드 바깥에 만들면, 편리한 반면에 encapsulation 속성을 해치게 됩니다: -* The code that builds the graph must document the names, types, - and shapes of variables to create. -* When the code changes, the callers may have to create more, or less, - or different variables. +* 그래프를 그리기 위한 코드는 생성할 변수의 이름, 타입, 형태(shape)를 기재해야 합니다. +* 코드가 변하면, 호출자는 더 많거나, 적거나 또는 다른 변수들을 생성해야 될 수도 있습니다. -One way to address the problem is to use classes to create a model, -where the classes take care of managing the variables they need. -For a lighter solution, not involving classes, TensorFlow provides -a *Variable Scope* mechanism that allows to easily share named variables -while constructing a graph. +이를 해결하기 위한 하나의 방법은, 모델을 만드는 클래스를 사용하고, 클래스에서 필요한 변수들을 관리하는 것입니다. +클래스를 사용하지 않는 좀 더 가벼운 해결방법을 위해 텐서플로우는 그래프를 그릴 수 있는 동시에, 이름을 갖는 변수들을 공유가능한 +*변수 scope(Variable Scope)* 메커니즘을 제공합니다. -## Variable Scope Example +## 변수 scope 예제 -Variable Scope mechanism in TensorFlow consists of 2 main functions: +텐서플로우의 변수 scope 메커니즘은 2가지 main function을 가집니다: * `tf.get_variable(, , )`: - Creates or returns a variable with a given name. + 주어진 이름의 변수를 만들거나 리턴합니다. * `tf.variable_scope()`: - Manages namespaces for names passed to `tf.get_variable()`. + `tf.get_variable()`에 전달됐던 이름들에 대한 namespace들을 관리합니다. -The function `tf.get_variable()` is used to get or create a variable instead -of a direct call to `tf.Variable`. It uses an *initializer* instead of passing -the value directly, as in `tf.Variable`. An initializer is a function that -takes the shape and provides a tensor with that shape. Here are some -initializers available in TensorFlow: +함수 `tf.get_variable()`는 `tf.Variable`를 직접 호출하는 대신 변수를 생성하거나 얻는데에 쓰입니다. +해당 함수는 변수를 직접 전달하는 대신 *initializer* 를 이용합니다. `tf.Variable`에서와 같이, +initializer는 형태(shape)를 취해 텐서와 형태(shape)를 제공하는 함수입니다. +텐서플로우에서 이용가능한 initializer들을 아래에서 확인하실 수 있습니다: -* `tf.constant_initializer(value)` initializes everything to the provided value, -* `tf.random_uniform_initializer(a, b)` initializes uniformly from [a, b], -* `tf.random_normal_initializer(mean, stddev)` initializes from the normal - distribution with the given mean and standard deviation. +* `tf.constant_initializer(value)` 제공된 값으로 모든것들을 초기화합니다, +* `tf.random_uniform_initializer(a, b)` a와 b를 포함하는 사이의 값([a, b])들 중에서 균등한 분포의 임의값들로 초기화합니다, +* `tf.random_normal_initializer(mean, stddev)` 주어진 평균값과 표준편차를 가지는 정규분포에서, 이를 따르는 임의값들로 초기화합니다. -To see how `tf.get_variable()` solves the problem discussed -before, let's refactor the code that created one convolution into -a separate function, named `conv_relu`: +전에 이야기한 문제를 `tf.get_variable()`를 통해 어떻게 해결하는지 보기 위해, +코드를 하나의 convolution을 만드는 분리된 함수 `conv_relu`로 refactor 해봅시다: ```python def conv_relu(input, kernel_shape, bias_shape): @@ -125,11 +114,10 @@ def conv_relu(input, kernel_shape, bias_shape): return tf.nn.relu(conv + biases) ``` -This function uses short names `"weights"` and `"biases"`. -We'd like to use it for both `conv1` and `conv2`, but -the variables need to have different names. -This is where `tf.variable_scope()` comes into play: -it pushes a namespace for variables. +이 함수는 변수들의 이름으로 간결하게 `"weights"` 와 `"biases"`를 사용합니다. +우리는 이것을 `conv1`과 `conv2`에 사용하고싶지만, 각각의 변수들은 다른 이름을 가져야 합니다. +자, 이제 `tf.variable_scope()`가 역할을 할 차례입니다: +이것은 변수들이 namespace를 갖도록 해줍니다. ```python def my_image_filter(input_images): @@ -141,7 +129,7 @@ def my_image_filter(input_images): return conv_relu(relu1, [5, 5, 32, 32], [32]) ``` -Now, let's see what happens when we call `my_image_filter()` twice. +자, 이제 우리가 `my_image_filter()`를 두번 호출했을 때 무슨 일이 일어나는지 봅시다. ``` result1 = my_image_filter(image1) @@ -149,9 +137,8 @@ result2 = my_image_filter(image2) # Raises ValueError(... conv1/weights already exists ...) ``` -As you can see, `tf.get_variable()` checks that already existing variables -are not shared by accident. If you want to share them, you need to specify -it by setting `reuse_variables()` as follows. +보시다시피, `tf.get_variable()` 는 이미 존재하는 변수들이 우연히라도 공유되지 않도록 검사합니다. +만약 여러분이 변수를 공유하고 싶다면, 다음과 같이 `reuse_variables()`를 통해 명시해야 합니다. ``` with tf.variable_scope("image_filters") as scope: @@ -160,33 +147,29 @@ with tf.variable_scope("image_filters") as scope: result2 = my_image_filter(image2) ``` -This is a good way to share variables, lightweight and safe. +이것이 변수들을 공유하는, 간단하고 안전한 방법입니다. -## How Does Variable Scope Work? +## 변수 scope는 어떻게 동작하나요? -### Understanding `tf.get_variable()` +### `tf.get_variable()`에 대한 이해 -To understand variable scope it is necessary to first -fully understand how `tf.get_variable()` works. -Here is how `tf.get_variable` is usually called. +변수 scope를 이해하기 위해 먼저 `tf.get_variable()`가 어떻게 동작하는지 완벽히 이해해야 합니다. +아래는 `tf.get_variable`가 호출되는 일반적인 경우입니다. ```python v = tf.get_variable(name, shape, dtype, initializer) ``` -This call does one of two things depending on the scope it is called in. -Here are the two options. +이 경우 함수 호출이 포함된 스코프에 따라 둘 중 하나를 실행합니다. +여기 두 가지 경우가 있습니다. -* Case 1: the scope is set for creating new variables, as evidenced by -`tf.get_variable_scope().reuse == False`. +* 경우 1: `tf.get_variable_scope().reuse == False`에 따라서 scope가 새 변수를 만들도록 설정되어 있을 경우. -In this case, `v` will be a newly created `tf.Variable` with the provided -shape and data type. The full name of the created variable will be set to -the current variable scope name + the provided `name` and a check will be -performed to ensure that no variable with this full name exists yet. -If a variable with this full name already exists, the function will -raise a `ValueError`. If a new variable is created, it will be -initialized to the value `initializer(shape)`. For example: +이 경우, `v`는 제공된 형태(shape)와 데이터 타입에 따라 새로 생성된 `tf.Variable`입니다. +생성된 변수의 완전한 이름은 (현재 scope 이름 + 제공된 `name`)가 되고, +이미 존재하는 변수의 이름과 겹치지 않는지 검증하는 과정이 이루어집니다. +만약 이름이 일치하는 변수가 이미 존재한다면, 함수는 `ValueError`를 발생시킵니다. +새로운 변수가 생성된다면 변수는 `initializer(shape)`의 값으로 초기화됩니다. 예시: ```python with tf.variable_scope("foo"): @@ -194,13 +177,10 @@ with tf.variable_scope("foo"): assert v.name == "foo/v:0" ``` -* Case 2: the scope is set for reusing variables, as evidenced by -`tf.get_variable_scope().reuse == True`. +* 경우 2: `tf.get_variable_scope().reuse == True`에 따라서 scope가 변수를 재사용하도록 설정되어 있을 경우. -In this case, the call will search for an already existing variable with -name equal to the current variable scope name + the provided `name`. -If no such variable exists, a `ValueError` will be raised. If the variable -is found, it will be returned. For example: +이 경우, 호출은 (현재 scope 이름 + 제공된 `name`)을 가진 이미 존재하는 변수를 찾는 형태로 이루어집니다. +만약 해당 변수가 존재하지 않는다면, `ValueError`를 발생시킵니다. 해당 변수가 존재한다면 해당 변수를 리턴합니다. 예시: ```python with tf.variable_scope("foo"): @@ -210,13 +190,11 @@ with tf.variable_scope("foo", reuse=True): assert v1 == v ``` -### Basics of `tf.variable_scope()` +### `tf.variable_scope()`의 기본 -Knowing how `tf.get_variable()` works makes it easy to understand variable -scope. The primary function of variable scope is to carry a name that will -be used as prefix for variable names and a reuse-flag to distinguish the two -cases described above. Nesting variable scopes appends their names in a way -analogous to how directories work: +`tf.get_variable()`이 어떻게 동작하는지 아는 것은 변수 scope를 이해하기 쉽게 해줍니다. +변수 scope의 주요한 기능은 변수 이름의 접두사로 붙일 이름과, 앞서 설명한 두가지 경우를 구별하기 위한 reuse-flag를 지니는 것입니다. +중첩된 변수 scope는 디렉토리와 유사한 방식으로 이름을 덧붙입니다: ```python with tf.variable_scope("foo"): @@ -225,9 +203,8 @@ with tf.variable_scope("foo"): assert v.name == "foo/bar/v:0" ``` -The current variable scope can be retrieved using `tf.get_variable_scope()` -and the `reuse` flag of the current variable scope can be set to `True` by -calling `tf.get_variable_scope().reuse_variables()`: +현재 변수 scope를 `tf.get_variable_scope()`를 통해 가져올 수 있습니다. +그리고 `tf.get_variable_scope().reuse_variables()`를 호출하여 현재 변수 scope의 `reuse` flag를 `True`로 설정할 수 있습니다: ```python with tf.variable_scope("foo"): @@ -237,19 +214,17 @@ with tf.variable_scope("foo"): assert v1 == v ``` -Note that you *cannot* set the `reuse` flag to `False`. The reason behind -this is to allow to compose functions that create models. Imagine you write -a function `my_image_filter(inputs)` as before. Someone calling the function -in a variable scope with `reuse=True` would expect all inner variables to be -reused as well. Allowing to force `reuse=False` inside the function would break -this contract and make it hard to share parameters in this way. +`reuse` flag를 `False`로 *설정할 수 없다* 는 것을 명심하세요. +이유는 모델을 만드는 함수를 구성하는 데에서 찾을 수 있습니다. +전처럼 `my_image_filter(inputs)`함수를 만든다고 생각해 봅시다. +`reuse=True`된 scope 안에서 그 함수를 호출하는 누군가는 함수 내의 변수 또한 재사용되기를 바랄 수 있습니다. +함수 내에서 `reuse=False`를 허락하는 것은 이 약속을 깨버릴 뿐더러 파라미터의 공유 또한 어렵게 만들어 버립니다. -Even though you cannot set `reuse` to `False` explicitly, you can enter -a reusing variable scope and then exit it, going back to a non-reusing one. -This can be done using a `reuse=True` parameter when opening a variable scope. -Note also that, for the same reason as above, the `reuse` parameter is -inherited. So when you open a reusing variable scope, all sub-scopes will -be reusing too. +`reuse`를 `False`로 명시적으로 설정할 수 없더라도 여러분은 변수를 재사용하는 scope에 들어왔다 나가서, +재사용하지 않는 scope로 돌아갈 수 있습니다. +이는 scope를 설정할 때, `reuse=True` 파라미터를 사용함으로써 가능합니다. +또한 위와 같은 이유로 `reuse` 파라미터는 상속된다는 것을 명심하세요. 따라서 한번 변수를 재사용하는 scope를 설정헀다면, +해당 scope의 모든 sub-scope는 변수를 재사용하게 됩니다. ```python with tf.variable_scope("root"): @@ -268,14 +243,12 @@ with tf.variable_scope("root"): assert tf.get_variable_scope().reuse == False ``` -### Capturing variable scope +### scope 가져오기 -In all examples presented above, we shared parameters only because their -names agreed, that is, because we opened a reusing variable scope with -exactly the same string. In more complex cases, it might be useful to pass -a VariableScope object rather than rely on getting the names right. -To this end, variable scopes can be captured and used instead of names -when opening a new variable scope. +위의 모든 예시에선, 우리는 같은 이름으로만 변수들을 재사용 할 수 있었습니다. +왜냐하면, 변수를 재사용하는 scope를 설정할 때 해당 스코프가 무엇인지를 string으로만 명시해주었기 때문입니다. +여러 복잡한 상황에선 scope들의 이름에만 의지하는 것보단 VariableScope 객체 자체를 전달하는 것이 더 유용할 수 있습니다. +이를 위해, 변수 scope를 설정할 때에 이름 대신 VariableScope 객체를 직접 전달할 수 있습니다. ```python with tf.variable_scope("foo") as foo_scope: @@ -289,9 +262,8 @@ assert v1 == v assert w1 == w ``` -When opening a variable scope using a previously existing scope -we jump out of the current variable scope prefix to an entirely -different one. This is fully independent of where we do it. +이미 존재하는 scope 객체를 이용하여 스코프를 설정할 때, +호출한 위치의 바깥에 설정되어있는 scope에 상관 없이 바로 다른 scope로 넘어갈 수 있습니다. ```python with tf.variable_scope("foo") as foo_scope: @@ -303,17 +275,15 @@ with tf.variable_scope("bar") assert foo_scope2.name == "foo" # Not changed. ``` -### Initializers in variable scope +### 변수 scope에 initializer 설정하기 -Using `tf.get_variable()` allows to write functions that create or reuse -variables and can be transparently called from outside. But what if we wanted -to change the initializer of the created variables? Do we need to pass an extra -argument to every function that creates variables? What about the most common -case, when we want to set the default initializer for all variables in one -place, on top of all functions? To help with these cases, variable scope -can carry a default initializer. It is inherited by sub-scopes and passed -to each `tf.get_variable()` call. But it will be overridden if another -initializer is specified explicitly. +`tf.get_variable()`를 사용하면 함수에서 변수들을 생성하고 재사용할 수 있게 하며, 이를 함수 외부에서 관여할 수 있게 해줍니다. +하지만 생성된 변수들의 initializer를 바꾸고 싶다면 어떻게 해야할까요? +추가적인 변수를 생성하는 argument를 모든 함수에 전달해야 할까요? +일반적인 경우는 어떤가요, 모든 변수의 default initializer를 모든 함수 호출 전의 한곳에서 설정하고 싶다면? +이런 경우를 위해, 변수 scope는 default initializer를 가질 수 있습니다. +이것은 sub-scope에도 상속되어 각각의 `tf.get_variable()` 호출에 전달됩니다. +다만 명시된 다른 initializer를 통해 override 할 수 있습니다. ```python with tf.variable_scope("foo", initializer=tf.constant_initializer(0.4)): @@ -329,13 +299,12 @@ with tf.variable_scope("foo", initializer=tf.constant_initializer(0.4)): assert v.eval() == 0.2 # Changed default initializer. ``` -### Names of ops in `tf.variable_scope()` +### `tf.variable_scope()` 안의 ops들의 이름 -We discussed how `tf.variable_scope` governs the names of variables. -But how does it influence the names of other ops in the scope? -It is natural that ops created inside a variable scope should also -share that name. For this reason, when we do `with tf.variable_scope("name")`, -this implicitly opens a `tf.name_scope("name")`. For example: +지금까지 `tf.variable_scope`가 어떻게 변수들의 이름을 관리하는 지 알아보았습니다. +그렇다면 이것이 scope 안의 ops들에 어떤 영향을 미칠까요? +변수 scope 안에 생성된 ops들 또한 scope의 이름을 공유하는것이 자연스럽기에, +`with tf.variable_scope("name")`를 설정한다면 암묵적으로 `tf.name_scope("name")` 또한 설정됩니다. 예시: ```python with tf.variable_scope("foo"): @@ -343,8 +312,8 @@ with tf.variable_scope("foo"): assert x.op.name == "foo/add" ``` -Name scopes can be opened in addition to a variable scope, and then -they will only affect the names of the ops, but not of variables. +또한 이름 scope를 변수 scope내에 설정할 수 있습니다. +이것은 오직 ops의 이름에만 영향을 주며, 변수에는 영향을 주지 않습니다. ```python with tf.variable_scope("foo"): @@ -355,18 +324,16 @@ assert v.name == "foo/v:0" assert x.op.name == "foo/bar/add" ``` -When opening a variable scope using a captured object instead of a string, -we do not alter the current name scope for ops. +string이 아닌 scope 객체를 전달하여 scope를 설정할 때엔, 이름 scope는 바뀌지 않습니다. ## Examples of Use -Here are pointers to a few files that make use of variable scope. -In particular, it is heavily used for recurrent neural networks -and sequence-to-sequence models. +여기에 변수 scope를 사용한 예시가 있습니다. +recurrent neural networks와 sequence-to-sequence models에는 특별히 많이 사용되었습니다. -File | What's in it? +파일 이름 | 내용 --- | --- -`models/image/cifar10.py` | Model for detecting objects in images. -`models/rnn/rnn_cell.py` | Cell functions for recurrent neural networks. -`models/rnn/seq2seq.py` | Functions for building sequence-to-sequence models. +`models/image/cifar10.py` | 이미지 속 물체를 인지하는 모델. +`models/rnn/rnn_cell.py` | recurrent neural networks를 위한 Cell function. +`models/rnn/seq2seq.py` | building sequence-to-sequence model 설계를 위한 Functions. From 3aaa650b88373a34b2b802f11940247414dbf3e5 Mon Sep 17 00:00:00 2001 From: SanggiHong Date: Mon, 17 Oct 2016 16:43:35 +0900 Subject: [PATCH 63/63] recover file loss --- g3doc/how_tos/variables/index.md | 253 +++++++++++++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 g3doc/how_tos/variables/index.md diff --git a/g3doc/how_tos/variables/index.md b/g3doc/how_tos/variables/index.md new file mode 100644 index 0000000..9a36cc3 --- /dev/null +++ b/g3doc/how_tos/variables/index.md @@ -0,0 +1,253 @@ +# 변수: 생성, 초기화, 저장, 복구 + +When you train a model, you use [variables](../../api_docs/python/state_ops.md) +to hold and update parameters. Variables are in-memory buffers containing +tensors. They must be explicitly initialized and can be saved to disk during +and after training. You can later restore saved values to exercise or analyse +the model. + +This document references the following TensorFlow classes. Follow the links to +their reference manual for a complete description of their API: + +* The [`tf.Variable`](../../api_docs/python/state_ops.md#Variable) class. +* The [`tf.train.Saver`](../../api_docs/python/state_ops.md#Saver) class. + + +## 생성 + +When you create a [Variable](../../api_docs/python/state_ops.md) you pass a +`Tensor` as its initial value to the `Variable()` constructor. TensorFlow +provides a collection of ops that produce tensors often used for initialization +from [constants or random values](../../api_docs/python/constant_op.md). + +Note that all these ops require you to specify the shape of the tensors. That +shape automatically becomes the shape of the variable. Variables generally +have a fixed shape, but TensorFlow provides advanced mechanisms to reshape +variables. + +```python +# Create two variables. +weights = tf.Variable(tf.random_normal([784, 200], stddev=0.35), + name="weights") +biases = tf.Variable(tf.zeros([200]), name="biases") +``` + +Calling `tf.Variable()` adds several ops to the graph: + +* A `variable` op that holds the variable value. +* An initializer op that sets the variable to its initial value. This is + actually a `tf.assign` op. +* The ops for the initial value, such as the `zeros` op for the `biases` + variable in the example are also added to the graph. + +The value returned by `tf.Variable()` value is an instance of the Python class +`tf.Variable`. + +### Device placement + +A variable can be pinned to a particular device when it is created, using a +[`with tf.device(...):`](../../api_docs/python/framework.md#device) block: + +```python +# Pin a variable to CPU. +with tf.device("/cpu:0"): + v = tf.Variable(...) + +# Pin a variable to GPU. +with tf.device("/gpu:0"): + v = tf.Variable(...) + +# Pin a variable to a particular parameter server task. +with tf.device("/job:ps/task:7"): + v = tf.Variable(...) +``` + +**N.B.** Operations that mutate a variable, such as +[`v.assign()`](../../api_docs/python/state.md#Variable.assign) and the parameter +update operations in a +[`tf.train.Optimizer`](../../api_docs/python/train.md#Optimizer) *must* run on +the same device as the variable. Incompatible device placement directives will +be ignored when creating these operations. + +Device placement is particularly important when running in a replicated +setting. See +[`tf.train.replica_device_setter()`](../../api_docs/python/train.md#replica_device_setter) +for details of a device function that can simplify the configuration for devices +for a replicated model. + +## 초기화 + +Variable initializers must be run explicitly before other ops in your model can +be run. The easiest way to do that is to add an op that runs all the variable +initializers, and run that op before using the model. + +You can alternatively restore variable values from a checkpoint file, see +below. + +Use `tf.initialize_all_variables()` to add an op to run variable initializers. +Only run that op after you have fully constructed your model and launched it in +a session. + +```python +# Create two variables. +weights = tf.Variable(tf.random_normal([784, 200], stddev=0.35), + name="weights") +biases = tf.Variable(tf.zeros([200]), name="biases") +... +# Add an op to initialize the variables. +init_op = tf.initialize_all_variables() + +# Later, when launching the model +with tf.Session() as sess: + # Run the init operation. + sess.run(init_op) + ... + # Use the model + ... +``` + +### 다른 변수값을 참조하여 초기화 하기 + +You sometimes need to initialize a variable from the initial value of another +variable. As the op added by `tf.initialize_all_variables()` initializes all +variables in parallel you have to be careful when this is needed. + +To initialize a new variable from the value of another variable use the other +variable's `initialized_value()` property. You can use the initialized value +directly as the initial value for the new variable, or you can use it as any +other tensor to compute a value for the new variable. + + +```python +# Create a variable with a random value. +weights = tf.Variable(tf.random_normal([784, 200], stddev=0.35), + name="weights") +# Create another variable with the same value as 'weights'. +w2 = tf.Variable(weights.initialized_value(), name="w2") +# Create another variable with twice the value of 'weights' +w_twice = tf.Variable(weights.initialized_value() * 2.0, name="w_twice") +``` + +### 커스텀 초기화 + +The convenience function `tf.initialize_all_variables()` adds an op to +initialize *all variables* in the model. You can also pass it an explicit list +of variables to initialize. See the +[Variables Documentation](../../api_docs/python/state_ops.md) for more options, +including checking if variables are initialized. + +## 저장과 복구 + +The easiest way to save and restore a model is to use a `tf.train.Saver` object. +The constructor adds `save` and `restore` ops to the graph for all, or a +specified list, of the variables in the graph. The saver object provides +methods to run these ops, specifying paths for the checkpoint files to write to +or read from. + +### 체크 포인트 화일 Checkpoint Files + +Variables are saved in binary files that, roughly, contain a map from variable +names to tensor values. + +When you create a `Saver` object, you can optionally choose names for the +variables in the checkpoint files. By default, it uses the value of the +[`Variable.name`](../../api_docs/python/state_ops.md#Variable.name) property for +each variable. + +To understand what variables are in a checkpoint, you can use the +[`inspect_checkpoint`](https://www.tensorflow.org/code/tensorflow/python/tools/inspect_checkpoint.py) +library, and in particular, the `print_tensors_in_checkpoint_file` function. + +### 변수 저장 + +Create a `Saver` with `tf.train.Saver()` to manage all variables in +the model. + +```python +# Create some variables. +v1 = tf.Variable(..., name="v1") +v2 = tf.Variable(..., name="v2") +... +# Add an op to initialize the variables. +init_op = tf.initialize_all_variables() + +# Add ops to save and restore all the variables. +saver = tf.train.Saver() + +# Later, launch the model, initialize the variables, do some work, save the +# variables to disk. +with tf.Session() as sess: + sess.run(init_op) + # Do some work with the model. + .. + # Save the variables to disk. + save_path = saver.save(sess, "/tmp/model.ckpt") + print("Model saved in file: %s" % save_path) +``` + +### 변수 복구 + +The same `Saver` object is used to restore variables. Note that when you +restore variables from a file you do not have to initialize them beforehand. + +```python +# Create some variables. +v1 = tf.Variable(..., name="v1") +v2 = tf.Variable(..., name="v2") +... +# Add ops to save and restore all the variables. +saver = tf.train.Saver() + +# Later, launch the model, use the saver to restore variables from disk, and +# do some work with the model. +with tf.Session() as sess: + # Restore variables from disk. + saver.restore(sess, "/tmp/model.ckpt") + print("Model restored.") + # Do some work with the model + ... +``` + +### 저장 및 복구할 변수들의 선택 + +If you do not pass any argument to `tf.train.Saver()` the saver handles all +variables in the graph. Each one of them is saved under the name that was +passed when the variable was created. + +It is sometimes useful to explicitly specify names for variables in the +checkpoint files. For example, you may have trained a model with a variable +named `"weights"` whose value you want to restore in a new variable named +`"params"`. + +It is also sometimes useful to only save or restore a subset of the variables +used by a model. For example, you may have trained a neural net with 5 layers, +and you now want to train a new model with 6 layers, restoring the parameters +from the 5 layers of the previously trained model into the first 5 layers of +the new model. + +You can easily specify the names and variables to save by passing to the +`tf.train.Saver()` constructor a Python dictionary: keys are the +names to use, values are the variables to manage. + +Notes: + +* You can create as many saver objects as you want if you need to save and + restore different subsets of the model variables. The same variable can be + listed in multiple saver objects, its value is only changed when the saver + `restore()` method is run. + +* If you only restore a subset of the model variables at the start + of a session, you have to run an initialize op for the other variables. See + [`tf.initialize_variables()`](../../api_docs/python/state_ops.md#initialize_variables) + for more information. + +```python +# Create some variables. +v1 = tf.Variable(..., name="v1") +v2 = tf.Variable(..., name="v2") +... +# Add ops to save and restore only 'v2' using the name "my_v2" +saver = tf.train.Saver({"my_v2": v2}) +# Use the saver object normally after that. +... +```