Created
November 20, 2020 17:50
-
-
Save boborbt/57cb9c43731043ed0efe0f147bc42513 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tensorflow as tf | |
| from tensorflow.keras.layers import Input | |
| from tensorflow.keras.layers import Dense | |
| from tensorflow.keras.models import Model | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import tensorflow.keras.backend as K | |
| x = Input(shape=[5]) | |
| h = Dense(10)(x) | |
| h = Dense(20)(h) | |
| y = Dense(5)(h) | |
| model = Model(x,y) | |
| def create_loss(model): | |
| def deriv_loss(y_true, y_pred): | |
| l1 = tf.keras.losses.binary_crossentropy(y_true, y_pred) | |
| l2 = K.sum(K.abs(K.gradients(y_pred, model.input))) | |
| return l1 | |
| return deriv_loss | |
| model.compile(loss=create_loss(model)) | |
| ds = np.random.multivariate_normal(np.zeros(5), np.eye(5), size=[1000]) | |
| model.fit(ds, ds) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment