{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":13836,"databundleVersionId":1718836,"sourceType":"competition"}],"dockerImageVersionId":30732,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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\n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session\n\nfrom IPython.display import clear_output\nclear_output()","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-06-15T16:18:16.843327Z","iopub.execute_input":"2024-06-15T16:18:16.843723Z","iopub.status.idle":"2024-06-15T16:18:34.130705Z","shell.execute_reply.started":"2024-06-15T16:18:16.843690Z","shell.execute_reply":"2024-06-15T16:18:34.129514Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/cassava-leaf-disease-classification/train.csv')","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:30:42.458654Z","iopub.execute_input":"2024-06-15T16:30:42.459155Z","iopub.status.idle":"2024-06-15T16:30:42.494686Z","shell.execute_reply.started":"2024-06-15T16:30:42.459112Z","shell.execute_reply":"2024-06-15T16:30:42.493369Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images = []","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:18:35.894431Z","iopub.execute_input":"2024-06-15T16:18:35.895350Z","iopub.status.idle":"2024-06-15T16:18:35.900614Z","shell.execute_reply.started":"2024-06-15T16:18:35.895310Z","shell.execute_reply":"2024-06-15T16:18:35.899116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = '/kaggle/input/cassava-leaf-disease-classification/train_images/'\nfor filename in os.listdir(path):\n    images.append(filename)","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:18:36.597598Z","iopub.execute_input":"2024-06-15T16:18:36.598093Z","iopub.status.idle":"2024-06-15T16:18:36.612066Z","shell.execute_reply.started":"2024-06-15T16:18:36.598054Z","shell.execute_reply":"2024-06-15T16:18:36.610728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_arr_list = []","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:19:02.924320Z","iopub.execute_input":"2024-06-15T16:19:02.924721Z","iopub.status.idle":"2024-06-15T16:19:02.930798Z","shell.execute_reply.started":"2024-06-15T16:19:02.924689Z","shell.execute_reply":"2024-06-15T16:19:02.929250Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from PIL import Image\nimport tensorflow as tf\nfrom tensorflow.keras.preprocessing.image import img_to_array , load_img\n\npath = '/kaggle/input/cassava-leaf-disease-classification/train_images/'\ncount = 0\nfor img in images:\n    if(count <= 1000):\n        pathhh  = os.path.join(path , img)\n        im = load_img(pathhh)\n        im = img_to_array(im) / 255.0\n        img_arr_list.append(im)\n        \n        count +=1","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:23:37.189463Z","iopub.execute_input":"2024-06-15T16:23:37.189885Z","iopub.status.idle":"2024-06-15T16:23:51.961139Z","shell.execute_reply.started":"2024-06-15T16:23:37.189841Z","shell.execute_reply":"2024-06-15T16:23:51.960144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Dense , Flatten\nfrom keras.optimizers import Adam","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:33:16.482996Z","iopub.execute_input":"2024-06-15T16:33:16.483460Z","iopub.status.idle":"2024-06-15T16:33:16.490540Z","shell.execute_reply.started":"2024-06-15T16:33:16.483426Z","shell.execute_reply":"2024-06-15T16:33:16.489079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_arr = np.array(img_arr_list)","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:28:24.367482Z","iopub.execute_input":"2024-06-15T16:28:24.367890Z","iopub.status.idle":"2024-06-15T16:28:26.909762Z","shell.execute_reply.started":"2024-06-15T16:28:24.367858Z","shell.execute_reply":"2024-06-15T16:28:26.908732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.utils import to_categorical\ny_train_cat = to_categorical(train.iloc[:1001 , 1], 10)","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:31:28.704856Z","iopub.execute_input":"2024-06-15T16:31:28.705250Z","iopub.status.idle":"2024-06-15T16:31:28.714145Z","shell.execute_reply.started":"2024-06-15T16:31:28.705218Z","shell.execute_reply":"2024-06-15T16:31:28.711993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential()\nmodel.add(Flatten(input_shape=(600, 800, 3)))  # Flatten the input images\nmodel.add(Dense(128, activation='relu'))\nmodel.add(Dense(64, activation='relu'))\nmodel.add(Dense(10, activation='softmax'))","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:33:30.751237Z","iopub.execute_input":"2024-06-15T16:33:30.751638Z","iopub.status.idle":"2024-06-15T16:33:32.341060Z","shell.execute_reply.started":"2024-06-15T16:33:30.751606Z","shell.execute_reply":"2024-06-15T16:33:32.339964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer=Adam(), loss='categorical_crossentropy', metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:34:16.384642Z","iopub.execute_input":"2024-06-15T16:34:16.385014Z","iopub.status.idle":"2024-06-15T16:34:16.403470Z","shell.execute_reply.started":"2024-06-15T16:34:16.384986Z","shell.execute_reply":"2024-06-15T16:34:16.402349Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Train the model\nmodel.fit(img_arr, y_train_cat, epochs=10, batch_size=32, validation_split = 0.1)\n","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:35:13.758774Z","iopub.execute_input":"2024-06-15T16:35:13.759176Z","iopub.status.idle":"2024-06-15T16:45:40.866228Z","shell.execute_reply.started":"2024-06-15T16:35:13.759145Z","shell.execute_reply":"2024-06-15T16:45:40.864404Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}