반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- discrete_scatter
- mglearn
- 머신러닝
- 웹 용어
- bccard
- web 사진
- cudnn
- 재귀함수
- web 용어
- paragraph
- inorder
- vscode
- web
- postorder
- tensorflow
- 결합전문기관
- 대이터
- CES 2O21 참여
- classification
- pycharm
- web 개발
- 자료구조
- CES 2O21 참가
- 데이터전문기관
- KNeighborsClassifier
- broscoding
- html
- Keras
- java역사
- C언어
Archives
- Today
- Total
bro's coding
tensorflow.basic 본문
반응형
import numpy as np
import tensorflow as tf
tensorflow에서의 data type
- tf.constant()
- tf.Variable()
- tf.placeholder()
tf.constant() # 상수 - 학습률 등 고정된 값
tf.Variable() # 변수 - 가중치(w)와 절편(b)
tf.placeholder() # 플레이스 홀더 - X값 등
> constant
a=tf.constant(2)
b=tf.constant(3)
display(a,b)
c=a*b
display(c)
sess=tf.Session()
display(sess.run(c))
sess.run([a,b,c])
sess.close()
<tf.Tensor 'Const_20:0' shape=() dtype=int32>
<tf.Tensor 'Const_21:0' shape=() dtype=int32>
<tf.Tensor 'mul_14:0' shape=() dtype=int32>
6
[2, 3, 6]
> Variable
a=tf.constant(2)
b=tf.Variable(3) # 3 : 초기값(반드시 넣어야함)
display(a,b)
c=a*b
sess=tf.Session()
sess.run(b.initializer)# 변수 초기화
display(sess.run(c))
<tf.Tensor 'Const_23:0' shape=() dtype=int32>
<tf.Variable 'Variable_5:0' shape=() dtype=int32_ref>
6
a=tf.constant([10,10,10])
b=tf.Variable([10,10,10])
c=a+b
sess=tf.Session()
sess.run(b.initializer)
sess.run(c)
array([20, 20, 20])
> placeholder
a=tf.constant(2)
b=tf.placeholder(tf.int32) # type을 설정
display(a,b)
c=a*b
sess=tf.Session()
sess.run(c,feed_dict={b:3}) #placeholder는 값을 지정해줘야한다.
# run 할때 마다 place holder에 값을 넣어야한다.
display(sess.run([a,b,c],feed_dict={b:3}))
display(sess.run([a,b,c],feed_dict={b:[3,1,2]})) # list도 가능하다
<tf.Tensor 'Const_28:0' shape=() dtype=int32>
<tf.Tensor 'Placeholder_11:0' shape=<unknown> dtype=int32>
[2, array(3), 6]
[2, array([3, 1, 2]), array([6, 2, 4])]
array([[ 0, 2, 4],
[ 6, 8, 10],
[12, 14, 16]])
[2, array([[ 0, 1, 2],
[ 3, 4, 5],
[ 6, 7, 8],
[ 9, 10, 11]]), array([[ 0, 2, 4],
[ 6, 8, 10],
[12, 14, 16],
[18, 20, 22]])]
a=tf.constant(2)
b=tf.placeholder(tf.int32,shape=(None,3))# None으로 행의 갯수를 임의로 지정
c=a*b
sess=tf.Session()
display(sess.run(c,feed_dict={b:np.arange(9).reshape(3,3)}))
display(sess.run([a,b,c],feed_dict={b:np.arange(12).reshape(4,3)}))
반응형
'[AI] > python.tensorflow' 카테고리의 다른 글
tensorflow.분류(중간층).relu,sigmoid 비교 (0) | 2020.05.12 |
---|---|
tensorflow.분류(중간층X) (0) | 2020.05.12 |
tensorflow.placeholder (0) | 2020.05.11 |
tensorflow.irisdata적용 (0) | 2020.05.11 |
tensorflow.optimizer (0) | 2020.05.11 |
tensorflow.행렬곱,전치행렬 (0) | 2020.05.11 |
tensorflow.Session/InteractiveSession (0) | 2020.05.11 |
tensorflow install (0) | 2020.05.11 |
Comments