반응형
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
- Keras
- web 용어
- C언어
- 결합전문기관
- 머신러닝
- cudnn
- classification
- KNeighborsClassifier
- inorder
- mglearn
- tensorflow
- CES 2O21 참여
- broscoding
- web 개발
- 데이터전문기관
- CES 2O21 참가
- 웹 용어
- postorder
- java역사
- discrete_scatter
- web 사진
- pycharm
- web
- bccard
- 재귀함수
- 자료구조
- 대이터
- html
- paragraph
- vscode
Archives
- Today
- Total
bro's coding
tensorflow.optimizer 본문
반응형
sess=tf.InteractiveSession()
X=tf.constant([1,2],dtype=tf.float32)
y=tf.constant([3,5],dtype=tf.float32)
w=tf.Variable(tf.random.normal([]))
b=tf.Variable(tf.random.normal([]))
tf.global_variables_initializer().run()
pred_y=X*w+b
mse=tf.reduce_mean(tf.square(y-pred_y))
dw=2*tf.reduce_mean(X*(y-pred_y))
db=2*tf.reduce_mean(y-pred_y)
learning_rate=.001
op1=tf.assign(w,w+learning_rate*dw) # variable 값 바꾸기
op2=tf.assign(b,b+learning_rate*db)
w.eval(),b.eval()
costs=[]
for i in range(100):
sess.run([op1,op2])
mse_val,w_val,b_val=sess.run([mse,w,b])
costs.append(mse_val)
import matplotlib.pyplot as plt
plt.plot(costs)

sess=tf.InteractiveSession()
X=tf.constant([1,2],dtype=tf.float32)
y=tf.constant([3,5],dtype=tf.float32)
w=tf.Variable(tf.random.normal([]))
b=tf.Variable(tf.random.normal([]))
tf.global_variables_initializer().run()
pred_y=X*w+b
mse=tf.reduce_mean(tf.square(y-pred_y))
# tensorflow 모터 사용
# graph에서 선언 된 모든 tf.variable을 최적값으로 변경
optimizer=tf.train.GradientDescentOptimizer(learning_rate=.01)
train_op=optimizer.minimize(mse)
costs=[]
for i in range(100):
sess.run(train_op)
costs.append(mse.eval())
import matplotlib.pyplot as plt
plt.plot(costs)

반응형
'[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.행렬곱,전치행렬 (0) | 2020.05.11 |
tensorflow.Session/InteractiveSession (0) | 2020.05.11 |
tensorflow.basic (0) | 2020.05.11 |
tensorflow install (0) | 2020.05.11 |