{"metadata":{"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"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install stegano","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-01-25T05:52:03.943196Z","iopub.execute_input":"2023-01-25T05:52:03.943637Z","iopub.status.idle":"2023-01-25T05:52:21.912416Z","shell.execute_reply.started":"2023-01-25T05:52:03.943600Z","shell.execute_reply":"2023-01-25T05:52:21.911392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nfrom stegano import lsb #USED FOR PNG IMAGE\nimport skimage.io as sk\nimport matplotlib.pyplot as plt\nfrom scipy import spatial\nfrom tqdm import tqdm\n\nfrom PIL import Image\nfrom random import shuffle\n\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)","metadata":{"execution":{"iopub.status.busy":"2023-01-25T05:52:21.915176Z","iopub.execute_input":"2023-01-25T05:52:21.915734Z","iopub.status.idle":"2023-01-25T05:52:22.441285Z","shell.execute_reply.started":"2023-01-25T05:52:21.915677Z","shell.execute_reply":"2023-01-25T05:52:22.440341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BASE_PATH = \"/kaggle/input/alaska2-image-steganalysis\"\ntrain_imageids = pd.Series(os.listdir(BASE_PATH + '/Cover')).sort_values(ascending=True).reset_index(drop=True)\ntest_imageids = pd.Series(os.listdir(BASE_PATH + '/Test')).sort_values(ascending=True).reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2023-01-25T05:52:22.442379Z","iopub.execute_input":"2023-01-25T05:52:22.443284Z","iopub.status.idle":"2023-01-25T05:52:23.624439Z","shell.execute_reply.started":"2023-01-25T05:52:22.443225Z","shell.execute_reply":"2023-01-25T05:52:23.622974Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cover_images_path = pd.Series(BASE_PATH + '/Cover/' + train_imageids ).sort_values(ascending=True)\nJMIPOD_images_path = pd.Series(BASE_PATH + '/JMiPOD/'+train_imageids).sort_values(ascending=True)\nJUNIWARD_images_path = pd.Series(BASE_PATH + '/JUNIWARD/'+train_imageids).sort_values(ascending=True)\nUERD_images_path = pd.Series(BASE_PATH + '/UERD/'+train_imageids).sort_values(ascending=True)\ntest_images_path = pd.Series(BASE_PATH + '/Test/'+test_imageids).sort_values(ascending=True)\nss = pd.read_csv(f'{BASE_PATH}/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2023-01-25T05:52:23.627449Z","iopub.execute_input":"2023-01-25T05:52:23.628393Z","iopub.status.idle":"2023-01-25T05:52:23.879539Z","shell.execute_reply.started":"2023-01-25T05:52:23.628338Z","shell.execute_reply":"2023-01-25T05:52:23.878416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(nrows=2, ncols=2, figsize=(30, 15))\nk=0\nfor i, row in enumerate(ax):\n    for j, col in enumerate(row):\n        img = sk.imread(cover_images_path[k])\n        col.imshow(img)\n        col.set_title(cover_images_path[k])\n        k=k+1\nplt.suptitle('Samples from Cover Images', fontsize=14)\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-01-25T05:52:23.880855Z","iopub.execute_input":"2023-01-25T05:52:23.881757Z","iopub.status.idle":"2023-01-25T05:52:25.391330Z","shell.execute_reply.started":"2023-01-25T05:52:23.881692Z","shell.execute_reply":"2023-01-25T05:52:25.390287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(nrows=3, ncols=4, figsize=(30, 15))\nfor i in range(3):\n    '''\n    If you want to print more images just change the values in range and ncols in subplot\n    \n    '''\n    cvimg = sk.imread(cover_images_path[i])\n    uniimg = sk.imread(JUNIWARD_images_path[i])\n    jpodimg = sk.imread(JMIPOD_images_path[i])\n    uerdimg = sk.imread(UERD_images_path[i])\n    \n    ax[i,0].imshow(cvimg)\n    ax[i,0].set_title('Cover_IMG'+train_imageids[i])\n    ax[i,1].imshow(uniimg)\n    ax[i,1].set_title('JNIWARD_IMG'+train_imageids[i])\n    ax[i,2].imshow(jpodimg)\n    ax[i,2].set_title('JMiPOD_IMG'+train_imageids[i])\n    ax[i,3].imshow(uerdimg)\n    ax[i,3].set_title('UERD_IMG'+train_imageids[i])","metadata":{"execution":{"iopub.status.busy":"2023-01-25T05:52:25.392894Z","iopub.execute_input":"2023-01-25T05:52:25.393576Z","iopub.status.idle":"2023-01-25T05:52:28.296457Z","shell.execute_reply.started":"2023-01-25T05:52:25.393537Z","shell.execute_reply":"2023-01-25T05:52:28.293206Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_cover = sk.imread(cover_images_path[0])\nimg_jmipod = sk.imread(JMIPOD_images_path[0])\nimg_juniward = sk.imread(JUNIWARD_images_path[0])\nimg_uerd = sk.imread(UERD_images_path[0])\n\n\nfig, ax = plt.subplots(nrows=3, ncols=4, figsize=(16, 12))\nax[0,0].imshow(img_jmipod)\nax[0,1].imshow((img_cover == img_jmipod).astype(int)[:,:,0])\nax[0,1].set_title(f'{train_imageids[k]} Channel 0')\n\nax[0,2].imshow((img_cover == img_jmipod).astype(int)[:,:,1])\nax[0,2].set_title(f'{train_imageids[k]} Channel 1')\nax[0,3].imshow((img_cover == img_jmipod).astype(int)[:,:,2])\nax[0,3].set_title(f'{train_imageids[k]} Channel 2')\nax[0,0].set_ylabel('JMiPOD', rotation=90, size='large')\n\n\nax[1,0].imshow(img_juniward)\nax[1,1].imshow((img_cover == img_juniward).astype(int)[:,:,0])\nax[1,2].imshow((img_cover == img_juniward).astype(int)[:,:,1])\nax[1,3].imshow((img_cover == img_juniward).astype(int)[:,:,2])\nax[1,0].set_ylabel('JUNIWARD', rotation=90, size='large')\n\nax[2,0].imshow(img_uerd)\nax[2,1].imshow((img_cover == img_uerd).astype(int)[:,:,0])\nax[2,2].imshow((img_cover == img_uerd).astype(int)[:,:,1])\nax[2,3].imshow((img_cover == img_uerd).astype(int)[:,:,2])\nax[2,0].set_ylabel('UERD', rotation=90, size='large')\n\nplt.suptitle('Pixel Deviation from Cover Image', fontsize=14)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-25T05:52:28.298347Z","iopub.execute_input":"2023-01-25T05:52:28.298823Z","iopub.status.idle":"2023-01-25T05:52:30.359031Z","shell.execute_reply.started":"2023-01-25T05:52:28.298782Z","shell.execute_reply":"2023-01-25T05:52:30.357564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig,ax = plt.subplots(3,4,figsize=(20,12))\n\nfor i,paths in enumerate(cover_images_path[:3]):\n    image = Image.open(paths)\n    ycbcr = image.convert('YCbCr')\n    (y, cb, cr) = ycbcr.split()\n\n    ax[i,0].imshow(image)\n    ax[i,0].set_title('Cover'+train_imageids[i])\n    ax[i,1].imshow(y)\n    ax[i,1].set_title('Luminance')\n    ax[i,2].imshow(cb)\n    ax[i,2].set_title('Cb:Chroma Blue')\n    ax[i,3].imshow(cr)\n    ax[i,3].set_title('Cr:Chroma Red')","metadata":{"execution":{"iopub.status.busy":"2023-01-25T05:52:30.361209Z","iopub.execute_input":"2023-01-25T05:52:30.361571Z","iopub.status.idle":"2023-01-25T05:52:32.931914Z","shell.execute_reply.started":"2023-01-25T05:52:30.361541Z","shell.execute_reply":"2023-01-25T05:52:32.930681Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig,ax = plt.subplots(4,4,figsize=(20,16))\nplt.tight_layout()\n\n\nim1 = Image.open(cover_images_path[0])\nim2 = Image.open(JUNIWARD_images_path[0])\nim3 = Image.open(JMIPOD_images_path[0])\nim4 = Image.open(UERD_images_path[0])\n\nfor i,image in enumerate([im1,im2,im3,im4]):\n    ycbcr = image.convert('YCbCr')\n    (y, cb, cr) = ycbcr.split()\n\n    ax[i,0].imshow(image)\n    ax[i,0].set_title('Image')\n    ax[i,1].imshow(y)\n    ax[i,1].set_title('Luminance')\n    ax[i,2].imshow(cb)\n    ax[i,2].set_title('Cb:Chroma Blue')\n    ax[i,3].imshow(cr)\n    ax[i,3].set_title('Cr:Chroma Red')\n","metadata":{"execution":{"iopub.status.busy":"2023-01-25T05:52:32.933336Z","iopub.execute_input":"2023-01-25T05:52:32.933696Z","iopub.status.idle":"2023-01-25T05:52:37.200407Z","shell.execute_reply.started":"2023-01-25T05:52:32.933664Z","shell.execute_reply":"2023-01-25T05:52:37.199147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! git clone https://github.com/dwgoon/jpegio","metadata":{"execution":{"iopub.status.busy":"2023-01-25T05:52:37.205323Z","iopub.execute_input":"2023-01-25T05:52:37.206068Z","iopub.status.idle":"2023-01-25T05:52:49.054835Z","shell.execute_reply.started":"2023-01-25T05:52:37.206021Z","shell.execute_reply":"2023-01-25T05:52:49.052873Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install jpegio/.\nimport jpegio as jio","metadata":{"execution":{"iopub.status.busy":"2023-01-25T05:52:49.057281Z","iopub.execute_input":"2023-01-25T05:52:49.057835Z","iopub.status.idle":"2023-01-25T05:53:32.899374Z","shell.execute_reply.started":"2023-01-25T05:52:49.057787Z","shell.execute_reply":"2023-01-25T05:53:32.897804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nfig,ax = plt.subplots(4,4,figsize=(20,16))\nplt.tight_layout()\n\nfor i,path in enumerate([cover_images_path[0],JUNIWARD_images_path[0],JMIPOD_images_path[0],UERD_images_path[0]]):\n    \n    image = Image.open(path)\n    jpeg = jio.read(path)\n    DCT_Y = jpeg.coef_arrays[0]\n    DCT_Cr = jpeg.coef_arrays[1]\n    DCT_Cb = jpeg.coef_arrays[2]\n    \n    \n    ax[i,0].imshow(image)\n    ax[i,0].set_title('Image')\n    ax[i,1].imshow(DCT_Y)\n    ax[i,1].set_title('Luminance')\n    ax[i,2].imshow(DCT_Cb)\n    ax[i,2].set_title('Cb:Chroma Blue')\n    ax[i,3].imshow(DCT_Cr)\n    ax[i,3].set_title('Cr:Chroma Red')","metadata":{"execution":{"iopub.status.busy":"2023-01-25T05:53:32.901620Z","iopub.execute_input":"2023-01-25T05:53:32.902595Z","iopub.status.idle":"2023-01-25T05:53:36.691761Z","shell.execute_reply.started":"2023-01-25T05:53:32.902534Z","shell.execute_reply":"2023-01-25T05:53:36.690414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"coverDCT = np.zeros([512,512,3])\nstegoDCT = np.zeros([512,512,3])\njpeg = jio.read(cover_images_path[0])\nstego_juni = jio.read(JUNIWARD_images_path[0])","metadata":{"execution":{"iopub.status.busy":"2023-01-25T05:53:36.693620Z","iopub.execute_input":"2023-01-25T05:53:36.694035Z","iopub.status.idle":"2023-01-25T05:53:36.746046Z","shell.execute_reply.started":"2023-01-25T05:53:36.693999Z","shell.execute_reply":"2023-01-25T05:53:36.745037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final=[]\ndef create_labels(cover,jmipod,juniward,uerd,image_id):\n    image = sk.imread(cover)\n    jmipodimg = sk.imread(jmipod)\n    juniward = sk.imread(juniward)\n    uerd = sk.imread(uerd)\n    \n    vec1 = np.reshape(image,(512*512*3))\n    vec2 = np.reshape(jmipodimg,(512*512*3))\n    vec3 = np.reshape(juniward,(512*512*3))\n    vec4 = np.reshape(uerd,(512*512*3))\n    \n    cos1 = spatial.distance.cosine(vec1,vec2)\n    cos2 = spatial.distance.cosine(vec1,vec3)\n    cos3 = spatial.distance.cosine(vec1,vec4)\n    \n    final.append({'image_id':image_id,'jmipod':cos1,'juniward':cos2,'uerd':cos3})","metadata":{"execution":{"iopub.status.busy":"2023-01-25T05:53:36.747707Z","iopub.execute_input":"2023-01-25T05:53:36.748614Z","iopub.status.idle":"2023-01-25T05:53:36.759412Z","shell.execute_reply.started":"2023-01-25T05:53:36.748562Z","shell.execute_reply":"2023-01-25T05:53:36.758341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport os\nimport skimage.io as sk\nimport matplotlib.pyplot as plt\nfrom scipy import spatial\nfrom tqdm import tqdm\nfrom PIL import Image\nfrom random import shuffle","metadata":{"execution":{"iopub.status.busy":"2023-01-25T05:53:36.761243Z","iopub.execute_input":"2023-01-25T05:53:36.761595Z","iopub.status.idle":"2023-01-25T05:53:36.779988Z","shell.execute_reply.started":"2023-01-25T05:53:36.761565Z","shell.execute_reply":"2023-01-25T05:53:36.778618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BASE_PATH = \"/kaggle/input/alaska2-image-steganalysis\"\ntrain_imageids = pd.Series(os.listdir(BASE_PATH + '/Cover')).sort_values(ascending=True).reset_index(drop=True)\ntest_imageids = pd.Series(os.listdir(BASE_PATH + '/Test')).sort_values(ascending=True).reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2023-01-25T05:53:36.781698Z","iopub.execute_input":"2023-01-25T05:53:36.782137Z","iopub.status.idle":"2023-01-25T05:53:36.922964Z","shell.execute_reply.started":"2023-01-25T05:53:36.782101Z","shell.execute_reply":"2023-01-25T05:53:36.921623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cover_images_path = pd.Series(BASE_PATH + '/Cover/' + train_imageids ).sort_values(ascending=True)\nJMIPOD_images_path = pd.Series(BASE_PATH + '/JMiPOD/'+train_imageids).sort_values(ascending=True)\nJUNIWARD_images_path = pd.Series(BASE_PATH + '/JUNIWARD/'+train_imageids).sort_values(ascending=True)\nUERD_images_path = pd.Series(BASE_PATH + '/UERD/'+train_imageids).sort_values(ascending=True)\ntest_images_path = pd.Series(BASE_PATH + '/Test/'+test_imageids).sort_values(ascending=True)\nss = pd.read_csv(f'{BASE_PATH}/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2023-01-25T05:53:36.924696Z","iopub.execute_input":"2023-01-25T05:53:36.925128Z","iopub.status.idle":"2023-01-25T05:53:37.193336Z","shell.execute_reply.started":"2023-01-25T05:53:36.925090Z","shell.execute_reply":"2023-01-25T05:53:37.192282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for k in tqdm(range(30000)):\n    create_labels(cover_images_path[k],JMIPOD_images_path[k],JUNIWARD_images_path[k],UERD_images_path[k],train_imageids[k])","metadata":{"execution":{"iopub.status.busy":"2023-01-25T05:53:37.195049Z","iopub.execute_input":"2023-01-25T05:53:37.196273Z","iopub.status.idle":"2023-01-25T06:28:30.581826Z","shell.execute_reply.started":"2023-01-25T05:53:37.196221Z","shell.execute_reply":"2023-01-25T06:28:30.577986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_temp = pd.DataFrame(final)\ntrain_temp.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-25T06:28:30.589666Z","iopub.execute_input":"2023-01-25T06:28:30.590390Z","iopub.status.idle":"2023-01-25T06:28:30.703102Z","shell.execute_reply.started":"2023-01-25T06:28:30.590307Z","shell.execute_reply":"2023-01-25T06:28:30.701753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def sigmoid(X):\n   return 1/(1+np.exp(-X))","metadata":{"execution":{"iopub.status.busy":"2023-01-25T06:28:30.705134Z","iopub.execute_input":"2023-01-25T06:28:30.705512Z","iopub.status.idle":"2023-01-25T06:28:30.718661Z","shell.execute_reply.started":"2023-01-25T06:28:30.705479Z","shell.execute_reply":"2023-01-25T06:28:30.716424Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_temp['jmipod'] = train_temp['jmipod'].apply(lambda x:sigmoid(x))\ntrain_temp['juniward'] = train_temp['juniward'].apply(lambda x:sigmoid(x))\ntrain_temp['uerd'] = train_temp['uerd'].apply(lambda x:sigmoid(x))","metadata":{"execution":{"iopub.status.busy":"2023-01-25T06:28:30.722126Z","iopub.execute_input":"2023-01-25T06:28:30.722627Z","iopub.status.idle":"2023-01-25T06:28:30.918538Z","shell.execute_reply.started":"2023-01-25T06:28:30.722574Z","shell.execute_reply":"2023-01-25T06:28:30.916550Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_temp.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-25T06:28:30.920398Z","iopub.execute_input":"2023-01-25T06:28:30.920824Z","iopub.status.idle":"2023-01-25T06:28:30.938933Z","shell.execute_reply.started":"2023-01-25T06:28:30.920786Z","shell.execute_reply":"2023-01-25T06:28:30.937228Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"IMG_SIZE = 300\ndef load_training_data():\n  train_data = []\n  data_paths = [cover_images_path,JUNIWARD_images_path,JMIPOD_images_path,UERD_images_path]\n  labels = [np.zeros(train_temp.shape[0]),train_temp['juniward'],train_temp['jmipod'],train_temp['uerd']]\n  for i,image_path in enumerate(data_paths):\n    for j,img in enumerate(image_path[:10000]):\n        label = labels[i][j]\n        img = Image.open(img)\n        img = img.convert('L')\n        img = img.resize((IMG_SIZE, IMG_SIZE), Image.ANTIALIAS)\n        train_data.append([np.array(img), label])\n        \n  shuffle(train_data)\n  return train_data","metadata":{"execution":{"iopub.status.busy":"2023-01-25T06:28:30.941223Z","iopub.execute_input":"2023-01-25T06:28:30.941637Z","iopub.status.idle":"2023-01-25T06:28:30.953738Z","shell.execute_reply.started":"2023-01-25T06:28:30.941603Z","shell.execute_reply":"2023-01-25T06:28:30.952543Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_test_data():\n    test_data = []\n    for img in test_images_path:\n        img = Image.open(img)\n        img = img.convert('L')\n        img = img.resize((IMG_SIZE, IMG_SIZE), Image.ANTIALIAS)\n        test_data.append([np.array(img)])\n            \n    return test_data\n","metadata":{"execution":{"iopub.status.busy":"2023-01-25T06:28:30.956016Z","iopub.execute_input":"2023-01-25T06:28:30.956450Z","iopub.status.idle":"2023-01-25T06:28:30.967644Z","shell.execute_reply.started":"2023-01-25T06:28:30.956414Z","shell.execute_reply":"2023-01-25T06:28:30.966565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\ntrain = load_training_data()","metadata":{"execution":{"iopub.status.busy":"2023-01-25T06:28:30.969686Z","iopub.execute_input":"2023-01-25T06:28:30.972373Z","iopub.status.idle":"2023-01-25T06:39:44.981209Z","shell.execute_reply.started":"2023-01-25T06:28:30.972226Z","shell.execute_reply":"2023-01-25T06:39:44.980149Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train)","metadata":{"execution":{"iopub.status.busy":"2023-01-25T06:39:44.982999Z","iopub.execute_input":"2023-01-25T06:39:44.984325Z","iopub.status.idle":"2023-01-25T06:39:44.994825Z","shell.execute_reply.started":"2023-01-25T06:39:44.984269Z","shell.execute_reply":"2023-01-25T06:39:44.993277Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(train[115][0], cmap = 'gist_gray')","metadata":{"execution":{"iopub.status.busy":"2023-01-25T06:39:44.996956Z","iopub.execute_input":"2023-01-25T06:39:44.997407Z","iopub.status.idle":"2023-01-25T06:39:45.285541Z","shell.execute_reply.started":"2023-01-25T06:39:44.997367Z","shell.execute_reply":"2023-01-25T06:39:45.284182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainImages = np.array([i[0] for i in train]).reshape(-1, IMG_SIZE, IMG_SIZE, 1)\ntrainLabels = np.array([i[1] for i in train])\ntrainImages = np.array([i[0] for i in train]).reshape(-1, IMG_SIZE, IMG_SIZE, 1)\ntrainLabels = np.array([i[1] for i in train])","metadata":{"execution":{"iopub.status.busy":"2023-01-25T06:40:12.729500Z","iopub.execute_input":"2023-01-25T06:40:12.729996Z","iopub.status.idle":"2023-01-25T06:40:18.477529Z","shell.execute_reply.started":"2023-01-25T06:40:12.729955Z","shell.execute_reply":"2023-01-25T06:40:18.476256Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import keras\nfrom keras.models import Sequential\nfrom keras.layers import Dense, Dropout, Flatten\nfrom keras.layers import Conv2D, MaxPooling2D\nfrom tensorflow.keras.layers import BatchNormalization","metadata":{"execution":{"iopub.status.busy":"2023-01-25T06:43:23.255972Z","iopub.execute_input":"2023-01-25T06:43:23.260500Z","iopub.status.idle":"2023-01-25T06:43:24.135281Z","shell.execute_reply.started":"2023-01-25T06:43:23.260422Z","shell.execute_reply":"2023-01-25T06:43:24.130132Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential()\nmodel.add(Conv2D(32, kernel_size = (3, 3), activation='relu', input_shape=(IMG_SIZE, IMG_SIZE, 1)))\nmodel.add(MaxPooling2D(pool_size=(2,2)))\nmodel.add(BatchNormalization())\nmodel.add(Conv2D(64, kernel_size=(3,3), activation='relu'))\nmodel.add(MaxPooling2D(pool_size=(2,2)))\nmodel.add(BatchNormalization())\nmodel.add(Conv2D(64, kernel_size=(3,3), activation='relu'))\nmodel.add(MaxPooling2D(pool_size=(2,2)))\nmodel.add(BatchNormalization())\nmodel.add(Conv2D(96, kernel_size=(3,3), activation='relu'))\nmodel.add(MaxPooling2D(pool_size=(2,2)))\nmodel.add(BatchNormalization())\nmodel.add(Conv2D(32, kernel_size=(3,3), activation='relu'))\nmodel.add(MaxPooling2D(pool_size=(2,2)))\nmodel.add(BatchNormalization())\nmodel.add(Dropout(0.2))\nmodel.add(Flatten())\nmodel.add(Dense(128, activation='relu'))\nmodel.add(Dense(1))","metadata":{"execution":{"iopub.status.busy":"2023-01-25T06:43:32.204879Z","iopub.execute_input":"2023-01-25T06:43:32.206268Z","iopub.status.idle":"2023-01-25T06:43:32.382930Z","shell.execute_reply.started":"2023-01-25T06:43:32.206198Z","shell.execute_reply":"2023-01-25T06:43:32.381692Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(loss='mean_squared_error', optimizer='adam',metrics = ['mean_squared_error'])","metadata":{"execution":{"iopub.status.busy":"2023-01-25T06:43:34.653146Z","iopub.execute_input":"2023-01-25T06:43:34.654252Z","iopub.status.idle":"2023-01-25T06:43:34.672021Z","shell.execute_reply.started":"2023-01-25T06:43:34.654200Z","shell.execute_reply":"2023-01-25T06:43:34.670905Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(model.summary())","metadata":{"execution":{"iopub.status.busy":"2023-01-25T06:43:43.679217Z","iopub.execute_input":"2023-01-25T06:43:43.679610Z","iopub.status.idle":"2023-01-25T06:43:43.688773Z","shell.execute_reply.started":"2023-01-25T06:43:43.679578Z","shell.execute_reply":"2023-01-25T06:43:43.687277Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(trainImages, trainLabels, batch_size = 100, epochs = 3, verbose = 1)","metadata":{"execution":{"iopub.status.busy":"2023-01-25T06:44:02.340673Z","iopub.execute_input":"2023-01-25T06:44:02.341135Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\ntest = load_test_data()\ntestImages = np.array([i[0] for i in test]).reshape(-1, IMG_SIZE, IMG_SIZE, 1)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\npredict = model.predict(testImages,batch_size=100)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ss['Label'] = predict","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}