{"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 Augmentor\n!pip install tensorflow_addons\nimport os\nfrom os import path\nimport random\nimport numpy as np\nimport pandas as pd\nimport cv2\nimport Augmentor\nfrom matplotlib import pyplot as plt\nimport tensorflow as tf\nfrom tensorflow import keras\nfrom tensorflow.keras import utils\nfrom tensorflow.keras import layers ,Model\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Conv2D,SeparableConv2D, MaxPooling2D,MaxPool2D, Dense,Add, Flatten,GlobalAvgPool2D\nfrom tensorflow.keras.layers import Dropout,GlobalAveragePooling2D,BatchNormalization, Input \nfrom tensorflow.keras.layers import ReLU,DepthwiseConv2D ,AvgPool2D,concatenate ,ReLU\nfrom keras.preprocessing import image\nfrom tensorflow_addons.optimizers import CyclicalLearningRate","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-03-04T17:28:48.881021Z","iopub.execute_input":"2023-03-04T17:28:48.882234Z","iopub.status.idle":"2023-03-04T17:29:23.418473Z","shell.execute_reply.started":"2023-03-04T17:28:48.882188Z","shell.execute_reply":"2023-03-04T17:29:23.417003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# split\nAll_Data = tf.keras.utils.image_dataset_from_directory(\n  \"/kaggle/input/state-farm-distracted-driver-detection/imgs/train\",\n    label_mode='categorical',\n    color_mode='rgb',\n    batch_size=16,\n    image_size=(256, 256)\n)","metadata":{"execution":{"iopub.status.busy":"2023-03-04T17:29:56.332900Z","iopub.execute_input":"2023-03-04T17:29:56.333893Z","iopub.status.idle":"2023-03-04T17:30:02.660770Z","shell.execute_reply.started":"2023-03-04T17:29:56.333844Z","shell.execute_reply":"2023-03-04T17:30:02.659526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(All_Data))","metadata":{"execution":{"iopub.status.busy":"2023-03-04T17:32:34.086242Z","iopub.execute_input":"2023-03-04T17:32:34.087096Z","iopub.status.idle":"2023-03-04T17:32:34.093128Z","shell.execute_reply.started":"2023-03-04T17:32:34.087046Z","shell.execute_reply":"2023-03-04T17:32:34.091816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Avoid OOM errors by setting GPU Memory Consumption Growth\ngpus = tf.config.experimental.list_physical_devices('GPU')\nfor gpu in gpus: \n    tf.config.experimental.set_memory_growth(gpu, True)","metadata":{"execution":{"iopub.status.busy":"2023-03-04T17:32:39.808477Z","iopub.execute_input":"2023-03-04T17:32:39.809352Z","iopub.status.idle":"2023-03-04T17:32:39.814707Z","shell.execute_reply.started":"2023-03-04T17:32:39.809309Z","shell.execute_reply":"2023-03-04T17:32:39.813578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.config.list_physical_devices('GPU')","metadata":{"execution":{"iopub.status.busy":"2023-03-04T17:32:56.786686Z","iopub.execute_input":"2023-03-04T17:32:56.787148Z","iopub.status.idle":"2023-03-04T17:32:56.794916Z","shell.execute_reply.started":"2023-03-04T17:32:56.787107Z","shell.execute_reply":"2023-03-04T17:32:56.793500Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"activity_map = {'c0': 'Safe driving', \n                'c1': 'Texting - right', \n                'c2': 'Talking on the phone - right', \n                'c3': 'Texting - left', \n                'c4': 'Talking on the phone - left', \n                'c5': 'Operating the radio', \n                'c6': 'Drinking', \n                'c7': 'Reaching behind', \n                'c8': 'Hair and makeup', \n                'c9': 'Talking to passenger'}\n\n\nplt.figure(figsize=(15,12))\ncount=1\npath= '../input/state-farm-distracted-driver-detection/imgs/train/'\nso = os.listdir(\"../input/state-farm-distracted-driver-detection/imgs/train/\")\nfor dirr in so:\n    for i, file in enumerate(os.listdir(path+dirr)):\n        if i==1:\n            break\n        else:\n            fig = plt.subplot(3,4,count)\n            count +=1\n            img= plt.imread(path+ dirr + '/' +file)\n            plt.imshow(img)\n            plt.title(activity_map[dirr])","metadata":{"execution":{"iopub.status.busy":"2023-03-04T17:39:53.466846Z","iopub.execute_input":"2023-03-04T17:39:53.467615Z","iopub.status.idle":"2023-03-04T17:39:55.924774Z","shell.execute_reply.started":"2023-03-04T17:39:53.467566Z","shell.execute_reply":"2023-03-04T17:39:55.923654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_size = 1122\nval_size =280\n\ntrain = All_Data.take(train_size)\nval = All_Data.skip(train_size).take(val_size)","metadata":{"execution":{"iopub.status.busy":"2023-03-04T17:45:49.725990Z","iopub.execute_input":"2023-03-04T17:45:49.727165Z","iopub.status.idle":"2023-03-04T17:45:49.737248Z","shell.execute_reply.started":"2023-03-04T17:45:49.727116Z","shell.execute_reply":"2023-03-04T17:45:49.736089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(train))\nprint(len(val))\n","metadata":{"execution":{"iopub.status.busy":"2023-03-04T17:46:08.160338Z","iopub.execute_input":"2023-03-04T17:46:08.160770Z","iopub.status.idle":"2023-03-04T17:46:08.168724Z","shell.execute_reply.started":"2023-03-04T17:46:08.160735Z","shell.execute_reply":"2023-03-04T17:46:08.167369Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}