Commit 0b402857 authored by Warnasooriya M.D.S.'s avatar Warnasooriya M.D.S.

Resnet Model Developed

parent bdeba643
...@@ -249,7 +249,75 @@ ...@@ -249,7 +249,75 @@
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": [
"🟢 ResNetModel"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Import Dependencies\n",
"import tensorflow as tf\n",
"import tensorflow_hub as hub\n",
"from tensorflow.keras import layers\n",
"from tensorflow.keras.layers import Conv2D , MaxPool2D , Dense , Flatten"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def create_model(model_url , num_classes=3):\n",
"\n",
" feature_extractor_layer = hub.KerasLayer(model_url,\n",
" trainable = False, #freeze the already learned patterns \n",
" name = \"feature_extraction_layer\",\n",
" input_shape = (448, 448,3)) \n",
" #Create our own model\n",
" model = tf.keras.Sequential([\n",
" feature_extractor_layer,\n",
" \n",
" layers.Dense(num_classes , activation=\"softmax\" , name=\"output_layer\")\n",
" ])\n",
"\n",
" return model"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"resnet_url = \"https://tfhub.dev/google/imagenet/resnet_v2_50/feature_vector/5\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Create Resnet Model\n",
"resnet_model = create_model(resnet_url , \n",
" num_classes = 3)\n",
"#Compile our resnet model\n",
"resnet_model.compile(loss='categorical_crossentropy',\n",
" optimizer = tf.keras.optimizers.Adam(),\n",
" metrics=[\"accuracy\"])\n",
"#Fitting the model\n",
"resnet_hist = resnet_model.fit(train_data,\n",
" epochs=15,\n",
" steps_per_epoch=len(train_data),\n",
" validation_data = test_data,\n",
" validation_steps = len(test_data)\n",
" )"
]
} }
], ],
"metadata": { "metadata": {
......
...@@ -249,7 +249,75 @@ ...@@ -249,7 +249,75 @@
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": [
"🟢 ResNetModel"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Import Dependencies\n",
"import tensorflow as tf\n",
"import tensorflow_hub as hub\n",
"from tensorflow.keras import layers\n",
"from tensorflow.keras.layers import Conv2D , MaxPool2D , Dense , Flatten"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def create_model(model_url , num_classes=3):\n",
"\n",
" feature_extractor_layer = hub.KerasLayer(model_url,\n",
" trainable = False, #freeze the already learned patterns \n",
" name = \"feature_extraction_layer\",\n",
" input_shape = (448, 448,3)) \n",
" #Create our own model\n",
" model = tf.keras.Sequential([\n",
" feature_extractor_layer,\n",
" \n",
" layers.Dense(num_classes , activation=\"softmax\" , name=\"output_layer\")\n",
" ])\n",
"\n",
" return model"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"resnet_url = \"https://tfhub.dev/google/imagenet/resnet_v2_50/feature_vector/5\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Create Resnet Model\n",
"resnet_model = create_model(resnet_url , \n",
" num_classes = 3)\n",
"#Compile our resnet model\n",
"resnet_model.compile(loss='categorical_crossentropy',\n",
" optimizer = tf.keras.optimizers.Adam(),\n",
" metrics=[\"accuracy\"])\n",
"#Fitting the model\n",
"resnet_hist = resnet_model.fit(train_data,\n",
" epochs=15,\n",
" steps_per_epoch=len(train_data),\n",
" validation_data = test_data,\n",
" validation_steps = len(test_data)\n",
" )"
]
} }
], ],
"metadata": { "metadata": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment