-
-
Save kiransair/bf447740ee1dec5e9f6c3a9524b41680 to your computer and use it in GitHub Desktop.
TF_Forum_14434.ipynb
This file contains 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
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"provenance": [], | |
"authorship_tag": "ABX9TyOg0LdoAtojI0vZDxxCvg9I", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/kiransair/bf447740ee1dec5e9f6c3a9524b41680/tf_forum_14434.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"import tensorflow as tf" | |
], | |
"metadata": { | |
"id": "Oa5VmmLa91Ho" | |
}, | |
"execution_count": 2, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"class AnomalyDetector(tf.keras.models.Model):\n", | |
" def __init__(self):\n", | |
" super(AnomalyDetector, self).__init__()\n", | |
" \n", | |
" self.encoder = tf.keras.Sequential([\n", | |
" tf.keras.layers.Input(shape=(300, 300, 3)),\n", | |
" tf.keras.layers.Conv2D(64, (3, 3), activation='relu', padding='same'),\n", | |
" tf.keras.layers.MaxPooling2D((2, 2), padding='same'),\n", | |
" tf.keras.layers.BatchNormalization(),\n", | |
" tf.keras.layers.Conv2D(32, (3, 3), activation='relu', padding='same'),\n", | |
" tf.keras.layers.MaxPooling2D((2, 2), padding='same'),\n", | |
" tf.keras.layers.BatchNormalization(),\n", | |
" tf.keras.layers.Conv2D(16, (3, 3), activation='relu', padding='same'),\n", | |
" tf.keras.layers.MaxPooling2D((2, 2), padding='same')\n", | |
" ]) # Smallest Layer Defined Here\n", | |
" \n", | |
" self.decoder = tf.keras.Sequential([\n", | |
" tf.keras.layers.Conv2D(64, (3, 3), activation='relu', padding='same'),\n", | |
" tf.keras.layers.UpSampling2D((2, 2)),\n", | |
" tf.keras.layers.Conv2D(32, (3, 3), activation='relu', padding='same'),\n", | |
" tf.keras.layers.UpSampling2D((2, 2)),\n", | |
" tf.keras.layers.Conv2D(16, (3, 3), activation='relu'),\n", | |
" tf.keras.layers.UpSampling2D((2, 2)),\n", | |
" tf.keras.layers.Conv2D(3, (3, 3), activation='sigmoid', padding='same')\n", | |
" ])\n", | |
" \n", | |
" def call(self, x):\n", | |
" encoded = self.encoder(x)\n", | |
" decoded = self.decoder(encoded)\n", | |
" return decoded\n", | |
"\n", | |
"auto_encoder = AnomalyDetector()" | |
], | |
"metadata": { | |
"id": "Z9ZDIfi9_FdU" | |
}, | |
"execution_count": 19, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"auto_encoder.build((None,300,300,3))" | |
], | |
"metadata": { | |
"id": "6Bs-l8hiAY2_" | |
}, | |
"execution_count": 23, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"auto_encoder.summary(expand_nested=True)\n", | |
"\n" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "skRepOs-_MfO", | |
"outputId": "f34a71f2-3e80-4d8d-8408-75d4347930cf" | |
}, | |
"execution_count": 33, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Model: \"anomaly_detector\"\n", | |
"_________________________________________________________________\n", | |
" Layer (type) Output Shape Param # \n", | |
"=================================================================\n", | |
" sequential_4 (Sequential) (None, 38, 38, 16) 25264 \n", | |
"|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|\n", | |
"| conv2d_14 (Conv2D) (None, 300, 300, 64) 1792 |\n", | |
"| |\n", | |
"| max_pooling2d_6 (MaxPooling (None, 150, 150, 64) 0 |\n", | |
"| 2D) |\n", | |
"| |\n", | |
"| batch_normalization_4 (Batc (None, 150, 150, 64) 256 |\n", | |
"| hNormalization) |\n", | |
"| |\n", | |
"| conv2d_15 (Conv2D) (None, 150, 150, 32) 18464 |\n", | |
"| |\n", | |
"| max_pooling2d_7 (MaxPooling (None, 75, 75, 32) 0 |\n", | |
"| 2D) |\n", | |
"| |\n", | |
"| batch_normalization_5 (Batc (None, 75, 75, 32) 128 |\n", | |
"| hNormalization) |\n", | |
"| |\n", | |
"| conv2d_16 (Conv2D) (None, 75, 75, 16) 4624 |\n", | |
"| |\n", | |
"| max_pooling2d_8 (MaxPooling (None, 38, 38, 16) 0 |\n", | |
"| 2D) |\n", | |
"¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\n", | |
" sequential_5 (Sequential) (None, 300, 300, 3) 32803 \n", | |
"|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|\n", | |
"| conv2d_17 (Conv2D) (None, 38, 38, 64) 9280 |\n", | |
"| |\n", | |
"| up_sampling2d_6 (UpSampling (None, 76, 76, 64) 0 |\n", | |
"| 2D) |\n", | |
"| |\n", | |
"| conv2d_18 (Conv2D) (None, 76, 76, 32) 18464 |\n", | |
"| |\n", | |
"| up_sampling2d_7 (UpSampling (None, 152, 152, 32) 0 |\n", | |
"| 2D) |\n", | |
"| |\n", | |
"| conv2d_19 (Conv2D) (None, 150, 150, 16) 4624 |\n", | |
"| |\n", | |
"| up_sampling2d_8 (UpSampling (None, 300, 300, 16) 0 |\n", | |
"| 2D) |\n", | |
"| |\n", | |
"| conv2d_20 (Conv2D) (None, 300, 300, 3) 435 |\n", | |
"¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\n", | |
"=================================================================\n", | |
"Total params: 58,067\n", | |
"Trainable params: 57,875\n", | |
"Non-trainable params: 192\n", | |
"_________________________________________________________________\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [], | |
"metadata": { | |
"id": "Al9vhak8BJqv" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment