File - Ipynb - JupyterLab

Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

3/6/24, 11:47 PM file

In [2]: import tensorflow as tf


import cv2, os
import matplotlib.pyplot as plt
import numpy as np
import sym_name

2024-03-05 15:37:25.626878: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightl
y different numerical results due to floating-point round-off errors from different computation orders. To turn them
off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-03-05 15:37:25.877079: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN
factory: Attempting to register factory for plugin cuDNN when one has already been registered
2024-03-05 15:37:25.877144: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT
factory: Attempting to register factory for plugin cuFFT when one has already been registered
2024-03-05 15:37:25.918724: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBL
AS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
2024-03-05 15:37:25.999476: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized
to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the
appropriate compiler flags.
2024-03-05 15:37:26.845677: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find T
ensorRT

In [3]: img_array = cv2.imread("training/0/Training_3908.jpg")

In [4]: img_array.shape

Out[4]: (48, 48, 3)

In [5]: plt.imshow(img_array)

Out[5]: <matplotlib.image.AxesImage at 0x7f3201e41c60>

localhost:8888/doc/tree/file.ipynb 1/30
3/6/24, 11:47 PM file

In [6]: dir = "training/"


classes = ['0','1','2','3','4','5','6']

In [7]: for category in classes:


path = os.path.join(dir, category)
for img in os.listdir(path):
img_path = os.path.join(path, img)
img_array = cv2.imread(img_path)
if img_array is not None: # Check if image was read successfully
plt.imshow(cv2.cvtColor(img_array, cv2.COLOR_BGR2RGB)) # Convert BGR to RGB
plt.show()
break
break

localhost:8888/doc/tree/file.ipynb 2/30
3/6/24, 11:47 PM file

In [8]: img_size = 224


new_array = cv2.resize(img_array,(img_size,img_size))
plt.imshow(cv2.cvtColor(new_array,cv2.COLOR_BGR2RGB))
plt.show()

localhost:8888/doc/tree/file.ipynb 3/30
3/6/24, 11:47 PM file

In [9]: new_array.shape

Out[9]: (224, 224, 3)

In [10]: train_data = []

def create_train_data():
for category in classes:
path = os.path.join(dir, category)
class_num = classes.index(category)
for img in os.listdir(path):
try:
img_path = os.path.join(path, img)
img_array = cv2.imread(img_path)
new_array = cv2.resize(img_array,(img_size,img_size))

localhost:8888/doc/tree/file.ipynb 4/30
3/6/24, 11:47 PM file

train_data.append([new_array,class_num])
except Exception as e:
pass

create_train_data()

In [11]: print(len(train_data))

28709

In [12]: import random

random.shuffle(train_data)

In [13]: x = []
y = []

for features,label in train_data:


x.append(features)
y.append(label)

x = np.array(x).reshape(-1, img_size, img_size, 3)

In [14]: x.shape

Out[14]: (28709, 224, 224, 3)

In [15]: # x = x/255.0

In [16]: type(y)

Out[16]: list

In [17]: y[0]

Out[17]: 5

In [18]: y = np.array(y)
y.shape

localhost:8888/doc/tree/file.ipynb 5/30
3/6/24, 11:47 PM file

Out[18]: (28709,)

In [19]: from tensorflow import keras


from tensorflow.keras import layers

In [20]: model = tf.keras.applications.MobileNetV2()

In [21]: model.summary()

localhost:8888/doc/tree/file.ipynb 6/30
3/6/24, 11:47 PM file

Model: "mobilenetv2_1.00_224"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_1 (InputLayer) [(None, 224, 224, 3)] 0 []

Conv1 (Conv2D) (None, 112, 112, 32) 864 ['input_1[0][0]']

bn_Conv1 (BatchNormalizati (None, 112, 112, 32) 128 ['Conv1[0][0]']


on)

Conv1_relu (ReLU) (None, 112, 112, 32) 0 ['bn_Conv1[0][0]']

expanded_conv_depthwise (D (None, 112, 112, 32) 288 ['Conv1_relu[0][0]']


epthwiseConv2D)

expanded_conv_depthwise_BN (None, 112, 112, 32) 128 ['expanded_conv_depthwise[0][0


(BatchNormalization) ]']

expanded_conv_depthwise_re (None, 112, 112, 32) 0 ['expanded_conv_depthwise_BN[0


lu (ReLU) ][0]']

expanded_conv_project (Con (None, 112, 112, 16) 512 ['expanded_conv_depthwise_relu


v2D) [0][0]']

expanded_conv_project_BN ( (None, 112, 112, 16) 64 ['expanded_conv_project[0][0]'


BatchNormalization) ]

block_1_expand (Conv2D) (None, 112, 112, 96) 1536 ['expanded_conv_project_BN[0][


0]']

block_1_expand_BN (BatchNo (None, 112, 112, 96) 384 ['block_1_expand[0][0]']


rmalization)

block_1_expand_relu (ReLU) (None, 112, 112, 96) 0 ['block_1_expand_BN[0][0]']

block_1_pad (ZeroPadding2D (None, 113, 113, 96) 0 ['block_1_expand_relu[0][0]']


)

block_1_depthwise (Depthwi (None, 56, 56, 96) 864 ['block_1_pad[0][0]']


seConv2D)

localhost:8888/doc/tree/file.ipynb 7/30
3/6/24, 11:47 PM file

block_1_depthwise_BN (Batc (None, 56, 56, 96) 384 ['block_1_depthwise[0][0]']


hNormalization)

block_1_depthwise_relu (Re (None, 56, 56, 96) 0 ['block_1_depthwise_BN[0][0]']


LU)

block_1_project (Conv2D) (None, 56, 56, 24) 2304 ['block_1_depthwise_relu[0][0]


']

block_1_project_BN (BatchN (None, 56, 56, 24) 96 ['block_1_project[0][0]']


ormalization)

block_2_expand (Conv2D) (None, 56, 56, 144) 3456 ['block_1_project_BN[0][0]']

block_2_expand_BN (BatchNo (None, 56, 56, 144) 576 ['block_2_expand[0][0]']


rmalization)

block_2_expand_relu (ReLU) (None, 56, 56, 144) 0 ['block_2_expand_BN[0][0]']

block_2_depthwise (Depthwi (None, 56, 56, 144) 1296 ['block_2_expand_relu[0][0]']


seConv2D)

block_2_depthwise_BN (Batc (None, 56, 56, 144) 576 ['block_2_depthwise[0][0]']


hNormalization)

block_2_depthwise_relu (Re (None, 56, 56, 144) 0 ['block_2_depthwise_BN[0][0]']


LU)

block_2_project (Conv2D) (None, 56, 56, 24) 3456 ['block_2_depthwise_relu[0][0]


']

block_2_project_BN (BatchN (None, 56, 56, 24) 96 ['block_2_project[0][0]']


ormalization)

block_2_add (Add) (None, 56, 56, 24) 0 ['block_1_project_BN[0][0]',


'block_2_project_BN[0][0]']

block_3_expand (Conv2D) (None, 56, 56, 144) 3456 ['block_2_add[0][0]']

block_3_expand_BN (BatchNo (None, 56, 56, 144) 576 ['block_3_expand[0][0]']

localhost:8888/doc/tree/file.ipynb 8/30
3/6/24, 11:47 PM file

rmalization)

block_3_expand_relu (ReLU) (None, 56, 56, 144) 0 ['block_3_expand_BN[0][0]']

block_3_pad (ZeroPadding2D (None, 57, 57, 144) 0 ['block_3_expand_relu[0][0]']


)

block_3_depthwise (Depthwi (None, 28, 28, 144) 1296 ['block_3_pad[0][0]']


seConv2D)

block_3_depthwise_BN (Batc (None, 28, 28, 144) 576 ['block_3_depthwise[0][0]']


hNormalization)

block_3_depthwise_relu (Re (None, 28, 28, 144) 0 ['block_3_depthwise_BN[0][0]']


LU)

block_3_project (Conv2D) (None, 28, 28, 32) 4608 ['block_3_depthwise_relu[0][0]


']

block_3_project_BN (BatchN (None, 28, 28, 32) 128 ['block_3_project[0][0]']


ormalization)

block_4_expand (Conv2D) (None, 28, 28, 192) 6144 ['block_3_project_BN[0][0]']

block_4_expand_BN (BatchNo (None, 28, 28, 192) 768 ['block_4_expand[0][0]']


rmalization)

block_4_expand_relu (ReLU) (None, 28, 28, 192) 0 ['block_4_expand_BN[0][0]']

block_4_depthwise (Depthwi (None, 28, 28, 192) 1728 ['block_4_expand_relu[0][0]']


seConv2D)

block_4_depthwise_BN (Batc (None, 28, 28, 192) 768 ['block_4_depthwise[0][0]']


hNormalization)

block_4_depthwise_relu (Re (None, 28, 28, 192) 0 ['block_4_depthwise_BN[0][0]']


LU)

block_4_project (Conv2D) (None, 28, 28, 32) 6144 ['block_4_depthwise_relu[0][0]


']

localhost:8888/doc/tree/file.ipynb 9/30
3/6/24, 11:47 PM file

block_4_project_BN (BatchN (None, 28, 28, 32) 128 ['block_4_project[0][0]']


ormalization)

block_4_add (Add) (None, 28, 28, 32) 0 ['block_3_project_BN[0][0]',


'block_4_project_BN[0][0]']

block_5_expand (Conv2D) (None, 28, 28, 192) 6144 ['block_4_add[0][0]']

block_5_expand_BN (BatchNo (None, 28, 28, 192) 768 ['block_5_expand[0][0]']


rmalization)

block_5_expand_relu (ReLU) (None, 28, 28, 192) 0 ['block_5_expand_BN[0][0]']

block_5_depthwise (Depthwi (None, 28, 28, 192) 1728 ['block_5_expand_relu[0][0]']


seConv2D)

block_5_depthwise_BN (Batc (None, 28, 28, 192) 768 ['block_5_depthwise[0][0]']


hNormalization)

block_5_depthwise_relu (Re (None, 28, 28, 192) 0 ['block_5_depthwise_BN[0][0]']


LU)

block_5_project (Conv2D) (None, 28, 28, 32) 6144 ['block_5_depthwise_relu[0][0]


']

block_5_project_BN (BatchN (None, 28, 28, 32) 128 ['block_5_project[0][0]']


ormalization)

block_5_add (Add) (None, 28, 28, 32) 0 ['block_4_add[0][0]',


'block_5_project_BN[0][0]']

block_6_expand (Conv2D) (None, 28, 28, 192) 6144 ['block_5_add[0][0]']

block_6_expand_BN (BatchNo (None, 28, 28, 192) 768 ['block_6_expand[0][0]']


rmalization)

block_6_expand_relu (ReLU) (None, 28, 28, 192) 0 ['block_6_expand_BN[0][0]']

block_6_pad (ZeroPadding2D (None, 29, 29, 192) 0 ['block_6_expand_relu[0][0]']


)

localhost:8888/doc/tree/file.ipynb 10/30
3/6/24, 11:47 PM file

block_6_depthwise (Depthwi (None, 14, 14, 192) 1728 ['block_6_pad[0][0]']


seConv2D)

block_6_depthwise_BN (Batc (None, 14, 14, 192) 768 ['block_6_depthwise[0][0]']


hNormalization)

block_6_depthwise_relu (Re (None, 14, 14, 192) 0 ['block_6_depthwise_BN[0][0]']


LU)

block_6_project (Conv2D) (None, 14, 14, 64) 12288 ['block_6_depthwise_relu[0][0]


']

block_6_project_BN (BatchN (None, 14, 14, 64) 256 ['block_6_project[0][0]']


ormalization)

block_7_expand (Conv2D) (None, 14, 14, 384) 24576 ['block_6_project_BN[0][0]']

block_7_expand_BN (BatchNo (None, 14, 14, 384) 1536 ['block_7_expand[0][0]']


rmalization)

block_7_expand_relu (ReLU) (None, 14, 14, 384) 0 ['block_7_expand_BN[0][0]']

block_7_depthwise (Depthwi (None, 14, 14, 384) 3456 ['block_7_expand_relu[0][0]']


seConv2D)

block_7_depthwise_BN (Batc (None, 14, 14, 384) 1536 ['block_7_depthwise[0][0]']


hNormalization)

block_7_depthwise_relu (Re (None, 14, 14, 384) 0 ['block_7_depthwise_BN[0][0]']


LU)

block_7_project (Conv2D) (None, 14, 14, 64) 24576 ['block_7_depthwise_relu[0][0]


']

block_7_project_BN (BatchN (None, 14, 14, 64) 256 ['block_7_project[0][0]']


ormalization)

block_7_add (Add) (None, 14, 14, 64) 0 ['block_6_project_BN[0][0]',


'block_7_project_BN[0][0]']

block_8_expand (Conv2D) (None, 14, 14, 384) 24576 ['block_7_add[0][0]']

localhost:8888/doc/tree/file.ipynb 11/30
3/6/24, 11:47 PM file

block_8_expand_BN (BatchNo (None, 14, 14, 384) 1536 ['block_8_expand[0][0]']


rmalization)

block_8_expand_relu (ReLU) (None, 14, 14, 384) 0 ['block_8_expand_BN[0][0]']

block_8_depthwise (Depthwi (None, 14, 14, 384) 3456 ['block_8_expand_relu[0][0]']


seConv2D)

block_8_depthwise_BN (Batc (None, 14, 14, 384) 1536 ['block_8_depthwise[0][0]']


hNormalization)

block_8_depthwise_relu (Re (None, 14, 14, 384) 0 ['block_8_depthwise_BN[0][0]']


LU)

block_8_project (Conv2D) (None, 14, 14, 64) 24576 ['block_8_depthwise_relu[0][0]


']

block_8_project_BN (BatchN (None, 14, 14, 64) 256 ['block_8_project[0][0]']


ormalization)

block_8_add (Add) (None, 14, 14, 64) 0 ['block_7_add[0][0]',


'block_8_project_BN[0][0]']

block_9_expand (Conv2D) (None, 14, 14, 384) 24576 ['block_8_add[0][0]']

block_9_expand_BN (BatchNo (None, 14, 14, 384) 1536 ['block_9_expand[0][0]']


rmalization)

block_9_expand_relu (ReLU) (None, 14, 14, 384) 0 ['block_9_expand_BN[0][0]']

block_9_depthwise (Depthwi (None, 14, 14, 384) 3456 ['block_9_expand_relu[0][0]']


seConv2D)

block_9_depthwise_BN (Batc (None, 14, 14, 384) 1536 ['block_9_depthwise[0][0]']


hNormalization)

block_9_depthwise_relu (Re (None, 14, 14, 384) 0 ['block_9_depthwise_BN[0][0]']


LU)

block_9_project (Conv2D) (None, 14, 14, 64) 24576 ['block_9_depthwise_relu[0][0]

localhost:8888/doc/tree/file.ipynb 12/30
3/6/24, 11:47 PM file

']

block_9_project_BN (BatchN (None, 14, 14, 64) 256 ['block_9_project[0][0]']


ormalization)

block_9_add (Add) (None, 14, 14, 64) 0 ['block_8_add[0][0]',


'block_9_project_BN[0][0]']

block_10_expand (Conv2D) (None, 14, 14, 384) 24576 ['block_9_add[0][0]']

block_10_expand_BN (BatchN (None, 14, 14, 384) 1536 ['block_10_expand[0][0]']


ormalization)

block_10_expand_relu (ReLU (None, 14, 14, 384) 0 ['block_10_expand_BN[0][0]']


)

block_10_depthwise (Depthw (None, 14, 14, 384) 3456 ['block_10_expand_relu[0][0]']


iseConv2D)

block_10_depthwise_BN (Bat (None, 14, 14, 384) 1536 ['block_10_depthwise[0][0]']


chNormalization)

block_10_depthwise_relu (R (None, 14, 14, 384) 0 ['block_10_depthwise_BN[0][0]'


eLU) ]

block_10_project (Conv2D) (None, 14, 14, 96) 36864 ['block_10_depthwise_relu[0][0


]']

block_10_project_BN (Batch (None, 14, 14, 96) 384 ['block_10_project[0][0]']


Normalization)

block_11_expand (Conv2D) (None, 14, 14, 576) 55296 ['block_10_project_BN[0][0]']

block_11_expand_BN (BatchN (None, 14, 14, 576) 2304 ['block_11_expand[0][0]']


ormalization)

block_11_expand_relu (ReLU (None, 14, 14, 576) 0 ['block_11_expand_BN[0][0]']


)

block_11_depthwise (Depthw (None, 14, 14, 576) 5184 ['block_11_expand_relu[0][0]']


iseConv2D)

localhost:8888/doc/tree/file.ipynb 13/30
3/6/24, 11:47 PM file

block_11_depthwise_BN (Bat (None, 14, 14, 576) 2304 ['block_11_depthwise[0][0]']


chNormalization)

block_11_depthwise_relu (R (None, 14, 14, 576) 0 ['block_11_depthwise_BN[0][0]'


eLU) ]

block_11_project (Conv2D) (None, 14, 14, 96) 55296 ['block_11_depthwise_relu[0][0


]']

block_11_project_BN (Batch (None, 14, 14, 96) 384 ['block_11_project[0][0]']


Normalization)

block_11_add (Add) (None, 14, 14, 96) 0 ['block_10_project_BN[0][0]',


'block_11_project_BN[0][0]']

block_12_expand (Conv2D) (None, 14, 14, 576) 55296 ['block_11_add[0][0]']

block_12_expand_BN (BatchN (None, 14, 14, 576) 2304 ['block_12_expand[0][0]']


ormalization)

block_12_expand_relu (ReLU (None, 14, 14, 576) 0 ['block_12_expand_BN[0][0]']


)

block_12_depthwise (Depthw (None, 14, 14, 576) 5184 ['block_12_expand_relu[0][0]']


iseConv2D)

block_12_depthwise_BN (Bat (None, 14, 14, 576) 2304 ['block_12_depthwise[0][0]']


chNormalization)

block_12_depthwise_relu (R (None, 14, 14, 576) 0 ['block_12_depthwise_BN[0][0]'


eLU) ]

block_12_project (Conv2D) (None, 14, 14, 96) 55296 ['block_12_depthwise_relu[0][0


]']

block_12_project_BN (Batch (None, 14, 14, 96) 384 ['block_12_project[0][0]']


Normalization)

block_12_add (Add) (None, 14, 14, 96) 0 ['block_11_add[0][0]',


'block_12_project_BN[0][0]']

localhost:8888/doc/tree/file.ipynb 14/30
3/6/24, 11:47 PM file

block_13_expand (Conv2D) (None, 14, 14, 576) 55296 ['block_12_add[0][0]']

block_13_expand_BN (BatchN (None, 14, 14, 576) 2304 ['block_13_expand[0][0]']


ormalization)

block_13_expand_relu (ReLU (None, 14, 14, 576) 0 ['block_13_expand_BN[0][0]']


)

block_13_pad (ZeroPadding2 (None, 15, 15, 576) 0 ['block_13_expand_relu[0][0]']


D)

block_13_depthwise (Depthw (None, 7, 7, 576) 5184 ['block_13_pad[0][0]']


iseConv2D)

block_13_depthwise_BN (Bat (None, 7, 7, 576) 2304 ['block_13_depthwise[0][0]']


chNormalization)

block_13_depthwise_relu (R (None, 7, 7, 576) 0 ['block_13_depthwise_BN[0][0]'


eLU) ]

block_13_project (Conv2D) (None, 7, 7, 160) 92160 ['block_13_depthwise_relu[0][0


]']

block_13_project_BN (Batch (None, 7, 7, 160) 640 ['block_13_project[0][0]']


Normalization)

block_14_expand (Conv2D) (None, 7, 7, 960) 153600 ['block_13_project_BN[0][0]']

block_14_expand_BN (BatchN (None, 7, 7, 960) 3840 ['block_14_expand[0][0]']


ormalization)

block_14_expand_relu (ReLU (None, 7, 7, 960) 0 ['block_14_expand_BN[0][0]']


)

block_14_depthwise (Depthw (None, 7, 7, 960) 8640 ['block_14_expand_relu[0][0]']


iseConv2D)

block_14_depthwise_BN (Bat (None, 7, 7, 960) 3840 ['block_14_depthwise[0][0]']


chNormalization)

localhost:8888/doc/tree/file.ipynb 15/30
3/6/24, 11:47 PM file

block_14_depthwise_relu (R (None, 7, 7, 960) 0 ['block_14_depthwise_BN[0][0]'


eLU) ]

block_14_project (Conv2D) (None, 7, 7, 160) 153600 ['block_14_depthwise_relu[0][0


]']

block_14_project_BN (Batch (None, 7, 7, 160) 640 ['block_14_project[0][0]']


Normalization)

block_14_add (Add) (None, 7, 7, 160) 0 ['block_13_project_BN[0][0]',


'block_14_project_BN[0][0]']

block_15_expand (Conv2D) (None, 7, 7, 960) 153600 ['block_14_add[0][0]']

block_15_expand_BN (BatchN (None, 7, 7, 960) 3840 ['block_15_expand[0][0]']


ormalization)

block_15_expand_relu (ReLU (None, 7, 7, 960) 0 ['block_15_expand_BN[0][0]']


)

block_15_depthwise (Depthw (None, 7, 7, 960) 8640 ['block_15_expand_relu[0][0]']


iseConv2D)

block_15_depthwise_BN (Bat (None, 7, 7, 960) 3840 ['block_15_depthwise[0][0]']


chNormalization)

block_15_depthwise_relu (R (None, 7, 7, 960) 0 ['block_15_depthwise_BN[0][0]'


eLU) ]

block_15_project (Conv2D) (None, 7, 7, 160) 153600 ['block_15_depthwise_relu[0][0


]']

block_15_project_BN (Batch (None, 7, 7, 160) 640 ['block_15_project[0][0]']


Normalization)

block_15_add (Add) (None, 7, 7, 160) 0 ['block_14_add[0][0]',


'block_15_project_BN[0][0]']

block_16_expand (Conv2D) (None, 7, 7, 960) 153600 ['block_15_add[0][0]']

block_16_expand_BN (BatchN (None, 7, 7, 960) 3840 ['block_16_expand[0][0]']

localhost:8888/doc/tree/file.ipynb 16/30
3/6/24, 11:47 PM file

ormalization)

block_16_expand_relu (ReLU (None, 7, 7, 960) 0 ['block_16_expand_BN[0][0]']


)

block_16_depthwise (Depthw (None, 7, 7, 960) 8640 ['block_16_expand_relu[0][0]']


iseConv2D)

block_16_depthwise_BN (Bat (None, 7, 7, 960) 3840 ['block_16_depthwise[0][0]']


chNormalization)

block_16_depthwise_relu (R (None, 7, 7, 960) 0 ['block_16_depthwise_BN[0][0]'


eLU) ]

block_16_project (Conv2D) (None, 7, 7, 320) 307200 ['block_16_depthwise_relu[0][0


]']

block_16_project_BN (Batch (None, 7, 7, 320) 1280 ['block_16_project[0][0]']


Normalization)

Conv_1 (Conv2D) (None, 7, 7, 1280) 409600 ['block_16_project_BN[0][0]']

Conv_1_bn (BatchNormalizat (None, 7, 7, 1280) 5120 ['Conv_1[0][0]']


ion)

out_relu (ReLU) (None, 7, 7, 1280) 0 ['Conv_1_bn[0][0]']

global_average_pooling2d ( (None, 1280) 0 ['out_relu[0][0]']


GlobalAveragePooling2D)

predictions (Dense) (None, 1000) 1281000 ['global_average_pooling2d[0][


0]']

==================================================================================================
Total params: 3538984 (13.50 MB)
Trainable params: 3504872 (13.37 MB)
Non-trainable params: 34112 (133.25 KB)
__________________________________________________________________________________________________

In [22]: base_input = model.layers[0].input

localhost:8888/doc/tree/file.ipynb 17/30
3/6/24, 11:47 PM file

base_output = model.layers[-2].output

In [23]: base_input
base_output

Out[23]: <KerasTensor: shape=(None, 1280) dtype=float32 (created by layer 'global_average_pooling2d')>

In [24]: final_output = layers.Dense(128)(base_output)


final_output = layers.Activation('relu')(final_output)
final_output = layers.Dense(64)(final_output)
final_output = layers.Activation('relu')(final_output)
final_output = layers.Dense(7,activation='softmax')(final_output)

In [25]: final_output

Out[25]: <KerasTensor: shape=(None, 7) dtype=float32 (created by layer 'dense_2')>

In [26]: new_model = keras.Model(inputs = base_input, outputs= final_output)

In [27]: new_model.summary()

localhost:8888/doc/tree/file.ipynb 18/30
3/6/24, 11:47 PM file

Model: "model"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_1 (InputLayer) [(None, 224, 224, 3)] 0 []

Conv1 (Conv2D) (None, 112, 112, 32) 864 ['input_1[0][0]']

bn_Conv1 (BatchNormalizati (None, 112, 112, 32) 128 ['Conv1[0][0]']


on)

Conv1_relu (ReLU) (None, 112, 112, 32) 0 ['bn_Conv1[0][0]']

expanded_conv_depthwise (D (None, 112, 112, 32) 288 ['Conv1_relu[0][0]']


epthwiseConv2D)

expanded_conv_depthwise_BN (None, 112, 112, 32) 128 ['expanded_conv_depthwise[0][0


(BatchNormalization) ]']

expanded_conv_depthwise_re (None, 112, 112, 32) 0 ['expanded_conv_depthwise_BN[0


lu (ReLU) ][0]']

expanded_conv_project (Con (None, 112, 112, 16) 512 ['expanded_conv_depthwise_relu


v2D) [0][0]']

expanded_conv_project_BN ( (None, 112, 112, 16) 64 ['expanded_conv_project[0][0]'


BatchNormalization) ]

block_1_expand (Conv2D) (None, 112, 112, 96) 1536 ['expanded_conv_project_BN[0][


0]']

block_1_expand_BN (BatchNo (None, 112, 112, 96) 384 ['block_1_expand[0][0]']


rmalization)

block_1_expand_relu (ReLU) (None, 112, 112, 96) 0 ['block_1_expand_BN[0][0]']

block_1_pad (ZeroPadding2D (None, 113, 113, 96) 0 ['block_1_expand_relu[0][0]']


)

block_1_depthwise (Depthwi (None, 56, 56, 96) 864 ['block_1_pad[0][0]']


seConv2D)

localhost:8888/doc/tree/file.ipynb 19/30
3/6/24, 11:47 PM file

block_1_depthwise_BN (Batc (None, 56, 56, 96) 384 ['block_1_depthwise[0][0]']


hNormalization)

block_1_depthwise_relu (Re (None, 56, 56, 96) 0 ['block_1_depthwise_BN[0][0]']


LU)

block_1_project (Conv2D) (None, 56, 56, 24) 2304 ['block_1_depthwise_relu[0][0]


']

block_1_project_BN (BatchN (None, 56, 56, 24) 96 ['block_1_project[0][0]']


ormalization)

block_2_expand (Conv2D) (None, 56, 56, 144) 3456 ['block_1_project_BN[0][0]']

block_2_expand_BN (BatchNo (None, 56, 56, 144) 576 ['block_2_expand[0][0]']


rmalization)

block_2_expand_relu (ReLU) (None, 56, 56, 144) 0 ['block_2_expand_BN[0][0]']

block_2_depthwise (Depthwi (None, 56, 56, 144) 1296 ['block_2_expand_relu[0][0]']


seConv2D)

block_2_depthwise_BN (Batc (None, 56, 56, 144) 576 ['block_2_depthwise[0][0]']


hNormalization)

block_2_depthwise_relu (Re (None, 56, 56, 144) 0 ['block_2_depthwise_BN[0][0]']


LU)

block_2_project (Conv2D) (None, 56, 56, 24) 3456 ['block_2_depthwise_relu[0][0]


']

block_2_project_BN (BatchN (None, 56, 56, 24) 96 ['block_2_project[0][0]']


ormalization)

block_2_add (Add) (None, 56, 56, 24) 0 ['block_1_project_BN[0][0]',


'block_2_project_BN[0][0]']

block_3_expand (Conv2D) (None, 56, 56, 144) 3456 ['block_2_add[0][0]']

block_3_expand_BN (BatchNo (None, 56, 56, 144) 576 ['block_3_expand[0][0]']

localhost:8888/doc/tree/file.ipynb 20/30
3/6/24, 11:47 PM file

rmalization)

block_3_expand_relu (ReLU) (None, 56, 56, 144) 0 ['block_3_expand_BN[0][0]']

block_3_pad (ZeroPadding2D (None, 57, 57, 144) 0 ['block_3_expand_relu[0][0]']


)

block_3_depthwise (Depthwi (None, 28, 28, 144) 1296 ['block_3_pad[0][0]']


seConv2D)

block_3_depthwise_BN (Batc (None, 28, 28, 144) 576 ['block_3_depthwise[0][0]']


hNormalization)

block_3_depthwise_relu (Re (None, 28, 28, 144) 0 ['block_3_depthwise_BN[0][0]']


LU)

block_3_project (Conv2D) (None, 28, 28, 32) 4608 ['block_3_depthwise_relu[0][0]


']

block_3_project_BN (BatchN (None, 28, 28, 32) 128 ['block_3_project[0][0]']


ormalization)

block_4_expand (Conv2D) (None, 28, 28, 192) 6144 ['block_3_project_BN[0][0]']

block_4_expand_BN (BatchNo (None, 28, 28, 192) 768 ['block_4_expand[0][0]']


rmalization)

block_4_expand_relu (ReLU) (None, 28, 28, 192) 0 ['block_4_expand_BN[0][0]']

block_4_depthwise (Depthwi (None, 28, 28, 192) 1728 ['block_4_expand_relu[0][0]']


seConv2D)

block_4_depthwise_BN (Batc (None, 28, 28, 192) 768 ['block_4_depthwise[0][0]']


hNormalization)

block_4_depthwise_relu (Re (None, 28, 28, 192) 0 ['block_4_depthwise_BN[0][0]']


LU)

block_4_project (Conv2D) (None, 28, 28, 32) 6144 ['block_4_depthwise_relu[0][0]


']

localhost:8888/doc/tree/file.ipynb 21/30
3/6/24, 11:47 PM file

block_4_project_BN (BatchN (None, 28, 28, 32) 128 ['block_4_project[0][0]']


ormalization)

block_4_add (Add) (None, 28, 28, 32) 0 ['block_3_project_BN[0][0]',


'block_4_project_BN[0][0]']

block_5_expand (Conv2D) (None, 28, 28, 192) 6144 ['block_4_add[0][0]']

block_5_expand_BN (BatchNo (None, 28, 28, 192) 768 ['block_5_expand[0][0]']


rmalization)

block_5_expand_relu (ReLU) (None, 28, 28, 192) 0 ['block_5_expand_BN[0][0]']

block_5_depthwise (Depthwi (None, 28, 28, 192) 1728 ['block_5_expand_relu[0][0]']


seConv2D)

block_5_depthwise_BN (Batc (None, 28, 28, 192) 768 ['block_5_depthwise[0][0]']


hNormalization)

block_5_depthwise_relu (Re (None, 28, 28, 192) 0 ['block_5_depthwise_BN[0][0]']


LU)

block_5_project (Conv2D) (None, 28, 28, 32) 6144 ['block_5_depthwise_relu[0][0]


']

block_5_project_BN (BatchN (None, 28, 28, 32) 128 ['block_5_project[0][0]']


ormalization)

block_5_add (Add) (None, 28, 28, 32) 0 ['block_4_add[0][0]',


'block_5_project_BN[0][0]']

block_6_expand (Conv2D) (None, 28, 28, 192) 6144 ['block_5_add[0][0]']

block_6_expand_BN (BatchNo (None, 28, 28, 192) 768 ['block_6_expand[0][0]']


rmalization)

block_6_expand_relu (ReLU) (None, 28, 28, 192) 0 ['block_6_expand_BN[0][0]']

block_6_pad (ZeroPadding2D (None, 29, 29, 192) 0 ['block_6_expand_relu[0][0]']


)

localhost:8888/doc/tree/file.ipynb 22/30
3/6/24, 11:47 PM file

block_6_depthwise (Depthwi (None, 14, 14, 192) 1728 ['block_6_pad[0][0]']


seConv2D)

block_6_depthwise_BN (Batc (None, 14, 14, 192) 768 ['block_6_depthwise[0][0]']


hNormalization)

block_6_depthwise_relu (Re (None, 14, 14, 192) 0 ['block_6_depthwise_BN[0][0]']


LU)

block_6_project (Conv2D) (None, 14, 14, 64) 12288 ['block_6_depthwise_relu[0][0]


']

block_6_project_BN (BatchN (None, 14, 14, 64) 256 ['block_6_project[0][0]']


ormalization)

block_7_expand (Conv2D) (None, 14, 14, 384) 24576 ['block_6_project_BN[0][0]']

block_7_expand_BN (BatchNo (None, 14, 14, 384) 1536 ['block_7_expand[0][0]']


rmalization)

block_7_expand_relu (ReLU) (None, 14, 14, 384) 0 ['block_7_expand_BN[0][0]']

block_7_depthwise (Depthwi (None, 14, 14, 384) 3456 ['block_7_expand_relu[0][0]']


seConv2D)

block_7_depthwise_BN (Batc (None, 14, 14, 384) 1536 ['block_7_depthwise[0][0]']


hNormalization)

block_7_depthwise_relu (Re (None, 14, 14, 384) 0 ['block_7_depthwise_BN[0][0]']


LU)

block_7_project (Conv2D) (None, 14, 14, 64) 24576 ['block_7_depthwise_relu[0][0]


']

block_7_project_BN (BatchN (None, 14, 14, 64) 256 ['block_7_project[0][0]']


ormalization)

block_7_add (Add) (None, 14, 14, 64) 0 ['block_6_project_BN[0][0]',


'block_7_project_BN[0][0]']

block_8_expand (Conv2D) (None, 14, 14, 384) 24576 ['block_7_add[0][0]']

localhost:8888/doc/tree/file.ipynb 23/30
3/6/24, 11:47 PM file

block_8_expand_BN (BatchNo (None, 14, 14, 384) 1536 ['block_8_expand[0][0]']


rmalization)

block_8_expand_relu (ReLU) (None, 14, 14, 384) 0 ['block_8_expand_BN[0][0]']

block_8_depthwise (Depthwi (None, 14, 14, 384) 3456 ['block_8_expand_relu[0][0]']


seConv2D)

block_8_depthwise_BN (Batc (None, 14, 14, 384) 1536 ['block_8_depthwise[0][0]']


hNormalization)

block_8_depthwise_relu (Re (None, 14, 14, 384) 0 ['block_8_depthwise_BN[0][0]']


LU)

block_8_project (Conv2D) (None, 14, 14, 64) 24576 ['block_8_depthwise_relu[0][0]


']

block_8_project_BN (BatchN (None, 14, 14, 64) 256 ['block_8_project[0][0]']


ormalization)

block_8_add (Add) (None, 14, 14, 64) 0 ['block_7_add[0][0]',


'block_8_project_BN[0][0]']

block_9_expand (Conv2D) (None, 14, 14, 384) 24576 ['block_8_add[0][0]']

block_9_expand_BN (BatchNo (None, 14, 14, 384) 1536 ['block_9_expand[0][0]']


rmalization)

block_9_expand_relu (ReLU) (None, 14, 14, 384) 0 ['block_9_expand_BN[0][0]']

block_9_depthwise (Depthwi (None, 14, 14, 384) 3456 ['block_9_expand_relu[0][0]']


seConv2D)

block_9_depthwise_BN (Batc (None, 14, 14, 384) 1536 ['block_9_depthwise[0][0]']


hNormalization)

block_9_depthwise_relu (Re (None, 14, 14, 384) 0 ['block_9_depthwise_BN[0][0]']


LU)

block_9_project (Conv2D) (None, 14, 14, 64) 24576 ['block_9_depthwise_relu[0][0]

localhost:8888/doc/tree/file.ipynb 24/30
3/6/24, 11:47 PM file

']

block_9_project_BN (BatchN (None, 14, 14, 64) 256 ['block_9_project[0][0]']


ormalization)

block_9_add (Add) (None, 14, 14, 64) 0 ['block_8_add[0][0]',


'block_9_project_BN[0][0]']

block_10_expand (Conv2D) (None, 14, 14, 384) 24576 ['block_9_add[0][0]']

block_10_expand_BN (BatchN (None, 14, 14, 384) 1536 ['block_10_expand[0][0]']


ormalization)

block_10_expand_relu (ReLU (None, 14, 14, 384) 0 ['block_10_expand_BN[0][0]']


)

block_10_depthwise (Depthw (None, 14, 14, 384) 3456 ['block_10_expand_relu[0][0]']


iseConv2D)

block_10_depthwise_BN (Bat (None, 14, 14, 384) 1536 ['block_10_depthwise[0][0]']


chNormalization)

block_10_depthwise_relu (R (None, 14, 14, 384) 0 ['block_10_depthwise_BN[0][0]'


eLU) ]

block_10_project (Conv2D) (None, 14, 14, 96) 36864 ['block_10_depthwise_relu[0][0


]']

block_10_project_BN (Batch (None, 14, 14, 96) 384 ['block_10_project[0][0]']


Normalization)

block_11_expand (Conv2D) (None, 14, 14, 576) 55296 ['block_10_project_BN[0][0]']

block_11_expand_BN (BatchN (None, 14, 14, 576) 2304 ['block_11_expand[0][0]']


ormalization)

block_11_expand_relu (ReLU (None, 14, 14, 576) 0 ['block_11_expand_BN[0][0]']


)

block_11_depthwise (Depthw (None, 14, 14, 576) 5184 ['block_11_expand_relu[0][0]']


iseConv2D)

localhost:8888/doc/tree/file.ipynb 25/30
3/6/24, 11:47 PM file

block_11_depthwise_BN (Bat (None, 14, 14, 576) 2304 ['block_11_depthwise[0][0]']


chNormalization)

block_11_depthwise_relu (R (None, 14, 14, 576) 0 ['block_11_depthwise_BN[0][0]'


eLU) ]

block_11_project (Conv2D) (None, 14, 14, 96) 55296 ['block_11_depthwise_relu[0][0


]']

block_11_project_BN (Batch (None, 14, 14, 96) 384 ['block_11_project[0][0]']


Normalization)

block_11_add (Add) (None, 14, 14, 96) 0 ['block_10_project_BN[0][0]',


'block_11_project_BN[0][0]']

block_12_expand (Conv2D) (None, 14, 14, 576) 55296 ['block_11_add[0][0]']

block_12_expand_BN (BatchN (None, 14, 14, 576) 2304 ['block_12_expand[0][0]']


ormalization)

block_12_expand_relu (ReLU (None, 14, 14, 576) 0 ['block_12_expand_BN[0][0]']


)

block_12_depthwise (Depthw (None, 14, 14, 576) 5184 ['block_12_expand_relu[0][0]']


iseConv2D)

block_12_depthwise_BN (Bat (None, 14, 14, 576) 2304 ['block_12_depthwise[0][0]']


chNormalization)

block_12_depthwise_relu (R (None, 14, 14, 576) 0 ['block_12_depthwise_BN[0][0]'


eLU) ]

block_12_project (Conv2D) (None, 14, 14, 96) 55296 ['block_12_depthwise_relu[0][0


]']

block_12_project_BN (Batch (None, 14, 14, 96) 384 ['block_12_project[0][0]']


Normalization)

block_12_add (Add) (None, 14, 14, 96) 0 ['block_11_add[0][0]',


'block_12_project_BN[0][0]']

localhost:8888/doc/tree/file.ipynb 26/30
3/6/24, 11:47 PM file

block_13_expand (Conv2D) (None, 14, 14, 576) 55296 ['block_12_add[0][0]']

block_13_expand_BN (BatchN (None, 14, 14, 576) 2304 ['block_13_expand[0][0]']


ormalization)

block_13_expand_relu (ReLU (None, 14, 14, 576) 0 ['block_13_expand_BN[0][0]']


)

block_13_pad (ZeroPadding2 (None, 15, 15, 576) 0 ['block_13_expand_relu[0][0]']


D)

block_13_depthwise (Depthw (None, 7, 7, 576) 5184 ['block_13_pad[0][0]']


iseConv2D)

block_13_depthwise_BN (Bat (None, 7, 7, 576) 2304 ['block_13_depthwise[0][0]']


chNormalization)

block_13_depthwise_relu (R (None, 7, 7, 576) 0 ['block_13_depthwise_BN[0][0]'


eLU) ]

block_13_project (Conv2D) (None, 7, 7, 160) 92160 ['block_13_depthwise_relu[0][0


]']

block_13_project_BN (Batch (None, 7, 7, 160) 640 ['block_13_project[0][0]']


Normalization)

block_14_expand (Conv2D) (None, 7, 7, 960) 153600 ['block_13_project_BN[0][0]']

block_14_expand_BN (BatchN (None, 7, 7, 960) 3840 ['block_14_expand[0][0]']


ormalization)

block_14_expand_relu (ReLU (None, 7, 7, 960) 0 ['block_14_expand_BN[0][0]']


)

block_14_depthwise (Depthw (None, 7, 7, 960) 8640 ['block_14_expand_relu[0][0]']


iseConv2D)

block_14_depthwise_BN (Bat (None, 7, 7, 960) 3840 ['block_14_depthwise[0][0]']


chNormalization)

localhost:8888/doc/tree/file.ipynb 27/30
3/6/24, 11:47 PM file

block_14_depthwise_relu (R (None, 7, 7, 960) 0 ['block_14_depthwise_BN[0][0]'


eLU) ]

block_14_project (Conv2D) (None, 7, 7, 160) 153600 ['block_14_depthwise_relu[0][0


]']

block_14_project_BN (Batch (None, 7, 7, 160) 640 ['block_14_project[0][0]']


Normalization)

block_14_add (Add) (None, 7, 7, 160) 0 ['block_13_project_BN[0][0]',


'block_14_project_BN[0][0]']

block_15_expand (Conv2D) (None, 7, 7, 960) 153600 ['block_14_add[0][0]']

block_15_expand_BN (BatchN (None, 7, 7, 960) 3840 ['block_15_expand[0][0]']


ormalization)

block_15_expand_relu (ReLU (None, 7, 7, 960) 0 ['block_15_expand_BN[0][0]']


)

block_15_depthwise (Depthw (None, 7, 7, 960) 8640 ['block_15_expand_relu[0][0]']


iseConv2D)

block_15_depthwise_BN (Bat (None, 7, 7, 960) 3840 ['block_15_depthwise[0][0]']


chNormalization)

block_15_depthwise_relu (R (None, 7, 7, 960) 0 ['block_15_depthwise_BN[0][0]'


eLU) ]

block_15_project (Conv2D) (None, 7, 7, 160) 153600 ['block_15_depthwise_relu[0][0


]']

block_15_project_BN (Batch (None, 7, 7, 160) 640 ['block_15_project[0][0]']


Normalization)

block_15_add (Add) (None, 7, 7, 160) 0 ['block_14_add[0][0]',


'block_15_project_BN[0][0]']

block_16_expand (Conv2D) (None, 7, 7, 960) 153600 ['block_15_add[0][0]']

block_16_expand_BN (BatchN (None, 7, 7, 960) 3840 ['block_16_expand[0][0]']

localhost:8888/doc/tree/file.ipynb 28/30
3/6/24, 11:47 PM file

ormalization)

block_16_expand_relu (ReLU (None, 7, 7, 960) 0 ['block_16_expand_BN[0][0]']


)

block_16_depthwise (Depthw (None, 7, 7, 960) 8640 ['block_16_expand_relu[0][0]']


iseConv2D)

block_16_depthwise_BN (Bat (None, 7, 7, 960) 3840 ['block_16_depthwise[0][0]']


chNormalization)

block_16_depthwise_relu (R (None, 7, 7, 960) 0 ['block_16_depthwise_BN[0][0]'


eLU) ]

block_16_project (Conv2D) (None, 7, 7, 320) 307200 ['block_16_depthwise_relu[0][0


]']

block_16_project_BN (Batch (None, 7, 7, 320) 1280 ['block_16_project[0][0]']


Normalization)

Conv_1 (Conv2D) (None, 7, 7, 1280) 409600 ['block_16_project_BN[0][0]']

Conv_1_bn (BatchNormalizat (None, 7, 7, 1280) 5120 ['Conv_1[0][0]']


ion)

out_relu (ReLU) (None, 7, 7, 1280) 0 ['Conv_1_bn[0][0]']

global_average_pooling2d ( (None, 1280) 0 ['out_relu[0][0]']


GlobalAveragePooling2D)

dense (Dense) (None, 128) 163968 ['global_average_pooling2d[0][


0]']

activation (Activation) (None, 128) 0 ['dense[0][0]']

dense_1 (Dense) (None, 64) 8256 ['activation[0][0]']

activation_1 (Activation) (None, 64) 0 ['dense_1[0][0]']

dense_2 (Dense) (None, 7) 455 ['activation_1[0][0]']

localhost:8888/doc/tree/file.ipynb 29/30
3/6/24, 11:47 PM file

==================================================================================================
Total params: 2430663 (9.27 MB)
Trainable params: 2396551 (9.14 MB)
Non-trainable params: 34112 (133.25 KB)
__________________________________________________________________________________________________

In [28]: new_model.compile(loss="sparse_categorical_crossentropy", optimizer="adam", metrics=["accuracy"])

In [29]: history = new_model.fit(x,y, batch_size = 32, epochs=5, verbose="True")

The Kernel crashed while executing code in the the current cell or a previous cell. Please review the code in the ce
ll(s) to identify a possible cause of the failure. Click <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a>
for more info. View Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details.

localhost:8888/doc/tree/file.ipynb 30/30

You might also like