{"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\n'''\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n'''\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":"2022-03-02T18:02:50.036282Z","iopub.execute_input":"2022-03-02T18:02:50.036899Z","iopub.status.idle":"2022-03-02T18:02:50.046988Z","shell.execute_reply.started":"2022-03-02T18:02:50.036858Z","shell.execute_reply":"2022-03-02T18:02:50.045788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom tqdm import tqdm\nimport cv2\nimport random\n\nfrom sklearn.utils import shuffle\nfrom sklearn.preprocessing import LabelEncoder\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import classification_report, accuracy_score, precision_score, recall_score\nfrom imblearn.over_sampling import RandomOverSampler\n#from sklearn.metrics import accuracy_score\n\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Conv2D, MaxPool2D, Dropout, Dense, Flatten, BatchNormalization\nfrom tensorflow.keras.optimizers import SGD, Adam\nfrom tensorflow.keras.callbacks import EarlyStopping\nfrom tensorflow.keras.utils import to_categorical\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator","metadata":{"execution":{"iopub.status.busy":"2022-03-02T18:02:50.048505Z","iopub.execute_input":"2022-03-02T18:02:50.049261Z","iopub.status.idle":"2022-03-02T18:02:58.449323Z","shell.execute_reply.started":"2022-03-02T18:02:50.049217Z","shell.execute_reply":"2022-03-02T18:02:58.448374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = os.path.join(\"../input\", 'siim-isic-melanoma-classification')\nprint(path)","metadata":{"execution":{"iopub.status.busy":"2022-03-02T18:02:58.450731Z","iopub.execute_input":"2022-03-02T18:02:58.451067Z","iopub.status.idle":"2022-03-02T18:02:58.45714Z","shell.execute_reply.started":"2022-03-02T18:02:58.450951Z","shell.execute_reply":"2022-03-02T18:02:58.456023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.listdir(path)","metadata":{"execution":{"iopub.status.busy":"2022-03-02T18:02:58.460006Z","iopub.execute_input":"2022-03-02T18:02:58.46094Z","iopub.status.idle":"2022-03-02T18:02:58.482738Z","shell.execute_reply.started":"2022-03-02T18:02:58.460887Z","shell.execute_reply":"2022-03-02T18:02:58.481506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_csv('../input/siim-isic-melanoma-classification/train.csv')\ntrain_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-02T18:02:58.484271Z","iopub.execute_input":"2022-03-02T18:02:58.484703Z","iopub.status.idle":"2022-03-02T18:02:58.600136Z","shell.execute_reply.started":"2022-03-02T18:02:58.484669Z","shell.execute_reply":"2022-03-02T18:02:58.599004Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data = pd.read_csv('../input/siim-isic-melanoma-classification/test.csv')\ntest_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-02T18:02:58.601528Z","iopub.execute_input":"2022-03-02T18:02:58.602365Z","iopub.status.idle":"2022-03-02T18:02:58.640216Z","shell.execute_reply.started":"2022-03-02T18:02:58.602301Z","shell.execute_reply":"2022-03-02T18:02:58.639435Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = \"../input/siim-isic-melanoma-classification/\"\nos.listdir(path)","metadata":{"execution":{"iopub.status.busy":"2022-03-02T18:02:58.641469Z","iopub.execute_input":"2022-03-02T18:02:58.641883Z","iopub.status.idle":"2022-03-02T18:02:58.649199Z","shell.execute_reply.started":"2022-03-02T18:02:58.641851Z","shell.execute_reply":"2022-03-02T18:02:58.648338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = plt.imread(os.path.join(path, 'jpeg', 'train', train_data['image_name'][0] + '.jpg'))\nimg = cv2.resize(img, (128,128))\nplt.imshow(img)","metadata":{"execution":{"iopub.status.busy":"2022-03-02T18:02:58.650648Z","iopub.execute_input":"2022-03-02T18:02:58.6512Z","iopub.status.idle":"2022-03-02T18:02:59.458599Z","shell.execute_reply.started":"2022-03-02T18:02:58.651154Z","shell.execute_reply":"2022-03-02T18:02:59.45792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def image_extension(df) : \n    image_names = df[\"image_name\"].values\n    image_names = image_names + \".jpg\"\n    return image_names\n\n\n\nimage_names = image_extension(train_data)\nimage_names = image_extension(test_data)","metadata":{"execution":{"iopub.status.busy":"2022-03-02T18:02:59.459638Z","iopub.execute_input":"2022-03-02T18:02:59.460041Z","iopub.status.idle":"2022-03-02T18:02:59.474598Z","shell.execute_reply.started":"2022-03-02T18:02:59.459998Z","shell.execute_reply":"2022-03-02T18:02:59.473453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.info()","metadata":{"execution":{"iopub.status.busy":"2022-03-02T18:02:59.478875Z","iopub.execute_input":"2022-03-02T18:02:59.479193Z","iopub.status.idle":"2022-03-02T18:02:59.528599Z","shell.execute_reply.started":"2022-03-02T18:02:59.47916Z","shell.execute_reply":"2022-03-02T18:02:59.527261Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.info()","metadata":{"execution":{"iopub.status.busy":"2022-03-02T18:02:59.530278Z","iopub.execute_input":"2022-03-02T18:02:59.531017Z","iopub.status.idle":"2022-03-02T18:02:59.547582Z","shell.execute_reply.started":"2022-03-02T18:02:59.53098Z","shell.execute_reply":"2022-03-02T18:02:59.546775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['target'].value_counts ()","metadata":{"execution":{"iopub.status.busy":"2022-03-02T18:02:59.548818Z","iopub.execute_input":"2022-03-02T18:02:59.549484Z","iopub.status.idle":"2022-03-02T18:02:59.562971Z","shell.execute_reply.started":"2022-03-02T18:02:59.549442Z","shell.execute_reply":"2022-03-02T18:02:59.562102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['sex'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-03-02T18:02:59.564437Z","iopub.execute_input":"2022-03-02T18:02:59.565349Z","iopub.status.idle":"2022-03-02T18:02:59.582869Z","shell.execute_reply.started":"2022-03-02T18:02:59.565311Z","shell.execute_reply":"2022-03-02T18:02:59.582069Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['age_approx'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-03-02T18:02:59.584384Z","iopub.execute_input":"2022-03-02T18:02:59.585242Z","iopub.status.idle":"2022-03-02T18:02:59.597299Z","shell.execute_reply.started":"2022-03-02T18:02:59.585206Z","shell.execute_reply":"2022-03-02T18:02:59.596253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['anatom_site_general_challenge'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-03-02T18:02:59.598574Z","iopub.execute_input":"2022-03-02T18:02:59.59914Z","iopub.status.idle":"2022-03-02T18:02:59.61266Z","shell.execute_reply.started":"2022-03-02T18:02:59.599102Z","shell.execute_reply":"2022-03-02T18:02:59.611709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['sex'].value_counts ()","metadata":{"execution":{"iopub.status.busy":"2022-03-02T18:02:59.613747Z","iopub.execute_input":"2022-03-02T18:02:59.614532Z","iopub.status.idle":"2022-03-02T18:02:59.630141Z","shell.execute_reply.started":"2022-03-02T18:02:59.614495Z","shell.execute_reply":"2022-03-02T18:02:59.62914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# handling missing values in train dataset\ntrain_data['sex'] = train_data['sex'].fillna('unknown')\ntrain_data['age_approx'] = train_data['age_approx'].fillna(0)\ntrain_data['anatom_site_general_challenge'] = train_data['anatom_site_general_challenge'].fillna('unknown')\n\n# handling missing values in test dataset\ntest_data['sex'] = test_data['sex'].fillna('unknown')\ntest_data['age_approx'] = test_data['age_approx'].fillna(0)\ntest_data['anatom_site_general_challenge'] = test_data['anatom_site_general_challenge'].fillna('unknown')","metadata":{"execution":{"iopub.status.busy":"2022-03-02T18:02:59.631402Z","iopub.execute_input":"2022-03-02T18:02:59.632259Z","iopub.status.idle":"2022-03-02T18:02:59.653431Z","shell.execute_reply.started":"2022-03-02T18:02:59.632224Z","shell.execute_reply":"2022-03-02T18:02:59.65227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def prepare_arrays (path) :\n    images_data = []\n    labels_data = []\n    train = pd.read_csv(os.path.join(path, 'train.csv'))\n    for k in tqdm(range(len(train['image_name']))) :\n        try :\n            img = plt.imread(os.path.join(path, 'jpeg', 'train', train['image_name'][k] + '.jpg'))\n            img = cv2.resize(img, (128,128))\n            images_data.append(img)\n            labels_data.append(train['target'][k])\n        except :\n            continue\n    print(\"finished : \", len(images_data))\n    return images_data, labels_data","metadata":{"execution":{"iopub.status.busy":"2022-03-02T18:02:59.654898Z","iopub.execute_input":"2022-03-02T18:02:59.655307Z","iopub.status.idle":"2022-03-02T18:02:59.662604Z","shell.execute_reply.started":"2022-03-02T18:02:59.655276Z","shell.execute_reply":"2022-03-02T18:02:59.661572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images_data, labels_data = prepare_arrays(path)","metadata":{"execution":{"iopub.status.busy":"2022-03-02T18:02:59.664072Z","iopub.execute_input":"2022-03-02T18:02:59.664339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images = images_data.copy()\nlabels = labels_data.copy()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_samples (images, labels) :\n    real_labels = [\"benign\", \"malignant\"]\n    fig = plt.figure(figsize = (20,25))\n    rand = random.randint(0, len(images))\n\n    for i in range(20): \n        fig.add_subplot(5,4, i+1)\n        plt.title(real_labels[int(labels[rand])])\n        plt.axis('off')\n        plt.imshow(images[rand])\n        rand = random.randint(0, len(images))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_samples(images, labels)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# processing the data for the model","metadata":{}},{"cell_type":"code","source":"def resize_array(images, size) :\n    for i in range(len(images)) :\n        images[i] = cv2.resize(images[i], size)\n    return images","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"le = LabelEncoder()\ndef preprocess_data(images, labels) :\n    labels = le.fit_transform(labels)\n    labels = to_categorical(labels, 2)\n    images, labels = shuffle(images, labels, random_state = 32)\n    x_train, x_test, y_train, y_test = train_test_split(images, labels, test_size = 0.25, random_state = 32)\n    x_train = np.array(x_train) \n    x_test = np.array(x_test) \n    y_train = np.array(y_train) \n    y_test = np.array(y_test)\n    return x_train, x_test, y_train, y_test","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images = resize_array(images, tuple((32,32)))\nx_train, x_test, y_train, y_test = preprocess_data(images, labels)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# modeling","metadata":{}},{"cell_type":"code","source":"def build_model () :\n    model = Sequential()\n    model.add(Conv2D(filters = 32, kernel_size = (3,3), padding = 'same',input_shape = (32, 32, 3), activation = 'relu'))\n    model.add(MaxPool2D(pool_size = (2,2)))\n    model.add(Dropout(0.25))\n    \n    model.add(Conv2D(filters = 64, kernel_size = (3,3), padding = 'same', activation = 'relu'))\n    model.add(MaxPool2D(pool_size = (2,2)))\n    model.add(Dropout(0.25))\n    model.add(BatchNormalization())\n    #model.add(GlobalAveragePooling2D())\n\n    model.add(Flatten())\n    model.add(Dense(64, activation = 'relu'))\n    model.add(Dropout(0.5))\n    model.add(Dense(2, activation = 'sigmoid')) # sigmoid is better for binary classification\n\n    model.summary()\n    return model","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = build_model()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def train(model, epochs_num) :\n    model.compile(loss = 'binary_crossentropy', optimizer = 'Adam', metrics = ['accuracy'])\n    early_stop = EarlyStopping(monitor = 'val_loss', patience = 3)\n    hist = model.fit(x_train, y_train, epochs = epochs_num, validation_data = (x_test, y_test))#, callbacks = early_stop)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train(model, 12)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_scores (model) :\n    scores = pd.DataFrame(model.history.history)\n    titles = [\"accuaracy vs val_accuracy\", \"loss vs val_loss\"]\n    fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize = (24,6))\n    #fig, ax = plt.figure(figsize = (20,8))\n\n    for i in range(2): \n        fig.add_subplot(1,2, i+1)\n        axes[i].set_title(titles[i])\n        if i==0 : plt.plot(scores[['accuracy','val_accuracy']])#, color = 'green')\n        if i==1 : plt.plot(scores[['loss','val_loss']])#, color = 'green')\n        #scores[['accuracy', 'val_accuracy']].plot(ax = axes[i])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_scores(model) ","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save('Normal_skin_cancer_model.h5')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.listdir('../input')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"final results for loss and accuracy : \")\nprint(model.evaluate(x_train, y_train))\nprint(model.evaluate(x_test,y_test))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# classification report ","metadata":{}},{"cell_type":"code","source":"pred = np.argmax(model.predict(x_test), axis = -1)\ny_testc = np.argmax(y_test, axis = -1)\n\n\nprint(classification_report(y_testc, pred))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"very bad recall and f1 score class 1 (maignant)","metadata":{}},{"cell_type":"code","source":"print(pred)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(y_test)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# modeling image augmentation","metadata":{}},{"cell_type":"code","source":"#be calm and watch wa3i\ndef image_augmentation(x_train, x_test, y_train, y_test) :\n    image_generator = ImageDataGenerator(\n        samplewise_center = True,\n        samplewise_std_normalization = True,\n        rotation_range = 25, \n        width_shift_range = 0.1, \n        height_shift_range = 0.1,\n        shear_range = 0.2,\n        zoom_range = 0.2,\n        horizontal_flip = True#, fill_mode = \"nearst\"\n    )\n    train_generator = image_generator.flow(x_train, y_train, batch_size = 32)\n    test_generator = image_generator.flow(x_test, y_test, batch_size = 32)\n    return train_generator, test_generator","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_generator, test_generator = image_augmentation(x_train, x_test, y_train, y_test)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"modelA =  build_model()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def trainA(model, epochs_num) :\n    model.compile(loss = 'binary_crossentropy', optimizer = 'Adam', metrics = ['accuracy'])\n    early_stop = EarlyStopping(monitor = 'val_loss', patience = 3)\n    hist = model.fit(train_generator, epochs = epochs_num, validation_data = (test_generator))#, callbacks = early_stop)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainA(modelA, 12)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_scores(modelA) ","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"modelA.save('Augmented_skin_cancer_model.h5')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# classification report","metadata":{}},{"cell_type":"code","source":"predA = np.argmax(modelA.predict(x_test), axis = -1)\ny_testc = np.argmax(y_test, axis = -1)\n\nprint(classification_report(y_testc, predA))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"very bad precision and recall","metadata":{}},{"cell_type":"markdown","source":"# oversamping our data","metadata":{}},{"cell_type":"code","source":"images_arr = np.array(images)\nprint(images_arr.shape)\nreshaped_images = images_arr.reshape(images_arr.shape[0], -1)\nprint(reshaped_images.shape)\n\noversample = RandomOverSampler()\noversample_images_non_normal, oversample_labels = oversample.fit_resample(reshaped_images, labels)\n\noversample_images = oversample_images_non_normal.reshape(-1, 32,32,3)\nprint(oversample_images.shape)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"c = 0\nfor i in oversample_labels :\n    if i == 1:\n        c += 1\n        \nprint(c)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(oversample_images[0])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# New models","metadata":{}},{"cell_type":"code","source":"x_train, x_test, y_train, y_test = preprocess_data(oversample_images, oversample_labels)\nmodel = build_model()\ntrain(model, 12)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_scores(model) ","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = np.argmax(model.predict(x_test), axis = -1)\ny_testc = np.argmax(y_test, axis = -1)\n\nprint(classification_report(y_testc, pred))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save('Normal_skin_cancer_model.h5')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# oversampling with augmentation","metadata":{}},{"cell_type":"code","source":"train_generator, test_generator = image_augmentation(x_train, x_test, y_train, y_test)\nmodelA = build_model()\ntrainA(modelA, 24)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_scores(modelA) ","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"modelA.evaluate(train_generator)\nmodelA.evaluate(test_generator)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predA = np.argmax(modelA.predict(x_test), axis = -1)\ny_testc = np.argmax(y_test, axis = -1)\n\nprint(classification_report(y_testc, pred))\nprint(len(x_test))\nprint(len(y_test))\n#print(accuracy_score(y_testc, predA))\n#print(classification_report(y_testc, predA))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"modelA.save('Augmented_skin_cancer_model.h5')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# evaluation","metadata":{}},{"cell_type":"code","source":"def prepare_eval_array (path) :\n    eval_array = []\n    train = pd.read_csv(os.path.join(path, 'train.csv'))\n    for k in tqdm(range(10)) :\n        rand = random.randint(0, len(test['image_name']))\n        try :\n            img = plt.imread(os.path.join(path, 'jpeg', 'test', test['image_name'][rand] + '.jpg'))\n            img = cv2.resize(img, (128,128))\n            eval_array.append(img)\n        except :\n            continue\n    print(\"finished : \", len(eval_array))\n    return eval_array","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"eval_array = prepare_eval_array(path)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_predictions (model) :\n    fig = plt.figure(figsize = (20,8))\n    real_labels = [\"benign\", \"malignant\"]\n\n    for i in range(10) :\n        img = eval_array[i]\n        img = cv2.resize(img, (32,32))\n        img = img.reshape(1,32,32,3)\n        val = np.argmax(model.predict(img))\n        fig.add_subplot(2,5, i+1)\n        plt.title(real_labels[val])\n        plt.imshow(eval_array[i])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_predictions(model)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_predictions(modelA)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"# images from website","metadata":{}},{"cell_type":"code","source":"os.listdir(\"../input\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"real_labels = [\"benign\", \"malignant\"]\nimg = plt.imread(\"../input/evaluation-images/binign_skin1.jpg\")\nimg1 = img.copy()\nimg1 = cv2.resize(img1, (32,32))\nimg1 = img1.reshape(1,32,32,3)\nval = np.argmax(model.predict(img1))\nplt.title(real_labels[val])\nplt.imshow(img)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.listdir(\"../input/melanoma-image\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"real_labels = [\"benign\", \"malignant\"]\nimg = plt.imread(\"../input/melanoma-image/melanoma-14.jpg\")\nimg1 = img.copy()\nimg1 = cv2.resize(img1, (32,32))\nimg1 = img1.reshape(1,32,32,3)\nval = np.argmax(model.predict(img1))\nplt.title(real_labels[val])\nplt.imshow(img)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"real_labels = [\"benign\", \"malignant\"]\nimg = plt.imread(\"../input/melanoma-image/melanoma-14.jpg\")\nimg1 = img.copy()\nimg1 = cv2.resize(img1, (32,32))\nimg1 = img1.reshape(1,32,32,3)\nval = np.argmax(modelA.predict(img1))\nplt.title(real_labels[val])\nplt.imshow(img)","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}