8.
Tensorflow 구조
텐서플로우는 edges와 nodes로 구조화된
graph로 프로그램이 구성
9.
Tensorflow : 처리 순서
텐서플로우는 빌딩구조와 실행구조(session)에
대한 처리 순서
1. tensorflow 모듈을 가져 와서 tf 호출
2. x라는 상수 값을 만들고 숫자 값 35를 지정.
3. y라는 변수를 만들고 방정식 x + 5로 정의
4. global_variables_initializer로 변수를 초기화
5. 값을 계산하기 위한 세션 만들기
6. 4에서 만든 모델 실행
7. 변수 y 만 실행하고 현재 값을 출력
10.
Tensorflow graph 조회
텐서플로우는 빌딩구조와 실행구조(session)가
분리
40.
cost function
n 번째의 원래데이타(y_data)와 예측 데이타(y)의 차이를 제곱
(^2)해서, 이 값을 n으로 나눈 평균 값이다
최소제곱법(Least-squares)을 사용합니다. 이 뜻은 각 점에서 선
까지의 평균 거리의 제곱의 합을 최소화한다는 것을 의미
분산식 비용함수
42.
class tf.train.Optimizer
tf.train.Optimizer는 기본 class이고 the
API to add Ops to train a model제공,
subclasses 로는GradientDescentOptimizer,
AdagradOptimizer, or MomentumOptimizer.
tf.train.Optimizer
GradientDescentOp
timizer
AdagradOptimizer MomentumOptimiz
er
43.
class tf.train.GradientOptimizer
코스트 함수와 옵티마이져(Gradient descent)
가 정의되었으면 트레이닝 모델에 적용
train = optimizer.minimize(loss)는 경사 하
강법(Gradient descent) 을 이용하여 코스트
함수 (loss)가 최소가 되는 값
44.
Gradient descent 이란
최적화할 함수 f(x )에 대하여, 먼저 시작점 x0를 정한다. 현재 x i 가 주어졌을 때, 그 다음으로 이동할 점인 x i+1 은 다음과 같이
계산된다.
gamma i는 이동할 거리를 조절하는 매개변수이다.
이 알고리즘의 수렴 여부는 f의 성질과 gamma i 의 선택에 따라 달라진다.
또한, 이 알고리즘은 지역 최적해로 수렴한다. 따라서 구한 값이 전역적인 최적해라는 것을 보장하지 않으며 시작점 x0 의 선택에
따라서 달라진다.
이에 따라 다양한 시작점에 대해 여러 번 경사 하강법을 적용하여 그 중 가장 좋은 결과를 선택할 수도 있다.
45.
tf.train.Optimizer.minimize
이 메소드는 단순히 compute_gradients () 및
apply_gradients () 호출을 결합처리, 적용하기 전
에 그라디언트를 처리하려면 이 함수 대신 명시적
으로 compute_gradients () 및 apply_gradients ()
를 호출 필요
minimize
명시적으로 호출 할 경우 예시
48.
Tensorflow 실행기준
텐서플로우는 Session에서는 Tensor Class
를 기준으로 실행
Tensor
SparseTensor
TensorArray
Tensor class
변환
49.
Tensor 용어
텐서는 0 차원 부터 n 차원까지를 가지는 대
표적인 데이터 클래스
0차 텐서 : 벡터가 없기 때문에 스칼라임
1차 텐서 : 벡터가 하나 있기 때문에 벡터임
2차 텐서 : 벡터가 두 개 일렬로 있기 때문에 행렬이나 다이애드임
3차 텐서 : 2차 텐서가 가 일렬로 있기 때문에 트라이애드임
N차 텐서 : n-1 차 텐서가 일렬로 구성됨
51.
dtype
tensor에 대한 데이터 타입
data type Python type Description
DT_FLOAT tf.float32 32 bits floating point.
DT_DOUBLE tf.float64 64 bits floating point.
DT_INT8 tf.int8 8 bits signed integer.
DT_INT16 tf.int16 16 bits signed integer.
DT_INT32 tf.int32 32 bits signed integer.
DT_INT64 tf.int64 64 bits signed integer.
DT_UINT8 tf.uint8 8 bits unsigned integer.
DT_STRING tf.string Variable length byte arrays. Each element of a Tensor is a byte array.
DT_BOOL tf.bool Boolean.
DT_COMPLEX64 tf.complex64 Complex number made of two 32 bits floating points: real and imaginary parts.
DT_COMPLEX128 tf.complex128 Complex number made of two 64 bits floating points: real and imaginary parts.
DT_QINT8 tf.qint8 8 bits signed integer used in quantized Ops.
DT_QINT32 tf.qint32 32 bits signed integer used in quantized Ops.
DT_QUINT8 tf.quint8 8 bits unsigned integer used in quantized Ops.
53.
변수 정의
변수 정의는 tf.Variable()를 이용해서 초기값과 변수
명을 정의
변수는 그래프의 실행시, 파라미터를 저장하고 갱신
하는데 사용되며, 메모리 상에서 텐서를 저장하는
버퍼 역할을 함
# Create a variable.
y = tf.Variable(<initial-value>, name=<optional-name>)
54.
변수 정의
변수 정의는 tf.Variable()로 정의하고 출력
해보면 Tensor 클래스의 값으로 나옴
55.
변수 정의 : Tensor 속성 보기
변수 정의는 tf.Variable()를 이용해서 정의
변수 정의한 y는 타입은 Variable임
56.
Numpy vs. Tensor 속성 비교
numpy와 tensorflow는 array에 대한 차원, 모
형, 크기에 대한 함수 비교
76.
placeholder 정의
placeholder는 실행시 데이터를 제공할 영
역을 지정하는 것
tf.placeholder(dtype, shape=None, name=None)
Args:
dtype: 데이터 타입
shape: 제공될 데이터에 대한 tensor 차원
name: A name for the operation
Returns:
A Tensor that may be used as a handle for feeding a value, but not evaluated directly.
77.
placeholder 정의
Tensor에 할당된 placeholder로 정의해도
Tensor 결정되고 실행시 데이터가 할당되어
야 함
78.
placeholder 실행
Tensor에 할당된 placeholder는 나중에 향
후에 사용시 자료를 공급(feed)해야 됨
209.
Session 종류
Session은 다음의 2가지를 세팅해서 사용가능하
며 반드시 Session.close() 해야 함
InteractiveSession
Session
Interactive 하게 사용가능.
Tensor.eval(), Operation.run()
으로 처리
Non-Interactive 하게 사용.
Session.run()으로 처리하고
221.
Session 이란
텐서플로우 내의 Operation 실행, Tensor가 평
가되는 환경
operation
tensor
Operation.run() 실
행
Tensor.eval()실행
Session.run( _ )
Session.run() 메소드의 파라미터로
operation이나 tensor 제공
222.
Session.run : tensor
텐서플로우 내의 텐서를 평가해서 결과 값 제공
223.
Session.run : operation run
Operation: 임의의 계산을 수행하는 것으로 다양
한 속성 값(attribute)을 가질 수 있습니다.
224.
Session.run 파라미터
fetches: 하나의 graph 요소나 grape 요소들이 리스트, grape
요소들을 가진 사전 .
feed_dict: graph 요소와 값을 가진 사전
options: A [RunOptions] protocol buffer
run_metadata: A [RunMetadata] protocol buffer
tf.Session.run(fetches, feed_dict=None, options=None,
run_metadata=None)
225.
Session : 최종 실행
Session 정의 될 경우 Session에서는 run을
사용해야 하거나 with 문을 사용해서 활용
sess = tf.InteractiveSession() 을 정의되어 있을
경우 tensor에 eval()로 실행가능
Session.run() Tensor.eval()
226.
Session 최종 결과 값처리
Session 처리 결과이 타입은 numpy.int32
객체이니 Tensor 타입이 아님
처리 결과는
tensor 타입이
아닌 실제 결과
타입이 저장됨
Parece que tem um bloqueador de anúncios ativo. Ao listar o SlideShare no seu bloqueador de anúncios, está a apoiar a nossa comunidade de criadores de conteúdo.
Odeia anúncios?
Atualizámos a nossa política de privacidade.
Atualizámos a nossa política de privacidade de modo a estarmos em conformidade com os regulamentos de privacidade em constante mutação a nível mundial e para lhe fornecer uma visão sobre as formas limitadas de utilização dos seus dados.
Pode ler os detalhes abaixo. Ao aceitar, está a concordar com a política de privacidade atualizada.