We-Co

[We-Co] Placeholder 본문

Python/Tensorflow

[We-Co] Placeholder

위기의코딩맨 2021. 6. 11. 14:25
반응형

안녕하세요. 위기의 코딩맨입니다.

오늘은 Tensorflow의 Placeholder를 알아보도록 하겠습니다.

[Placeholder]

Placeholder는 쉽게 말하면 말그대로 하나의 공간이며, 나중에 데이터로 채워질 빈 변수로 생각하면 된다.

Tensorflow는 입력값을 공급하기 위한 내장 구조를 갖고있는데, 이러한 구조를 Placeholder로 부른다.

 

*      PL= tf.placehholder(tf.float32)

*      PL= tf.placehholder(tf.float32, shape(2,2))

 

 

Placehorder의 선언은 이렇다. 

첫번째 인자에 해당 타입을 설정하여 선언할수있고

두번재로 shape는 배열형태로 선언할 수 있다. 받을수 있는 크기를 선언할 수 있지만, None으로 설정 시, 모든 크기의 데이터를 받을 수 있다.

 

x_Value = 5
y_Value = 10

with tf.Session() as sess:
    x_Placeholder = tf.placeholder(tf.float32)
    y_Placeholder = tf.placeholder(tf.float32)
    add_ = x_Placeholder + y_Placeholder
    outs = sess.run(add_,feed_dict={x_Placeholder:x_Value, y_Placeholder:y_Value})

print(outs)

 

위 소스 예제를 확인해보면 x_Value, y_Value를 선언하고

작업을 위해 Session을 선언하고 x_Placeholder, y_Placeholder를 통해 각각의 Placeholder를 선언해 줍니다. 

더하기의 작업을 위해 add_를 만들고 Placeholder의 값을 피드해주기위해  feed_dict()를 사용한다.

feed_dict() 작업 add_를 진행하기위해 첫번째 인자에 넣어주고, 

선언한 x_Placeholder에 x_Value의 값을, y_Placeholder에는 y_Value의 값을 넣어주도록 하면

outs에는 x_Value, y_Value의  add_ 작업한 결과를 받을 수 잇다.

결과 값

반응형

'Python > Tensorflow' 카테고리의 다른 글

[We-Co] TensorFlow Linspace  (0) 2021.07.18
[We-Co] TensorFlow 형변환  (0) 2021.07.18
[We-Co] TensorFlow - Graph  (0) 2021.07.13
[We-Co] Hello TensorFlow!  (0) 2021.05.25
[We-Co] TensorFlow  (0) 2021.05.24