{"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":"import tensorflow as tf\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom PIL import Image\nimport tensorflow_hub as hub\nimport tensorflow_datasets as tfds","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-05-28T18:52:02.346776Z","iopub.execute_input":"2023-05-28T18:52:02.347164Z","iopub.status.idle":"2023-05-28T18:52:11.726428Z","shell.execute_reply.started":"2023-05-28T18:52:02.347132Z","shell.execute_reply":"2023-05-28T18:52:11.725233Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.preprocessing.image import ImageDataGenerator\n\nimage_gen_train = ImageDataGenerator(rescale=1./255,\n                               rotation_range=45,\n                               horizontal_flip=True,\n                               width_shift_range=0.15,\n                               height_shift_range=0.15)\ntrain_data_gen = image_gen_train.flow_from_directory('/kaggle/input/state-farm-distracted-driver-detection/imgs/train', batch_size=100, target_size=(150, 150), shuffle=True, class_mode='sparse')","metadata":{"execution":{"iopub.status.busy":"2023-05-28T18:53:11.463547Z","iopub.execute_input":"2023-05-28T18:53:11.463933Z","iopub.status.idle":"2023-05-28T18:53:15.345977Z","shell.execute_reply.started":"2023-05-28T18:53:11.463902Z","shell.execute_reply":"2023-05-28T18:53:15.345095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = tf.keras.models.Sequential([\n    tf.keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(150, 150, 3)),\n    tf.keras.layers.MaxPooling2D(2, 2),\n\n    tf.keras.layers.Conv2D(64, (3, 3), activation='relu'),\n    tf.keras.layers.MaxPooling2D(2, 2),\n\n    tf.keras.layers.Conv2D(128, (3, 3), activation='relu'),\n    tf.keras.layers.MaxPooling2D(2, 2),\n\n    tf.keras.layers.Flatten(),\n    tf.keras.layers.Dropout(0.2),\n    tf.keras.layers.Dense(128, 'relu'),\n    tf.keras.layers.Dense(128, 'relu'),\n    tf.keras.layers.Dense(10)\n])","metadata":{"execution":{"iopub.status.busy":"2023-05-28T18:53:15.347993Z","iopub.execute_input":"2023-05-28T18:53:15.348373Z","iopub.status.idle":"2023-05-28T18:53:15.438293Z","shell.execute_reply.started":"2023-05-28T18:53:15.348333Z","shell.execute_reply":"2023-05-28T18:53:15.437381Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer='adam', loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), metrics=['accuracy'])\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2023-05-28T18:53:15.439627Z","iopub.execute_input":"2023-05-28T18:53:15.440170Z","iopub.status.idle":"2023-05-28T18:53:15.480275Z","shell.execute_reply.started":"2023-05-28T18:53:15.440138Z","shell.execute_reply":"2023-05-28T18:53:15.479550Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(train_data_gen, epochs=50)\nmodel.save('/kaggle/working/gfgModel.h5')","metadata":{"execution":{"iopub.status.busy":"2023-05-28T19:00:11.239236Z","iopub.execute_input":"2023-05-28T19:00:11.239602Z","iopub.status.idle":"2023-05-28T19:57:12.466245Z","shell.execute_reply.started":"2023-05-28T19:00:11.239572Z","shell.execute_reply":"2023-05-28T19:57:12.462725Z"},"trusted":true},"execution_count":null,"outputs":[]}]}