{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport cv2\nimport matplotlib.pyplot as plt\nimport os\nimport random\nimport seaborn as sns\nimport tensorflow as tf\nfrom pathlib import Path\nfrom tensorflow.keras import applications\nfrom tensorflow.keras import losses\nfrom tensorflow.keras import optimizers\nfrom tensorflow.keras import metrics\nfrom tensorflow.keras import Model\nfrom tensorflow.keras.applications import resnet\n\n\ntarget_shape = (200, 200)\n\n\nimport plotly.express as px\n\nfrom PIL import Image\n\nfrom scipy.stats import mode, skew\n\nfrom sklearn.mixture import GaussianMixture\nfrom sklearn.preprocessing import StandardScaler\n\n\nimport warnings\nwarnings.filterwarnings(\"ignore\", category=DeprecationWarning)\nwarnings.filterwarnings(\"ignore\", category=UserWarning)\nwarnings.filterwarnings(\"ignore\", category=FutureWarning)\nimport imageio\nimport skimage\nimport scipy.ndimage as ndi\nsns.set_style('darkgrid')\nsns.set_color_codes('bright')\nfrom tensorflow.keras.applications import ResNet50\nfrom sklearn.model_selection import train_test_split\nfrom tensorflow.keras import layers , Sequential\n","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:10.070490Z","iopub.execute_input":"2023-08-31T16:02:10.070897Z","iopub.status.idle":"2023-08-31T16:02:16.395529Z","shell.execute_reply.started":"2023-08-31T16:02:10.070864Z","shell.execute_reply":"2023-08-31T16:02:16.394464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Import laibirary","metadata":{}},{"cell_type":"raw","source":"","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base = \"../input/bioverse-hackathon-a/train/\"","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:16.397731Z","iopub.execute_input":"2023-08-31T16:02:16.398121Z","iopub.status.idle":"2023-08-31T16:02:16.403668Z","shell.execute_reply.started":"2023-08-31T16:02:16.398085Z","shell.execute_reply":"2023-08-31T16:02:16.402338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.path.join(base,'/normal/')","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:16.405048Z","iopub.execute_input":"2023-08-31T16:02:16.405371Z","iopub.status.idle":"2023-08-31T16:02:16.421633Z","shell.execute_reply.started":"2023-08-31T16:02:16.405339Z","shell.execute_reply":"2023-08-31T16:02:16.420339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classes = []\nimgs = []\nphotos=[]\nfor folder in os.listdir(base):\n    folder_path = os.path.join(base, folder)\n    for file in os.listdir(folder_path):\n        file_path = os.path.join(folder_path, file)\n        for img in os.listdir(file_path):\n            img_path = os.path.join(file_path,img)\n            imgs.append(img_path)\n            photos.append(cv2.imread(img_path))\n            classes.append(folder)","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:16.424082Z","iopub.execute_input":"2023-08-31T16:02:16.424375Z","iopub.status.idle":"2023-08-31T16:02:42.150862Z","shell.execute_reply.started":"2023-08-31T16:02:16.424352Z","shell.execute_reply":"2023-08-31T16:02:42.149767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.DataFrame([imgs,classes]).T","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:42.152254Z","iopub.execute_input":"2023-08-31T16:02:42.152703Z","iopub.status.idle":"2023-08-31T16:02:42.176052Z","shell.execute_reply.started":"2023-08-31T16:02:42.152663Z","shell.execute_reply":"2023-08-31T16:02:42.174892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:42.178002Z","iopub.execute_input":"2023-08-31T16:02:42.178754Z","iopub.status.idle":"2023-08-31T16:02:42.197098Z","shell.execute_reply.started":"2023-08-31T16:02:42.178718Z","shell.execute_reply":"2023-08-31T16:02:42.196003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def preprocess_img(img):\n    resized = cv2.resize(img, (224,224))\n    eq_img = skimage.exposure.equalize_adapthist(resized)\n    return eq_img","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:42.198579Z","iopub.execute_input":"2023-08-31T16:02:42.198923Z","iopub.status.idle":"2023-08-31T16:02:42.204138Z","shell.execute_reply.started":"2023-08-31T16:02:42.198890Z","shell.execute_reply":"2023-08-31T16:02:42.202868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(preprocess_img(photos[2]))","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:42.206074Z","iopub.execute_input":"2023-08-31T16:02:42.206443Z","iopub.status.idle":"2023-08-31T16:02:42.686435Z","shell.execute_reply.started":"2023-08-31T16:02:42.206409Z","shell.execute_reply":"2023-08-31T16:02:42.685488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(photos[2])","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:42.687587Z","iopub.execute_input":"2023-08-31T16:02:42.687935Z","iopub.status.idle":"2023-08-31T16:02:44.260433Z","shell.execute_reply.started":"2023-08-31T16:02:42.687902Z","shell.execute_reply":"2023-08-31T16:02:44.259325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preprocessed_images = []\nfor i in photos:\n    preprocessed_images.append(preprocess_img(i))","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:44.265475Z","iopub.execute_input":"2023-08-31T16:02:44.265959Z","iopub.status.idle":"2023-08-31T16:02:58.392174Z","shell.execute_reply.started":"2023-08-31T16:02:44.265912Z","shell.execute_reply":"2023-08-31T16:02:58.391093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# fig , axes = plt.subplots(1,4)\n# for i in range(len(axes)):\n#     axes[i].imshow(preprocessed_images[i*95])\n#     axes[i].set_title(classes[i*95])\n#     axes[i].axis('off')","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.393860Z","iopub.execute_input":"2023-08-31T16:02:58.394659Z","iopub.status.idle":"2023-08-31T16:02:58.399094Z","shell.execute_reply.started":"2023-08-31T16:02:58.394620Z","shell.execute_reply":"2023-08-31T16:02:58.398104Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# model = Sequential()\n\n# # Conv 01 Layer\n# model.add(layers.Convolution2D(96, 11,padding = \"valid\",strides =(4, 4),input_shape = (224, 224, 3),activation = \"relu\"))\n\n# model.add(layers.MaxPooling2D(pool_size = (2, 2),strides = (2, 2),padding=\"valid\"))\n# model.add(layers.BatchNormalization())\n\n\n\n# # Conv 02 Layer\n# model.add(layers.Convolution2D(256, 5,padding = \"valid\",strides =(1, 1),activation = \"relu\"))\n\n# model.add(layers.MaxPooling2D(pool_size = (2, 2),strides = (2, 2),padding=\"valid\"))\n# model.add(layers.BatchNormalization())\n\n\n# # Conv 03 Layer\n# model.add(layers.Convolution2D(384, 3,padding = \"valid\",strides =(1, 1),activation = \"relu\"))\n# model.add(layers.BatchNormalization())\n\n\n# # Conv 04 Layer\n# model.add(layers.Convolution2D(384, 3,padding = \"valid\",strides =(1, 1),activation = \"relu\"))\n# model.add(layers.BatchNormalization())\n\n\n\n# # Conv 05 Layer\n# model.add(layers.Convolution2D(256, 3,padding = \"valid\",strides =(1, 1),activation = \"relu\"))\n\n# model.add(layers.MaxPooling2D(pool_size = (3, 3),strides = (2, 2),padding=\"valid\"))\n# model.add(layers.BatchNormalization())\n\n\n# # Flatten Layer\n# model.add(layers.Flatten())\n\n\n# # Dense 01\n# model.add(layers.Dense(4096, activation=\"relu\"))\n# model.add(layers.Dropout(0.2))\n# model.add(layers.BatchNormalization())\n\n\n# # Dense 02\n# model.add(layers.Dense(4096, activation=\"relu\"))\n# model.add(layers.Dropout(0.2))\n# model.add(layers.BatchNormalization())\n\n\n# # Dense 03\n# model.add(layers.Dense(1000, activation=\"relu\"))\n# model.add(layers.Dropout(0.2))\n# model.add(layers.BatchNormalization())\n\n\n# # Final Layer\n# model.add(layers.Dense(3, activation=\"softmax\"))","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.400404Z","iopub.execute_input":"2023-08-31T16:02:58.401279Z","iopub.status.idle":"2023-08-31T16:02:58.415011Z","shell.execute_reply.started":"2023-08-31T16:02:58.401243Z","shell.execute_reply":"2023-08-31T16:02:58.413944Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# One Hote Incoding","metadata":{}},{"cell_type":"code","source":"labels_ohe = pd.get_dummies(df[1])","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.416263Z","iopub.execute_input":"2023-08-31T16:02:58.417161Z","iopub.status.idle":"2023-08-31T16:02:58.431792Z","shell.execute_reply.started":"2023-08-31T16:02:58.417126Z","shell.execute_reply":"2023-08-31T16:02:58.430762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y=np.array(labels_ohe)\nX= np.array(preprocessed_images)","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.435332Z","iopub.execute_input":"2023-08-31T16:02:58.435688Z","iopub.status.idle":"2023-08-31T16:02:58.579550Z","shell.execute_reply.started":"2023-08-31T16:02:58.435654Z","shell.execute_reply":"2023-08-31T16:02:58.578459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# beneign\tmalignant\tnormal","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.581250Z","iopub.execute_input":"2023-08-31T16:02:58.581637Z","iopub.status.idle":"2023-08-31T16:02:58.587765Z","shell.execute_reply.started":"2023-08-31T16:02:58.581603Z","shell.execute_reply":"2023-08-31T16:02:58.586037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# type(preprocessed_images)","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.589606Z","iopub.execute_input":"2023-08-31T16:02:58.590030Z","iopub.status.idle":"2023-08-31T16:02:58.595868Z","shell.execute_reply.started":"2023-08-31T16:02:58.589997Z","shell.execute_reply":"2023-08-31T16:02:58.594855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Spliting Data","metadata":{}},{"cell_type":"code","source":"x_train,x_val, y_train,y_val = train_test_split(X,y,test_size=0.15,random_state=42,shuffle=True)","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.597401Z","iopub.execute_input":"2023-08-31T16:02:58.598029Z","iopub.status.idle":"2023-08-31T16:02:58.739000Z","shell.execute_reply.started":"2023-08-31T16:02:58.597996Z","shell.execute_reply":"2023-08-31T16:02:58.737914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# model.compile(optimizer ='adam', loss = 'categorical_crossentropy',metrics = ['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.741224Z","iopub.execute_input":"2023-08-31T16:02:58.742012Z","iopub.status.idle":"2023-08-31T16:02:58.746372Z","shell.execute_reply.started":"2023-08-31T16:02:58.741950Z","shell.execute_reply":"2023-08-31T16:02:58.745254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# model.fit(x_train,y_train,epochs=40)","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.748187Z","iopub.execute_input":"2023-08-31T16:02:58.748904Z","iopub.status.idle":"2023-08-31T16:02:58.756635Z","shell.execute_reply.started":"2023-08-31T16:02:58.748869Z","shell.execute_reply":"2023-08-31T16:02:58.755505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# resnet =  ResNet50(input_shape = (224,224,3) ,include_top=False,weights='imagenet')","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.759905Z","iopub.execute_input":"2023-08-31T16:02:58.760289Z","iopub.status.idle":"2023-08-31T16:02:58.767078Z","shell.execute_reply.started":"2023-08-31T16:02:58.760264Z","shell.execute_reply":"2023-08-31T16:02:58.766120Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# for layer in resnet.layers:\n#     layer.trainable = False","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.768447Z","iopub.execute_input":"2023-08-31T16:02:58.768866Z","iopub.status.idle":"2023-08-31T16:02:58.777296Z","shell.execute_reply.started":"2023-08-31T16:02:58.768833Z","shell.execute_reply":"2023-08-31T16:02:58.776224Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# z = layers.Flatten()(resnet.output)\n# z = layers.Dense(256,activation='relu')(z)\n# z_output = layers.Dense(3,activation='softmax')(z)\n\n# resnet_model = tf.keras.models.Model(inputs=resnet.input , outputs = z_output)\n\n# resnet_model.compile(optimizer ='adam', loss = 'categorical_crossentropy',metrics = ['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.780464Z","iopub.execute_input":"2023-08-31T16:02:58.780758Z","iopub.status.idle":"2023-08-31T16:02:58.787790Z","shell.execute_reply.started":"2023-08-31T16:02:58.780732Z","shell.execute_reply":"2023-08-31T16:02:58.786581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# resnet_model.fit(x_train,y_train,epochs=35)","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.789393Z","iopub.execute_input":"2023-08-31T16:02:58.789754Z","iopub.status.idle":"2023-08-31T16:02:58.798141Z","shell.execute_reply.started":"2023-08-31T16:02:58.789720Z","shell.execute_reply":"2023-08-31T16:02:58.796784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.models import load_model","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.799714Z","iopub.execute_input":"2023-08-31T16:02:58.800144Z","iopub.status.idle":"2023-08-31T16:02:58.807927Z","shell.execute_reply.started":"2023-08-31T16:02:58.800112Z","shell.execute_reply":"2023-08-31T16:02:58.806901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# t_dir = os.listdir('../input/bioverse-hackathon-a/test')\n# test_imgs = []\n# for i in t_dir:\n#     test_imgs.append(cv2.imread(f\"../input/bioverse-hackathon-a/test/{i}\"))","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.810728Z","iopub.execute_input":"2023-08-31T16:02:58.811142Z","iopub.status.idle":"2023-08-31T16:02:58.818303Z","shell.execute_reply.started":"2023-08-31T16:02:58.811107Z","shell.execute_reply":"2023-08-31T16:02:58.817262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# preprocessed_test = []\n# for i in test_imgs:\n#     preprocessed_test.append(preprocess_img(i))","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.819857Z","iopub.execute_input":"2023-08-31T16:02:58.820256Z","iopub.status.idle":"2023-08-31T16:02:58.828030Z","shell.execute_reply.started":"2023-08-31T16:02:58.820198Z","shell.execute_reply":"2023-08-31T16:02:58.826951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# predicts = model.predict(np.array(preprocessed_test))","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.829401Z","iopub.execute_input":"2023-08-31T16:02:58.829933Z","iopub.status.idle":"2023-08-31T16:02:58.838430Z","shell.execute_reply.started":"2023-08-31T16:02:58.829899Z","shell.execute_reply":"2023-08-31T16:02:58.837176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# preds_test = [np.argmax(i) for i in predicts]","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.846333Z","iopub.execute_input":"2023-08-31T16:02:58.847086Z","iopub.status.idle":"2023-08-31T16:02:58.851107Z","shell.execute_reply.started":"2023-08-31T16:02:58.847051Z","shell.execute_reply":"2023-08-31T16:02:58.850059Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test_label = []\n# for i in t_dir:\n#     test_label.append(f\"{i}\")","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.853014Z","iopub.execute_input":"2023-08-31T16:02:58.853750Z","iopub.status.idle":"2023-08-31T16:02:58.862587Z","shell.execute_reply.started":"2023-08-31T16:02:58.853709Z","shell.execute_reply":"2023-08-31T16:02:58.861800Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# df_test = pd.DataFrame([test_label , preds_test]).T\n","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.864219Z","iopub.execute_input":"2023-08-31T16:02:58.864989Z","iopub.status.idle":"2023-08-31T16:02:58.872659Z","shell.execute_reply.started":"2023-08-31T16:02:58.864917Z","shell.execute_reply":"2023-08-31T16:02:58.871550Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# df_test[1] = df_test[1].replace({0:'beneign' , 1:'malignant' , 2:'normal'})\n# # beneign\tmalignant\tnormal","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.874597Z","iopub.execute_input":"2023-08-31T16:02:58.875457Z","iopub.status.idle":"2023-08-31T16:02:58.881752Z","shell.execute_reply.started":"2023-08-31T16:02:58.875419Z","shell.execute_reply":"2023-08-31T16:02:58.880926Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# df_test","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.883372Z","iopub.execute_input":"2023-08-31T16:02:58.884131Z","iopub.status.idle":"2023-08-31T16:02:58.891105Z","shell.execute_reply.started":"2023-08-31T16:02:58.884095Z","shell.execute_reply":"2023-08-31T16:02:58.890237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# df_test.to_csv('submission.csv',index = False)","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.892623Z","iopub.execute_input":"2023-08-31T16:02:58.893434Z","iopub.status.idle":"2023-08-31T16:02:58.901825Z","shell.execute_reply.started":"2023-08-31T16:02:58.893400Z","shell.execute_reply":"2023-08-31T16:02:58.900699Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout\n\ndef AlexNet(input_shape, num_classes):\n    model = Sequential([\n        Conv2D(96, (11, 11), strides=(4, 4), activation='relu', input_shape=input_shape),\n        MaxPooling2D((3, 3), strides=(2, 2)),\n        Conv2D(256, (5, 5), padding='same', activation='relu'),\n        MaxPooling2D((3, 3), strides=(2, 2)),\n        Conv2D(384, (3, 3), padding='same', activation='relu'),\n        Conv2D(384, (3, 3), padding='same', activation='relu'),\n        Conv2D(256, (3, 3), padding='same', activation='relu'),\n        MaxPooling2D((3, 3), strides=(2, 2)),\n        Flatten(),\n        Dense(4096, activation='relu'),\n        Dropout(0.5),\n        Dense(4096, activation='relu'),\n        Dropout(0.5),\n        Dense(num_classes, activation='softmax')\n    ])\n    return model\n\n# Define the input shape and number of classes\ninput_shape = (227, 227, 3)  # Adjust based on your image size\nnum_classes = 1000  # Adjust based on your classification task\n\n# Create an instance of the AlexNet model\nmodel = AlexNet((224,224,3), 3)\nprint(model.summary())\n","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:02:58.903771Z","iopub.execute_input":"2023-08-31T16:02:58.904291Z","iopub.status.idle":"2023-08-31T16:03:02.170723Z","shell.execute_reply.started":"2023-08-31T16:02:58.904256Z","shell.execute_reply":"2023-08-31T16:03:02.169890Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer ='adam', loss = 'categorical_crossentropy',metrics = ['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:03:02.171871Z","iopub.execute_input":"2023-08-31T16:03:02.172265Z","iopub.status.idle":"2023-08-31T16:03:02.203769Z","shell.execute_reply.started":"2023-08-31T16:03:02.172230Z","shell.execute_reply":"2023-08-31T16:03:02.202761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(x_train,y_train , epochs = 50)","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:03:02.205409Z","iopub.execute_input":"2023-08-31T16:03:02.206130Z","iopub.status.idle":"2023-08-31T16:03:45.088099Z","shell.execute_reply.started":"2023-08-31T16:03:02.206094Z","shell.execute_reply":"2023-08-31T16:03:45.086384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save('my_model.h5') # creates a HDF5 file 'my_model.h5'\ndel model # deletes the existing model\n\n# returns a compiled model\n# identical to the previous one\nmodel = load_model('my_model.h5')","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:03:45.093985Z","iopub.execute_input":"2023-08-31T16:03:45.094312Z","iopub.status.idle":"2023-08-31T16:03:57.993204Z","shell.execute_reply.started":"2023-08-31T16:03:45.094284Z","shell.execute_reply":"2023-08-31T16:03:57.991912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = model.predict(x_val)\npreds = [np.argmax(i) for i in pred]\ntest_vals = [np.argmax(i) for i in y_val]\nfrom sklearn.metrics import classification_report\nprint(classification_report(test_vals , preds))","metadata":{"execution":{"iopub.status.busy":"2023-08-31T16:03:57.994636Z","iopub.execute_input":"2023-08-31T16:03:57.995017Z","iopub.status.idle":"2023-08-31T16:03:58.969855Z","shell.execute_reply.started":"2023-08-31T16:03:57.994982Z","shell.execute_reply":"2023-08-31T16:03:58.968717Z"},"trusted":true},"execution_count":null,"outputs":[]}],"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}}