{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Import"},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"import tensorflow.keras as keras\nimport tensorflow.keras.layers as layers\nimport tensorflow.keras.layers.experimental.preprocessing as preprocessing\n#import tensorflow_datasets as tfds\nimport seaborn as sns\nimport os, warnings\nwarnings.simplefilter(\"ignore\")\nimport matplotlib.pyplot as plt\nfrom matplotlib import gridspec\n%matplotlib inline \nimport math, re, os, cv2, json\nimport pandas as pd\nimport numpy as np\nimport tensorflow as tf\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\n#from tensorflow.python.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.python.keras import optimizers\nfrom tensorflow.python.keras.models import Sequential\nfrom tensorflow.python.keras.layers import Dropout, Flatten, Dense, Activation\nfrom tensorflow.keras.models import Model\nfrom tensorflow.keras.layers import Dense\nfrom tensorflow.python.keras.layers import  Convolution2D, MaxPooling2D\nfrom kaggle_datasets import KaggleDatasets\nimport tensorflow.keras.layers as L\nfrom tensorflow.keras.models import load_model\nfrom sklearn import metrics\nfrom sklearn.model_selection import train_test_split\nfrom tensorflow.python.keras import backend as K\nK.clear_session()\n# Helper functions\ndef decode_image(path, label=None, target_size=(512, 512)):\n    img = tf.image.decode_jpeg(tf.io.read_file(path), channels=3)\n    img = tf.cast(img, tf.float32) / 255.0\n    img = tf.image.resize(img, target_size)\n    \n    return img if label is None else img, label\n\ndef data_augment(img, label=None):\n    img = tf.image.random_flip_left_right(img)\n    img = tf.image.random_flip_up_down(img)\n    \n    return img if label is None else img, label","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"strategy = tf.distribute.get_strategy()\nAUTO = tf.data.experimental.AUTOTUNE\nBATCH_SIZE = 32\n\nload_dir = \"../input/cassava-leaf-disease-classification/\"\nsub_df = pd.read_csv(load_dir + 'sample_submission.csv')\nsub_df['paths'] = load_dir + \"/test_images/\" + sub_df.image_id\n\ntest_dataset = (\n    tf.data.Dataset\n    .from_tensor_slices(sub_df.paths.values)\n    .map(decode_image, num_parallel_calls=AUTO)\n    .batch(BATCH_SIZE).prefetch(AUTO))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Load Model\nyou can see the development:  \n[building-a-cnn-base-model-with-keras](https://www.kaggle.com/azhura/building-a-cnn-base-model-with-keras-gpu)"},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"with strategy.scope():\n    model = load_model('../input/building-a-cnn-base-model-with-keras-gpu/Model_3.h5')\n    model.summary()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Predictions"},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"preds = model.predict(test_dataset, verbose=1)\nsub_df['label'] = preds.argmax(axis=1)\nsub_df.drop(columns='paths').to_csv('submission.csv', index=False)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Work in progress ..."}],"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":4,"nbformat_minor":4}