(15주차) 6월13일
- Imports
import tensorflow as tf
import tensorflow.experimental.numpy as tnp
import matplotlib.pyplot as plt
tnp.experimental_enable_numpy_behavior()
- data
x= tnp.linspace(0,1,100).reshape(100,1)
y= x + tf.random.normal([100,1])*0.1
plt.plot(x,y,'.')
- input layer
x0= tf.keras.layers.Input(shape=(1,))
- 아키텍처
l1=tf.keras.layers.Dense(30)
a1=tf.keras.layers.Activation(tf.nn.relu)
x1=a1(l1(x0))
l2=tf.keras.layers.Dense(30)
a2=tf.keras.layers.Activation(tf.nn.relu)
x2=a2(l2(x1))
l3=tf.keras.layers.Dense(1)
x3=l3(x2) # output
- input, output 으로 모델(net)설정
net = tf.keras.Model(inputs=x0, outputs=x3)
net.summary()
- compile and fit
net.compile(loss='mse', optimizer='sgd')
net.fit(x,y,epochs=100)
plt.plot(x,y,'.')
plt.plot(x,net(x),'--')