{"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":"2023-05-31T14:36:48.309799Z","iopub.execute_input":"2023-05-31T14:36:48.310183Z","iopub.status.idle":"2023-05-31T14:36:53.167445Z","shell.execute_reply.started":"2023-05-31T14:36:48.310154Z","shell.execute_reply":"2023-05-31T14:36:53.166194Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install virtualenv\n\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n!virtualenv myenv\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!source myenv/bin/activate","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sys\n\nprint(sys.version)","metadata":{"execution":{"iopub.status.busy":"2023-05-31T14:37:33.583187Z","iopub.execute_input":"2023-05-31T14:37:33.583568Z","iopub.status.idle":"2023-05-31T14:37:33.588533Z","shell.execute_reply.started":"2023-05-31T14:37:33.583523Z","shell.execute_reply":"2023-05-31T14:37:33.587516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install --upgrade tensorflow keras protobuf tensorflow-serving-api","metadata":{"execution":{"iopub.status.busy":"2023-05-31T12:30:55.851414Z","iopub.execute_input":"2023-05-31T12:30:55.851845Z","iopub.status.idle":"2023-05-31T12:31:07.858993Z","shell.execute_reply.started":"2023-05-31T12:30:55.851816Z","shell.execute_reply":"2023-05-31T12:31:07.85764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install --upgrade tensorflow ","metadata":{"execution":{"iopub.status.busy":"2023-05-31T14:37:40.525867Z","iopub.execute_input":"2023-05-31T14:37:40.526228Z","iopub.status.idle":"2023-05-31T14:38:59.735307Z","shell.execute_reply.started":"2023-05-31T14:37:40.5262Z","shell.execute_reply":"2023-05-31T14:38:59.734048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf","metadata":{"execution":{"iopub.status.busy":"2023-05-31T12:31:39.142727Z","iopub.execute_input":"2023-05-31T12:31:39.143725Z","iopub.status.idle":"2023-05-31T12:31:43.837533Z","shell.execute_reply.started":"2023-05-31T12:31:39.143681Z","shell.execute_reply":"2023-05-31T12:31:43.836471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip freeze","metadata":{"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nimport numpy as np\nimport tensorflow as tf\n\n# Set the random seed for reproducibility\nseed = 42\nnp.random.seed(seed)\ntf.random.set_seed(seed)","metadata":{"execution":{"iopub.status.busy":"2023-05-31T12:31:51.604176Z","iopub.execute_input":"2023-05-31T12:31:51.604991Z","iopub.status.idle":"2023-05-31T12:31:51.611259Z","shell.execute_reply.started":"2023-05-31T12:31:51.60495Z","shell.execute_reply":"2023-05-31T12:31:51.610075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! pip install scipy","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%matplotlib inline\nfrom matplotlib import pyplot as plt\n#This is simply a linear stack of neural network layers, and it's perfect for the type of feed-forward CNN we're building in this tutorial.\nfrom keras.models import Sequential\n# These are the layers that are used in almost any neural network:\nfrom keras.layers import Dense, Dropout, Activation, Flatten\n#These are the convolutional layers that will help us efficiently train on image data:\nfrom keras.layers import Convolution2D, MaxPooling2D\n#helpful utilities\nfrom keras.utils import np_utils","metadata":{"execution":{"iopub.status.busy":"2023-05-31T12:34:29.210684Z","iopub.execute_input":"2023-05-31T12:34:29.211129Z","iopub.status.idle":"2023-05-31T12:34:29.219007Z","shell.execute_reply.started":"2023-05-31T12:34:29.211097Z","shell.execute_reply":"2023-05-31T12:34:29.217789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip uninstall tensorflow","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install tensorflow","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import json\nimport math\nimport os\n\nimport cv2\nfrom PIL import Image\n#from keras_efficientnet import *\nfrom keras import layers\n#from keras.applications.resnet50 import ResNet50, preprocess_input\n#from keras.applications import DenseNet121\nfrom keras.callbacks import Callback, ModelCheckpoint,EarlyStopping\nfrom keras.preprocessing.image import ImageDataGenerator\n#from keras.models import Sequential\nfrom keras.optimizers import Adam\nimport matplotlib.pyplot as plt\nimport pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import cohen_kappa_score, accuracy_score\nimport scipy\nfrom tqdm import tqdm\nprint(os.listdir('../input'))\n%matplotlib inline\n\nIMG_SIZE=256\nBATCH_SIZE=16","metadata":{"execution":{"iopub.status.busy":"2023-05-31T12:34:35.702633Z","iopub.execute_input":"2023-05-31T12:34:35.703753Z","iopub.status.idle":"2023-05-31T12:34:36.576331Z","shell.execute_reply.started":"2023-05-31T12:34:35.703707Z","shell.execute_reply":"2023-05-31T12:34:36.575459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv('../input/aptos2019-blindness-detection/train.csv')\ntest_df = pd.read_csv('../input/aptos2019-blindness-detection/test.csv')","metadata":{"execution":{"iopub.status.busy":"2023-05-31T12:34:43.363822Z","iopub.execute_input":"2023-05-31T12:34:43.364218Z","iopub.status.idle":"2023-05-31T12:34:43.400955Z","shell.execute_reply.started":"2023-05-31T12:34:43.364189Z","shell.execute_reply":"2023-05-31T12:34:43.399987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-31T12:35:01.345854Z","iopub.execute_input":"2023-05-31T12:35:01.34628Z","iopub.status.idle":"2023-05-31T12:35:01.378731Z","shell.execute_reply.started":"2023-05-31T12:35:01.346248Z","shell.execute_reply":"2023-05-31T12:35:01.377678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ntrain_df['diagnosis'].value_counts()\n\n","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2023-05-31T12:35:09.885465Z","iopub.execute_input":"2023-05-31T12:35:09.88589Z","iopub.status.idle":"2023-05-31T12:35:09.902186Z","shell.execute_reply.started":"2023-05-31T12:35:09.885853Z","shell.execute_reply":"2023-05-31T12:35:09.90091Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['diagnosis'].hist()\ntrain_df['diagnosis'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-05-31T12:35:15.190309Z","iopub.execute_input":"2023-05-31T12:35:15.190983Z","iopub.status.idle":"2023-05-31T12:35:15.537897Z","shell.execute_reply.started":"2023-05-31T12:35:15.190935Z","shell.execute_reply":"2023-05-31T12:35:15.536647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def display_samples(df, columns=4, rows=3):\n    fig=plt.figure(figsize=(5*columns, 4*rows))\n\n    for i in range(columns*rows):\n        image_path = df.loc[i,'id_code']\n        image_id = df.loc[i,'diagnosis']\n        img = cv2.imread(f'../input/aptos2019-blindness-detection/train_images/{image_path}.png')\n        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n        \n        fig.add_subplot(rows, columns, i+1)\n        plt.title(image_id)\n        plt.axis('off')\n        plt.imshow(img)\n    \n    plt.tight_layout()\n\ndisplay_samples(train_df)","metadata":{"execution":{"iopub.status.busy":"2023-05-31T12:35:21.800616Z","iopub.execute_input":"2023-05-31T12:35:21.801013Z","iopub.status.idle":"2023-05-31T12:35:38.021474Z","shell.execute_reply.started":"2023-05-31T12:35:21.800983Z","shell.execute_reply":"2023-05-31T12:35:38.019712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def crop_image_from_gray(img,tol=7):\n    if img.ndim ==2:\n        mask = img>tol\n        return img[np.ix_(mask.any(1),mask.any(0))]\n    elif img.ndim==3:\n        gray_img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)\n        mask = gray_img>tol\n        \n        check_shape = img[:,:,0][np.ix_(mask.any(1),mask.any(0))].shape[0]\n        if (check_shape == 0): # image is too dark so that we crop out everything,\n            return img # return original image\n        else:\n            img1=img[:,:,0][np.ix_(mask.any(1),mask.any(0))]\n            img2=img[:,:,1][np.ix_(mask.any(1),mask.any(0))]\n            img3=img[:,:,2][np.ix_(mask.any(1),mask.any(0))]\n    #         print(img1.shape,img2.shape,img3.shape)\n            img = np.stack([img1,img2,img3],axis=-1)\n    #         print(img.shape)\n        return img\n    def preprocess_image(path, sigmaX=10):\n        image = cv2.imread(path)\n        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n        image = crop_image_from_gray(image)\n        image = cv2.resize(image, (IMG_SIZE, IMG_SIZE))\n        #     image=cv2.addWeighted ( image,4, cv2.GaussianBlur( image , (0,0) , sigmaX) ,-4 ,128)\n        image=CLAHEgreen(image)\n        \n    return image\n\ndef CLAHEgreen(image):\n    green=image[:, :, 1]\n    clipLimit = 2.0\n    tileGridSize = (8,8)\n    clahe=cv2.createCLAHE(clipLimit = clipLimit, tileGridSize = tileGridSize)\n    cla=clahe.apply(green)\n#     cla=clahe.apply(cla)\n    img=cv2.merge((cla,cla,cla))\n    \n    return img","metadata":{"execution":{"iopub.status.busy":"2023-05-31T12:39:13.829855Z","iopub.execute_input":"2023-05-31T12:39:13.83035Z","iopub.status.idle":"2023-05-31T12:39:13.842606Z","shell.execute_reply.started":"2023-05-31T12:39:13.830312Z","shell.execute_reply":"2023-05-31T12:39:13.841362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_histograms(df,columns=4, rows=3):\n    ax, fig=plt.subplots(columns*rows,figsize=(5*columns, 4*rows))\n\n    for i in range(columns*rows):\n        image_path = df.loc[i,'id_code']\n        image_id = df.loc[i,'diagnosis']\n        plt.subplot(columns, rows, i+1)\n        img = cv2.imread(f'../kaggle/input/aptos2019-blindness-detection/train_images.png')\n        plt.hist(img.flatten(),256,[0,256],color='r')\n#         fig.add_subplot(rows, columns, i+1)\n        plt.title(image_id)\n#         plt.axis('off')\n#         plt.imshow(img)\n    \n    plt.tight_layout()    ","metadata":{"execution":{"iopub.status.busy":"2023-05-31T12:45:49.957845Z","iopub.execute_input":"2023-05-31T12:45:49.958317Z","iopub.status.idle":"2023-05-31T12:45:49.965615Z","shell.execute_reply.started":"2023-05-31T12:45:49.958268Z","shell.execute_reply":"2023-05-31T12:45:49.964691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"get_histograms(train_df)","metadata":{"execution":{"iopub.status.busy":"2023-05-31T12:39:28.325735Z","iopub.execute_input":"2023-05-31T12:39:28.327052Z","iopub.status.idle":"2023-05-31T12:39:41.067548Z","shell.execute_reply.started":"2023-05-31T12:39:28.327009Z","shell.execute_reply":"2023-05-31T12:39:41.066379Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_histograms_preprocess(df,columns=4, rows=3):\n    ax, fig=plt.subplots(columns*rows,figsize=(5*columns, 4*rows))\n\n    for i in range(columns*rows):\n        image_path = df.loc[i,'id_code']\n        image_id = df.loc[i,'diagnosis']\n        plt.subplot(columns, rows, i+1)\n        img = preprocess_image(f'../kaggle/input/aptos2019-blindness-detection/train_image')\n        plt.hist(img.flatten(),256,[0,256],color='r')\n#         fig.add_subplot(rows, columns, i+1)\n        plt.title(image_id)\n#         plt.axis('off')\n#         plt.imshow(img)\n    \n    plt.tight_layout()   ","metadata":{"execution":{"iopub.status.busy":"2023-05-31T12:52:33.968808Z","iopub.execute_input":"2023-05-31T12:52:33.969261Z","iopub.status.idle":"2023-05-31T12:52:33.976994Z","shell.execute_reply.started":"2023-05-31T12:52:33.969229Z","shell.execute_reply":"2023-05-31T12:52:33.97589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"get_histograms_preprocess(train_df)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def display_samples_gaussian(df, columns=4, rows=3):\n    fig=plt.figure(figsize=(5*columns, 4*rows))\n\n    for i in range(columns*rows):\n        image_path = df.loc[i,'id_code']\n        image_id = df.loc[i,'diagnosis']\n        img = preprocess_image(f'../kaggle/input/aptos2019-blindness-detection/train_images')\n        \n        fig.add_subplot(rows, columns, i+1)\n        plt.title(image_id)\n        plt.axis('off')\n        plt.imshow(img)\n    \n    plt.tight_layout()\n    \n#display_samples_gaussian(train_df)\n\n","metadata":{"execution":{"iopub.status.busy":"2023-05-31T13:17:16.619681Z","iopub.execute_input":"2023-05-31T13:17:16.620083Z","iopub.status.idle":"2023-05-31T13:17:16.628204Z","shell.execute_reply.started":"2023-05-31T13:17:16.620052Z","shell.execute_reply":"2023-05-31T13:17:16.626697Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"N = train_df.shape[0]\nx_train = np.empty((N, IMG_SIZE, IMG_SIZE, 3), dtype=np.uint8)\n\nfor i, image_id in enumerate(tqdm(train_df['id_code'])):\n    x_train[i, :, :, :] = preprocess_image(\n        f'../kaggle/input/aptos2019-blindness-detection/train_images'\n    )","metadata":{"execution":{"iopub.status.busy":"2023-05-31T13:17:21.146273Z","iopub.execute_input":"2023-05-31T13:17:21.146713Z","iopub.status.idle":"2023-05-31T13:17:21.176688Z","shell.execute_reply.started":"2023-05-31T13:17:21.146677Z","shell.execute_reply":"2023-05-31T13:17:21.17507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train = pd.get_dummies(train_df['diagnosis']).values\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(y_train.shape)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train_multi = np.empty(y_train.shape, dtype=y_train.dtype)\ny_train_multi[:, 4] = y_train[:, 4]\n\nfor i in range(3, -1, -1):\n    y_train_multi[:, i] = np.logical_or(y_train[:, i], y_train_multi[:, i+1])\n\nprint(\"Original y_train:\", y_train.sum(axis=0))\nprint(\"Multilabel version:\", y_train_multi.sum(axis=0))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train, x_val, y_train, y_val = train_test_split(\n    x_train, y_train_multi, \n    test_size=0.15, \n    random_state=2019\n)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_val=x_val/255","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['diagnosis']=train_df['diagnosis'].astype(str)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"datagen =  ImageDataGenerator(\n        zoom_range=0.6,  # set range for random zoom, changed from 0.15 to 0.3, now changed from 0.3 to 0.45, from 0.45 to 0.6\n        # set mode for filling points outside the input boundaries\n        fill_mode='constant',\n        cval=0.,  # value used for fill_mode = \"constant\"\n        horizontal_flip=True,  # randomly flip images\n        vertical_flip=True,# randomly flip images\n        rotation_range=360,\n        width_shift_range=0.1,\n        height_shift_range=0.1,\n        rescale=1./255\n    )","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_generator = datagen.flow(x_train, y_train, batch_size=BATCH_SIZE, seed=2019)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"true_labels = np.array([1, 0, 1, 1, 0, 1])\npred_labels = np.array([1, 0, 0, 0, 0, 1])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy_score(true_labels, pred_labels)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cohen_kappa_score(true_labels, pred_labels)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class Metrics(Callback):\n    def on_train_begin(self, logs={}):\n        self.val_kappas = []\n\n    def on_epoch_end(self, epoch, logs={}):\n\n        X_val, y_val = self.validation_data[:2]\n        y_val = y_val.sum(axis=1) - 1\n        \n        y_pred = self.model.predict(X_val) > 0.5\n        y_pred = y_pred.astype(int).sum(axis=1) - 1\n        \n        _val_kappa = cohen_kappa_score(\n            y_val,\n            y_pred, \n            weights='quadratic'\n        )\n\n        self.val_kappas.append(_val_kappa)\n\n        print(f\"val_kappa: {_val_kappa:.4f}\")\n        if _val_kappa == max(self.val_kappas):\n            print(\"Validation Kappa has improved. Saving model.\")\n            model.save_weights('model.h5')\n            model_json = model.to_json()\n            with open('model.json', \"w\") as json_file:\n                json_file.write(model_json)\n            json_file.close()\n\n        return\n        ","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! pip install keras\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"import tensorflow as tf","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow import keras ","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! pip install efficientnet","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install --upgrade efficientnet","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport sys\n# Repository source: https://github.com/qubvel/efficientnet\nsys.path.append(os.path.abspath('../input/efficientnet/efficientnet-master/efficientnet-master/'))\nfrom efficientnet import EfficientNetB5","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nimport keras\nfrom keras import initializers\nfrom keras import regularizers\nfrom keras import constraints\nfrom keras import backend as K\nfrom keras.activations import elu\nfrom keras.optimizers import Adam\nfrom keras.models import Sequential\n#from keras.engine import Layer, InputSpec\n#from keras.utils.generic_utils import get_custom_objects\nfrom keras.callbacks import Callback, EarlyStopping, ReduceLROnPlateau\nfrom keras.layers import Dense, Conv2D, Flatten, GlobalAveragePooling2D, Dropout\nfrom keras.preprocessing.image import ImageDataGenerator\nfrom sklearn.metrics import cohen_kappa_score","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tf.keras.appliciations import EfficientNetB5","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! pip3 install tf-nightly","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import json\nimport math\nimport os\n\nimport cv2\nfrom PIL import Image\nimport numpy as np\nfrom keras import layers\nfrom keras.applications import DenseNet121\nfrom keras.callbacks import Callback, ModelCheckpoint\nfrom keras.preprocessing.image import ImageDataGenerator\nfrom keras.models import Sequential\nfrom keras.optimizers import Adam\nimport matplotlib.pyplot as plt\nimport pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import cohen_kappa_score, accuracy_score\nimport scipy\nimport tensorflow as tf\nfrom tqdm import tqdm\nfrom keras.applications.densenet import DenseNet121\nimport seaborn as sns\nsns.set()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! pip3 install EfficientNet","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"eff=efficient.load_weights('../input/efficientnet-keras-weights-b0b5/efficientnet-b5_imagenet_1000_notop.h5')\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from EfficeintNet import EfficientNetB5\nefficient = EfficientNetB5(\n    weights=None,\n    include_top=False,\n    input_shape=(IMG_SIZE,IMG_SIZE,3)\n)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def build_model():\n    model = Sequential()\n    model.add(efficient)\n    model.add(layers.GlobalAveragePooling2D())\n    model.add(layers.Dropout(0.5))\n    model.add(layers.Dense(5, activation='sigmoid'))\n    \n    \n    model.compile(\n        loss='binary_crossentropy',\n        optimizer=Adam(lr=0.00005),\n        metrics=['accuracy']\n    )\n    \n    return model","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = build_model()\nmodel.summary()","metadata":{},"execution_count":null,"outputs":[]}]}