Merge pull request #448 from gsundeep-tech/chapter_12/gaussian_layer

Chapter 12: Gaussian Noise Custom Layer Example
main
Aurélien Geron 2021-07-01 12:32:36 +12:00 committed by GitHub
commit 872abd822e
1 changed files with 31 additions and 2 deletions

View File

@ -1963,7 +1963,7 @@
},
{
"cell_type": "code",
"execution_count": 147,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
@ -1985,7 +1985,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": [