{"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)\nimport matplotlib.image as mpimg\nimport os\nfrom matplotlib import pyplot as plt\nimport tensorflow as tf\nfrom PIL import Image\nfrom sklearn.preprocessing import MultiLabelBinarizer","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-12-07T15:12:43.903073Z","iopub.execute_input":"2022-12-07T15:12:43.904281Z","iopub.status.idle":"2022-12-07T15:12:43.911546Z","shell.execute_reply.started":"2022-12-07T15:12:43.904231Z","shell.execute_reply":"2022-12-07T15:12:43.910583Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def image_size():\n    image_size_set = set()\n\n    for dirname, _, filenames in os.walk('/kaggle/input/plant-pathology-2021-fgvc8/train_images'):\n        for idx, filename in enumerate(filenames):\n            img = Image.open(os.path.join(dirname, filename))\n            image_size_set.add(img.size)\n\n    print(image_size_set)\n#image_size()","metadata":{"execution":{"iopub.status.busy":"2022-12-07T14:40:56.058645Z","iopub.execute_input":"2022-12-07T14:40:56.059011Z","iopub.status.idle":"2022-12-07T14:40:56.066643Z","shell.execute_reply.started":"2022-12-07T14:40:56.058964Z","shell.execute_reply":"2022-12-07T14:40:56.065344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def resize_images():\n    resized_images = tf.keras.preprocessing.image_dataset_from_directory(\n        directory='/kaggle/input/plant-pathology-2021-fgvc8/train_images/',\n        labels=None,\n        shuffle=False)\n    return resized_images\nresized_images = resize_images()","metadata":{"execution":{"iopub.status.busy":"2022-12-07T14:40:56.068280Z","iopub.execute_input":"2022-12-07T14:40:56.068733Z","iopub.status.idle":"2022-12-07T14:41:00.007579Z","shell.execute_reply.started":"2022-12-07T14:40:56.068677Z","shell.execute_reply":"2022-12-07T14:41:00.006396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# # **NORMALIZE IMAGES!!!**","metadata":{}},{"cell_type":"code","source":"def show_image_batch(images):\n    plt.figure(figsize=(20,20))\n    for images in images.take(5):\n        for i in range(32):\n            ax = plt.subplot(6, 6, i+1)\n            plt.imshow(images[i].numpy().astype(\"uint8\"))\n            plt.axis(\"off\")\n            \nshow_image_batch(resized_images)","metadata":{"execution":{"iopub.status.busy":"2022-12-07T14:41:01.881784Z","iopub.execute_input":"2022-12-07T14:41:01.882828Z","iopub.status.idle":"2022-12-07T14:41:13.610763Z","shell.execute_reply.started":"2022-12-07T14:41:01.882775Z","shell.execute_reply":"2022-12-07T14:41:13.608792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def string_to_vector(text):\n    text = text.split()    \n    return text\n\ndef translate_labels_from_string_to_vector():\n    directory = \"/kaggle/input/plant-pathology-2021-fgvc8/train.csv\"\n    label_df = pd.read_csv(directory)\n    label_df.loc[:,\"labels\"] = label_df.loc[:,\"labels\"].apply(string_to_vector)\n    mlb = MultiLabelBinarizer()\n    a = mlb.fit_transform(label_df[\"labels\"].to_list())\n    dff = pd.DataFrame(a, columns=mlb.classes_)\n    print(dff)\n    arr = dff[[\"complex\", \"frog_eye_leaf_spot\", \"healthy\", \"powdery_mildew\", \"rust\", \"scab\"]].values\n    print(arr)\n    return label_df\n\nprint(translate_labels_from_string_to_vector())\n","metadata":{"execution":{"iopub.status.busy":"2022-12-07T15:28:53.290793Z","iopub.execute_input":"2022-12-07T15:28:53.291977Z","iopub.status.idle":"2022-12-07T15:28:53.360490Z","shell.execute_reply.started":"2022-12-07T15:28:53.291932Z","shell.execute_reply":"2022-12-07T15:28:53.359112Z"},"trusted":true},"execution_count":null,"outputs":[]}]}