반응형
본 포스팅은 다음 과정을 정리 한 글입니다.
Custom Models, Layers, and Loss Functions with TensorFlow
www.coursera.org/specializations/tensorflow-advanced-techniques
지난 시간 리뷰
2021.03.21 - [Artificial Intelligence/Keras] - [Tensorflow 2][Keras] Week 2 - Contrastive Loss
# Please uncomment all lines in this cell and replace those marked with `# YOUR CODE HERE`.
# You can select all lines in this code cell with Ctrl+A (Windows/Linux) or Cmd+A (Mac), then press Ctrl+/ (Windows/Linux) or Cmd+/ (Mac) to uncomment.
def my_rmse(y_true, y_pred):
error = y_true - y_pred;
sqr_error = K.square(error)
mean_sqr_error = K.mean(sqr_error)
sqrt_mean_sqr_error = K.sqrt(mean_sqr_error)
return sqrt_mean_sqr_error
# Please uncomment all lines in this cell and replace those marked with `# YOUR CODE HERE`.
# You can select all lines in this code cell with Ctrl+A (Windows/Linux) or Cmd+A (Mac), then press Ctrl+/ (Windows/Linux) or Cmd+/ (Mac) to uncomment.
# define the model architecture
model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
# use the function you just coded as the loss
model.compile(optimizer='sgd', loss=my_rmse)
# train the model
model.fit(xs, ys, epochs=500,verbose=0)
# test with a sample input
print(model.predict([10.0]))
300x250
'Artificial Intelligence > Keras' 카테고리의 다른 글
[Tensorflow 2][Keras] Week 3 - Implementing Custom Layers (0) | 2021.03.26 |
---|---|
[Tensorflow 2][Keras] Week 3 - Custom lambda layers (0) | 2021.03.26 |
[Tensorflow 2][Keras] Week 2 - Contrastive Loss (0) | 2021.03.21 |
[Tensorflow 2][Keras] Week 2 - Custom loss hyperparameters and classes (0) | 2021.03.20 |
[Tensorflow 2][Keras] Week 2 - Custom loss functions (0) | 2021.03.18 |
댓글