diff --git a/12_custom_models_and_training_with_tensorflow.ipynb b/12_custom_models_and_training_with_tensorflow.ipynb index c5aa1a8..8f17e3b 100644 --- a/12_custom_models_and_training_with_tensorflow.ipynb +++ b/12_custom_models_and_training_with_tensorflow.ipynb @@ -1900,7 +1900,7 @@ }, { "cell_type": "code", - "execution_count": 147, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -1922,7 +1922,36 @@ }, { "cell_type": "code", - "execution_count": 148, + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "class GaussianNoiseModel(keras.Model):\n", + " def __init__(self, units, activation, **kwargs):\n", + " super(GaussianNoiseModel, self).__init__(**kwargs)\n", + " self.noise = AddGaussianNoise(stddev=1.0)\n", + " self.hidden = keras.layers.Dense(units, activation=activation)\n", + " self.out = keras.layers.Dense(1)\n", + " \n", + " def call(self, inputs):\n", + " noise = self.noise(inputs)\n", + " hidden = self.hidden(noise)\n", + " out = self.out(hidden)\n", + " return out" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "model = GaussianNoiseModel(units=30, activation='selu')" + ] + }, + { + "cell_type": "code", + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -3883,7 +3912,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.10" + "version": "3.8.10" } }, "nbformat": 4,