{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-08-30T17:08:42.481424Z","iopub.execute_input":"2021-08-30T17:08:42.481843Z","iopub.status.idle":"2021-08-30T17:08:43.088433Z","shell.execute_reply.started":"2021-08-30T17:08:42.481812Z","shell.execute_reply":"2021-08-30T17:08:43.070322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib as plt\nimport keras\nfrom keras.layers import Dense,Conv2D,MaxPool2D,Dropout,Flatten\nfrom keras.models import Sequential\nfrom keras.preprocessing import image\n\n","metadata":{"execution":{"iopub.status.busy":"2021-08-30T17:08:43.090435Z","iopub.execute_input":"2021-08-30T17:08:43.090878Z","iopub.status.idle":"2021-08-30T17:08:48.471797Z","shell.execute_reply.started":"2021-08-30T17:08:43.090835Z","shell.execute_reply":"2021-08-30T17:08:48.470366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_datagen=image.ImageDataGenerator(rescale=1/255,horizontal_flip=True,zoom_range=0.2,shear_range=0.2\n)\ntrain_data=train_datagen.flow_from_directory(directory='../input/csc532/datasets/datasets/train',target_size=(256,256),batch_size=1,class_mode='binary')","metadata":{"execution":{"iopub.status.busy":"2021-08-30T17:08:48.474214Z","iopub.execute_input":"2021-08-30T17:08:48.474676Z","iopub.status.idle":"2021-08-30T17:08:48.591596Z","shell.execute_reply.started":"2021-08-30T17:08:48.474619Z","shell.execute_reply":"2021-08-30T17:08:48.589238Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.class_indices","metadata":{"execution":{"iopub.status.busy":"2021-08-30T17:08:48.593868Z","iopub.execute_input":"2021-08-30T17:08:48.594285Z","iopub.status.idle":"2021-08-30T17:08:48.609540Z","shell.execute_reply.started":"2021-08-30T17:08:48.594233Z","shell.execute_reply":"2021-08-30T17:08:48.607892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_datagen=image.ImageDataGenerator(rescale=1/255,horizontal_flip=True,zoom_range=0.2,shear_range=0.2\n)\ntest_data=train_datagen.flow_from_directory(directory='../input/csc532/datasets/datasets/test',target_size=(256,256),batch_size=1,class_mode='binary')\ntrain_data.class_indices","metadata":{"execution":{"iopub.status.busy":"2021-08-30T17:08:48.611589Z","iopub.execute_input":"2021-08-30T17:08:48.612134Z","iopub.status.idle":"2021-08-30T17:08:48.740493Z","shell.execute_reply.started":"2021-08-30T17:08:48.612060Z","shell.execute_reply":"2021-08-30T17:08:48.739369Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model=Sequential()\nmodel.add(Conv2D(filters=32,kernel_size=(3,3),activation='relu',input_shape=(256,256,3)))\n\nmodel.add(Conv2D(filters=32,kernel_size=(3,3),activation='relu',input_shape=(256,256,3)))\nmodel.add(MaxPool2D())\nmodel.add(Dropout(rate=0.25))\n\nmodel.add(Conv2D(filters=32,kernel_size=(3,3),activation='relu',input_shape=(256,256,3)))\nmodel.add(MaxPool2D())\nmodel.add(Dropout(rate=0.25))\n\nmodel.add(Conv2D(filters=32,kernel_size=(3,3),activation='relu',input_shape=(256,256,3)))\nmodel.add(MaxPool2D())\nmodel.add(Dropout(rate=0.25))\n\nmodel.add(Flatten())\nmodel.add(Dense(units=64, activation='relu'))\nmodel.add(Dropout(rate=0.50))\nmodel.add(Dense(units=1,activation='sigmoid'))\n\nmodel.compile(loss=keras.losses.binary_crossentropy,optimizer=\"adam\",metrics=['acc']) \n","metadata":{"execution":{"iopub.status.busy":"2021-08-30T17:08:48.742355Z","iopub.execute_input":"2021-08-30T17:08:48.742858Z","iopub.status.idle":"2021-08-30T17:08:51.312369Z","shell.execute_reply.started":"2021-08-30T17:08:48.742813Z","shell.execute_reply":"2021-08-30T17:08:51.311282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2021-08-30T17:08:51.314034Z","iopub.execute_input":"2021-08-30T17:08:51.314467Z","iopub.status.idle":"2021-08-30T17:08:51.333093Z","shell.execute_reply.started":"2021-08-30T17:08:51.314427Z","shell.execute_reply":"2021-08-30T17:08:51.331806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit_generator(train_data,steps_per_epoch=8,epochs=10,validation_steps=2,validation_data=test_data)","metadata":{"execution":{"iopub.status.busy":"2021-08-30T17:08:51.335473Z","iopub.execute_input":"2021-08-30T17:08:51.335810Z","iopub.status.idle":"2021-08-30T17:09:06.255052Z","shell.execute_reply.started":"2021-08-30T17:08:51.335775Z","shell.execute_reply":"2021-08-30T17:09:06.253986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path=\"../input/csc532/datasets/datasets/test/positive/1-s2.0-S0140673620303706-fx1_lrg.jpg\"\nimg=image.load_img(path, target_size=(256,256))\nimg=image.img_to_array(img)/255\nimg=np.array([img])\nimg.shape","metadata":{"execution":{"iopub.status.busy":"2021-08-30T17:09:06.257191Z","iopub.execute_input":"2021-08-30T17:09:06.257676Z","iopub.status.idle":"2021-08-30T17:09:06.346458Z","shell.execute_reply.started":"2021-08-30T17:09:06.257625Z","shell.execute_reply":"2021-08-30T17:09:06.345237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.predict_classes(img)","metadata":{"execution":{"iopub.status.busy":"2021-08-30T17:09:34.750344Z","iopub.execute_input":"2021-08-30T17:09:34.750740Z","iopub.status.idle":"2021-08-30T17:09:34.926686Z","shell.execute_reply.started":"2021-08-30T17:09:34.750692Z","shell.execute_reply":"2021-08-30T17:09:34.925645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}