{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"scrolled":true},"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nimport random\nfrom skimage.feature import hog\nfrom skimage import data, exposure\nimport sys\nimport cv2\nimport matplotlib\nfrom subprocess import check_output\n\nfrom keras.models import Sequential\nfrom keras.layers import Dense, Conv2D, MaxPooling2D, Dropout, Flatten\nfrom keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img\nfrom keras.optimizers import Adam\nfrom sklearn.model_selection import train_test_split\nfrom keras.utils import to_categorical\n#list the files in the input directory\n#print(os.listdir(\"../input\"))\n#print(check_output([\"ls\", \"../input\"]).decode(\"utf8\")) #trainLabels.csv\n#print(check_output([\"pwd\", \"\"]).decode(\"utf8\")) # /kaggle/working/\n#classes : 0 - No DR, 1 - Mild, 2 - Moderate, 3 - Severe, 4 - Proliferative DR\ndef classes_to_int(label):\n    # label = classes.index(dir)\n    label = label.strip()\n    if label == \"No DR\":  return 0\n    if label == \"Mild\":  return 1\n    if label == \"Moderate\":  return 2\n    if label == \"Severe\":  return 3\n    if label == \"Proliferative DR\":  return 4\n    print(\"Invalid Label\", label)\n    return 5\n\ndef int_to_classes(i):\n    if i == 0: return \"No DR\"\n    elif i == 1: return \"Mild\"\n    elif i == 2: return \"Moderate\"\n    elif i == 3: return \"Severe\"\n    elif i == 4: return \"Proliferative DR\"\n    print(\"Invalid class \", i)\n    return \"Invalid Class\"","execution_count":16,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a8392f068f3887a4ef107e51530e2eb05fb3035a"},"cell_type":"code","source":"NUM_CLASSES = 5\n# we need images of same size so we convert them into the size\nWIDTH = 128\nHEIGHT = 128\nDEPTH = 3\ninputShape = (HEIGHT, WIDTH, DEPTH)\n# initialize number of epochs to train for, initial learning rate and batch size\nEPOCHS = 15\nINIT_LR = 1e-3\nBS = 32\n#global variables\nImageNameDataHash = {}\nuniquePatientIDList = []","execution_count":17,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"18c3c3a9599a32a49199918bef643166cde51928"},"cell_type":"code","source":"def readTrainData(trainDir):\n    global ImageNameDataHash\n    # loop over the input images\n    images = os.listdir(trainDir)\n    print(\"Number of files in \" + trainDir + \" is \" + str(len(images)))\n    for imageFileName in images:\n        if (imageFileName == \"trainLabels.csv\"):\n            continue\n        # load the image, pre-process it, and store it in the data list\n        imageFullPath = os.path.join(os.path.sep, trainDir, imageFileName)\n        #print(imageFullPath)\n        \n        image = load_img(imageFullPath)\n        \n        fd, hog_image = hog(image, orientations=8, pixels_per_cell=(16, 16),\n                    cells_per_block=(1, 1), visualize=True, multichannel=True)\n\n        fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4), sharex=True, sharey=True)\n\n        ax1.axis('off')\n        ax1.imshow(image, cmap=plt.cm.gray)\n        ax1.set_title('Input image')\n\n# Rescale histogram for better display\n        hog_image_rescaled = exposure.rescale_intensity(hog_image, in_range=(0, 10))\n\n        ax2.axis('off')\n        ax2.imshow(hog_image_rescaled, cmap=plt.cm.gray)\n        ax2.set_title('Histogram of Oriented Gradients')\n        plt.show()\n    return \n        ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a255507029c703ab70b7bd82e2dba11487abf73a"},"cell_type":"code","source":"\nfrom datetime import datetime\nprint(\"Loading images at...\"+ str(datetime.now()))\nsys.stdout.flush()\nreadTrainData(\"/kaggle/working/../input/\")\nprint(\"Loaded \" + str(len(ImageNameDataHash)) + \" images at...\"+ str(datetime.now())) # 1000","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"da157990920eda7c89bd96f6457cf2696d45b01b","scrolled":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"bbceaf7b7abd5a2c2f562b63f2ead55c00e451e2"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"98a5849022c032a33b2d75f54ec2d05da2cd9245"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2d8c229035728a04562a428aed1b685974e172e8"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ea37d7a5dffecdb0744c223090c98c91ee097ccf"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c3fd926f29c25be1bd728da76c175e283b1fac83"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"25fd586d9cc4b7a1beeb2e8c7cdee896f068b8c6"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5de4e16737d21bd5c842e3b3fe7ca16b3177f76a"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4550440da8759c52ed43bfe0737bfa2684e7583c"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"07f4a9232379f1c7057f9921ad372266caadd887"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"19f9a8d5aba3229deecf254d2db0b7e5c5cbd81f"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6673e914026947e96d26318834ed6ac914ab4e9d"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8925ee30a9086c36f0e8f7cc88ff24e177870051"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ff8002067d4fb19fd8ef9634f3bab2a8daa35b1a"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"55ee93f18f850e1fb144e578778a3b5420637684"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2f61c84f7f96522c7355bd126c8722676c8e3836"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6a66f5862854d1b03730a172f38ef25465fd2421"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"701909840ec8ee1f5da90a8cac0902d880d4f79a"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ebaac96c16fc39a6665ac3e8917ca856029f12dc"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}