강의

멘토링

로드맵

Inflearn Community Q&A

ybs11643788's profile image
ybs11643788

asked

Tensorflow User Manual

Gradient Tape in Tensorflow

SyntaxError: keyword can't be an expression

Written on

·

511

0

x_data = tf.random.normal(shape=(1000,), dtype=tf.float32)
y_data = 3*x_data - 1

w = tf.Variable(-1.)
b = tf.Variable(-1.)

learning_rate = 0.01

w_trace, b_trace = [], []
for x, y in zip(x_data, y_data):
  with tf.GradientTape() as tape:
    prediction = w*x + b
    loss = (prediction - y)**2
  
  gradients = tape.gradient(loss, [w, b])

  w_trace.append(w.numpy())
  b_trace.append(b.numpy())
  w = tf.Variable(w - learning_rate=gradients[0])
  b = tf.Variable(b - learning_rate=gradients[1])

flg, ax = plt.subplots(figsize=(2010))

ax.plot(w_trace,
        label='weight')
ax.plot(b_trace,
        label='bias')

ax.tick_params(labelsize=20)
ax.legend(fontsize=30)
File "<ipython-input-20-19f2193f023b>", line 19 w = tf.Variable(w - learning_rate=gradients[0]) ^ SyntaxError: keyword can't be an expression
구글 코랩으로 진행하고 있다가 이런 오류가 났습니다, 어떻게 해결해야 하나요?
tensorflow딥러닝

Answer

This question is waiting for answers
Be the first to answer!
ybs11643788's profile image
ybs11643788

asked

Ask a question