In [1]:
# we will use alexnet architecture for our base line model
# https://towardsdatascience.com/implementing-alexnet-cnn-architecture-using-tensorflow-2-0-and-keras-2113e090ad98
# Model Implementation
## layers in AlexNet
# 1. Convolutional layer
# 2. Batch Normalization layer
# 3. Max pooling layer
# 4. Flatten layer
# 5. Dense layer
## operations and techniques used in AlexNet
# 1. Activation Function
# 2. ReLU
# 3. Softmax Activation Function
# 4. Dropout
In [2]:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.cm as cm
import shutil, pathlib
from glob import glob
import os
import warnings
warnings.filterwarnings('ignore')
In [3]:
# loading data
## create a folder, name 'data' for placeing all the data in this folder. And cd in folder
if os.getcwd().split("/")[-1] == "data":
print("In 'data' directory")
pass
else:
os.mkdir('data')
os.chdir('data')
print(os.getcwd(),"nn")
/content/data
In [4]:
## here download, unzip the data
if os.path.exists('101_ObjectCategories'):
print("Data Already Downloaded!")
pass
else:
!wget https://data.caltech.edu/records/mzrjq-6wc02/files/caltech-101.zip?download=1
!mv caltech-101.zip?download=1 Caltech101.zip
!unzip Caltech101.zip ## unzip downlaoded file
!tar -xzf caltech-101/101_ObjectCategories.tar.gz ## unzip the folder of 101 classes + 1 class (BACKGROUND_Google)
!rm -rf Caltech101.zip
!rm -rf caltech-101
!rm -rf __MACOSX
!rm -rf 101_ObjectCategories/BACKGROUND_Google
--2022-10-07 05:02:36-- https://data.caltech.edu/records/mzrjq-6wc02/files/caltech-101.zip?download=1 Resolving data.caltech.edu (data.caltech.edu)... 35.155.11.48 Connecting to data.caltech.edu (data.caltech.edu)|35.155.11.48|:443... connected. HTTP request sent, awaiting response... 302 FOUND Location: https://s3.us-west-2.amazonaws.com/caltechdata/47/20/fc77-d78a-4c50-81c9-d47c2004df45/data?response-content-type=application%2Foctet-stream&response-content-disposition=attachment%3B%20filename%3Dcaltech-101.zip&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIARCVIVNNAP7NNDVEA%2F20221007%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20221007T050236Z&X-Amz-Expires=60&X-Amz-SignedHeaders=host&X-Amz-Signature=8def9d0e2ac8a58225e244d37e0447fd2da7c1b6d5ce95890278dfff69426383 [following] --2022-10-07 05:02:36-- https://s3.us-west-2.amazonaws.com/caltechdata/47/20/fc77-d78a-4c50-81c9-d47c2004df45/data?response-content-type=application%2Foctet-stream&response-content-disposition=attachment%3B%20filename%3Dcaltech-101.zip&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIARCVIVNNAP7NNDVEA%2F20221007%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20221007T050236Z&X-Amz-Expires=60&X-Amz-SignedHeaders=host&X-Amz-Signature=8def9d0e2ac8a58225e244d37e0447fd2da7c1b6d5ce95890278dfff69426383 Resolving s3.us-west-2.amazonaws.com (s3.us-west-2.amazonaws.com)... 52.92.177.16 Connecting to s3.us-west-2.amazonaws.com (s3.us-west-2.amazonaws.com)|52.92.177.16|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 137414764 (131M) [application/octet-stream] Saving to: ‘caltech-101.zip?download=1’ caltech-101.zip?dow 100%[===================>] 131.05M 30.5MB/s in 4.8s 2022-10-07 05:02:41 (27.5 MB/s) - ‘caltech-101.zip?download=1’ saved [137414764/137414764] Archive: Caltech101.zip creating: caltech-101/ inflating: __MACOSX/._caltech-101 inflating: caltech-101/101_ObjectCategories.tar.gz inflating: __MACOSX/caltech-101/._101_ObjectCategories.tar.gz inflating: caltech-101/show_annotation.m inflating: __MACOSX/caltech-101/._show_annotation.m inflating: caltech-101/Annotations.tar inflating: __MACOSX/caltech-101/._Annotations.tar
In [5]:
def plot_folder(folder_name, plot_title="Count Plot", color = 'yellow', show_cnt=True, show_xticks=False):
count_dict = {i:len(os.listdir(folder_name+"/"+i)) for i in os.listdir(folder_name)}
dic2=dict(sorted(count_dict.items(),key= lambda x:x[1] , reverse=True))
palette = sns.color_palette("icefire", len(dic2))
plt.title(plot_title, fontsize=15)
plt.bar(*zip(*dic2.items()), color=palette, alpha=0.5)
plt.xticks(rotation=90)
y = sorted(count_dict.values())[-4]
y_count = sum(count_dict.values())
if show_cnt:
plt.text(10, y, f'{y_count} images', style='italic',
bbox={'facecolor': color ,'alpha': 0.5, 'pad': 9})
if show_xticks:
pass
else:
plt.xticks([])
plt.grid(False)
main_folder="101_ObjectCategories"
plt.figure(figsize=(25,8))
plot_folder(main_folder, plot_title="Original DataSet", color='green' , show_cnt=False, show_xticks=True)
Copyright © Code Fetcher 2022