{"id":1,"date":"2019-12-02T08:57:00","date_gmt":"2019-12-02T08:57:00","guid":{"rendered":"https:\/\/box5118\/cgi\/addon_GT.cgi?s=GT::WP::Install::EIG+%28khanhcod%29+-+10.24.48.82+%5BWordPress%3b+\/var\/hp\/common\/lib\/WordPress.pm%3b+292%3b+Hosting::gap_call%5D\/?p=1"},"modified":"2020-12-20T01:21:26","modified_gmt":"2020-12-20T01:21:26","slug":"keras-alexnet-dog-vs-cat","status":"publish","type":"post","link":"https:\/\/khanhcode.com\/?p=1","title":{"rendered":"Keras AlexNet: Dog vs. Cat Classification"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"1\" class=\"elementor elementor-1\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-8d762a elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"8d762a\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-6da002cc\" data-id=\"6da002cc\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-2b85b931 elementor-widget elementor-widget-text-editor\" data-id=\"2b85b931\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\n<p><strong>Project URL:<\/strong> <a href=\"https:\/\/github.com\/Insignite\/Alexnet-DogvsCat-Classification\" data-type=\"URL\" data-id=\"https:\/\/github.com\/Insignite\/Alexnet-DogvsCat-Classification\">https:\/\/github.com\/Insignite\/Alexnet-DogvsCat-Classification<\/a><\/p>\n\n<p>I want to build a simple Deep Learning model for image classification on\u00a0<a href=\"https:\/\/www.kaggle.com\/c\/dogs-vs-cats\" target=\"_blank\" rel=\"noreferrer noopener\">Kaggle Dog vs. Cat Dataset<\/a>. In this project, I decided to use AlexNet architecture as it repeatedly mentions during my Machine Learning course. This project is simple enough that helps me understand Alexnet, familiarize myself with Keras, and gain more experience in the ML field.<\/p>\n\n<h2 class=\"wp-block-heading\"><strong>Dataset<\/strong><\/h2>\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-recalc-dims=\"1\" src=\"https:\/\/i0.wp.com\/raw.githubusercontent.com\/Insignite\/Alexnet-DogvsCat-Classification\/master\/img\/2.PNG?ssl=1\" alt=\"\" \/><\/figure>\n\n<p>After download and extract dataset from zip file, let&#8217;s view the data.<\/p>\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-recalc-dims=\"1\" src=\"https:\/\/i0.wp.com\/raw.githubusercontent.com\/Insignite\/Alexnet-DogvsCat-Classification\/master\/img\/1.PNG?ssl=1\" alt=\"\" \/><\/figure>\n\n<p>The dataset doesn&#8217;t come with a label file. But I can extract the label from image name in train dataset.<\/p>\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-recalc-dims=\"1\" src=\"https:\/\/i0.wp.com\/raw.githubusercontent.com\/Insignite\/Alexnet-DogvsCat-Classification\/master\/img\/3.PNG?ssl=1\" alt=\"\" \/><\/figure>\n\n<p>I apply a data generator to provide variety to our train dataset which definitely will improve the model accuracy. This also &#8220;replicate&#8221; real-world dataset because not all input image will be a perfect picture of a dog or a cat. Let&#8217;s view a sample from our generator.<\/p>\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-recalc-dims=\"1\" src=\"https:\/\/i0.wp.com\/raw.githubusercontent.com\/Insignite\/Alexnet-DogvsCat-Classification\/master\/img\/4.PNG?ssl=1\" alt=\"\" \/><\/figure>\n\n<p>The train dataset split as 80% training and 20% validation with image generator applied to both. Data now ready to be train.<\/p>\n\n<h2 class=\"wp-block-heading\"><strong>Deep Learning Model<\/strong><\/h2>\n\n<p>As mentioned, I will be using AlexNet architecture to build the model. AlexNet consist of five convolutional layers, some followed by maximum pooling layers and then three fully connected layers. Since the dataset only consist of two classes (Dog and Cat), the last layer is a 2-ways softwax.<\/p>\n\n<figure class=\"wp-block-table\">\n<table>\n<tbody>\n<tr>\n<td>Layer name<\/td>\n<td>Output<\/td>\n<td>Filters<\/td>\n<td>Kernel size<\/td>\n<td>Stride<\/td>\n<td>Padding<\/td>\n<\/tr>\n<tr>\n<td>Input<\/td>\n<td>227x227x3<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<tr>\n<td>Convol_1<\/td>\n<td>55x55x96<\/td>\n<td>96<\/td>\n<td>11&#215;11<\/td>\n<td>4<\/td>\n<td>valid<\/td>\n<\/tr>\n<tr>\n<td>MaxPool_1<\/td>\n<td>27x27x96<\/td>\n<td>&#8211;<\/td>\n<td>3&#215;3<\/td>\n<td>2<\/td>\n<td>valid<\/td>\n<\/tr>\n<tr>\n<td>Norm_1<\/td>\n<td>27x27x96<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<tr>\n<td>Convol_2<\/td>\n<td>27x27x256<\/td>\n<td>256<\/td>\n<td>5&#215;5<\/td>\n<td>1<\/td>\n<td>valid<\/td>\n<\/tr>\n<tr>\n<td>MaxPool_2<\/td>\n<td>13x13x256<\/td>\n<td>&#8211;<\/td>\n<td>3&#215;3<\/td>\n<td>2<\/td>\n<td>valid<\/td>\n<\/tr>\n<tr>\n<td>Norm_2<\/td>\n<td>13x13x256<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<tr>\n<td>Convol_3<\/td>\n<td>13x13x384<\/td>\n<td>384<\/td>\n<td>3&#215;3<\/td>\n<td>1<\/td>\n<td>valid<\/td>\n<\/tr>\n<tr>\n<td>Convol_4<\/td>\n<td>13x13x384<\/td>\n<td>384<\/td>\n<td>3&#215;3<\/td>\n<td>1<\/td>\n<td>valid<\/td>\n<\/tr>\n<tr>\n<td>Convol_5<\/td>\n<td>13x13x256<\/td>\n<td>256<\/td>\n<td>3&#215;3<\/td>\n<td>1<\/td>\n<td>valid<\/td>\n<\/tr>\n<tr>\n<td>MaxPool_3<\/td>\n<td>6x6x256<\/td>\n<td>&#8211;<\/td>\n<td>3&#215;3<\/td>\n<td>2<\/td>\n<td>valid<\/td>\n<\/tr>\n<tr>\n<td>FullConnect_1<\/td>\n<td>4096<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<tr>\n<td>FullConnect_2<\/td>\n<td>4096<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<tr>\n<td>FullConnect_3<\/td>\n<td>1000<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<tr>\n<td>FullConnect_4<\/td>\n<td>2 (Dog vs Cat)<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n<h2 class=\"wp-block-heading\"><strong>Training<\/strong><\/h2>\n\n<p><br \/>I am using a Huaweii Matebook Pro with 8th Gen Intel- i7, 16GB RAM, NVIDIA GeForce MX150. Definitely not a good laptop to run any type of machine learning project so each epochs take me roughly 10-15 minutes. I decided to use small epochs but reasonable enough to get a decent results. I tried out with 3, then 10, and finally 20 epochs. If you have stronger hardware, an increase to 50 or so definitely will yield a good result.<\/p>\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-recalc-dims=\"1\" src=\"https:\/\/i0.wp.com\/raw.githubusercontent.com\/Insignite\/Alexnet-DogvsCat-Classification\/master\/img\/5.PNG?ssl=1\" alt=\"\" \/><\/figure>\n\n<p>Let&#8217;s graph the train lost, train accuracy, validation lost, and validation accuracy for 20 epochs.<\/p>\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-recalc-dims=\"1\" src=\"https:\/\/i0.wp.com\/raw.githubusercontent.com\/Insignite\/Alexnet-DogvsCat-Classification\/master\/img\/6.PNG?ssl=1\" alt=\"\" \/><\/figure>\n\n<h2 class=\"wp-block-heading\"><strong>Result<\/strong><\/h2>\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-recalc-dims=\"1\" src=\"https:\/\/i0.wp.com\/raw.githubusercontent.com\/Insignite\/Alexnet-DogvsCat-Classification\/master\/img\/8.PNG?ssl=1\" alt=\"\" \/><\/figure>\n\n<p>Let&#8217;s put some predicted result with images so we can see our prediction result better. I will do first 20 images from test result.<\/p>\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-recalc-dims=\"1\" src=\"https:\/\/i0.wp.com\/raw.githubusercontent.com\/Insignite\/Alexnet-DogvsCat-Classification\/master\/img\/7.PNG?ssl=1\" alt=\"\" \/><\/figure>\n\n<p>TADA!!! I now have a simple model to classify picture of dog or cat.<\/p>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-4f3de50 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"4f3de50\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-eda5b53\" data-id=\"eda5b53\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap\">\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Project URL: https:\/\/github.com\/Insignite\/Alexnet-DogvsCat-Classification I want to build a simple Deep Learning model for image classification on\u00a0Kaggle Dog vs. Cat Dataset. In this project, I decided to use AlexNet architecture as it repeatedly mentions during my Machine Learning course. This project is simple enough that helps me understand Alexnet, familiarize myself with Keras, and gain more [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":404,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-projects"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/khanhcode.com\/wp-content\/uploads\/2020\/10\/AlexNet-1.png?fit=960%2C540&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/khanhcode.com\/index.php?rest_route=\/wp\/v2\/posts\/1","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/khanhcode.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/khanhcode.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/khanhcode.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/khanhcode.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1"}],"version-history":[{"count":6,"href":"https:\/\/khanhcode.com\/index.php?rest_route=\/wp\/v2\/posts\/1\/revisions"}],"predecessor-version":[{"id":502,"href":"https:\/\/khanhcode.com\/index.php?rest_route=\/wp\/v2\/posts\/1\/revisions\/502"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/khanhcode.com\/index.php?rest_route=\/wp\/v2\/media\/404"}],"wp:attachment":[{"href":"https:\/\/khanhcode.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/khanhcode.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/khanhcode.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}