{"cells":[{"metadata":{},"cell_type":"markdown","source":"## This notebook is part 2 (inference) of the first notebook which was for training <a href='https://www.kaggle.com/sinamhd9/efficientnetb0-in-keras-part-1-training'>[Part 1] </a>"},{"metadata":{},"cell_type":"markdown","source":"Now we have the trained model, we can simply load it here and save a lot of time for our submission. Having the training and inference all in one notebook is very time-consuming since your model should be trained again each time you run the notebook."},{"metadata":{"trusted":true},"cell_type":"code","source":"# Importing useful libraries\n\nimport pandas as pd \nimport numpy as np\nimport os\n\nimport keras\nfrom keras.models import load_model\nfrom PIL import Image\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Load model"},{"metadata":{"trusted":true},"cell_type":"code","source":"model = load_model('../input/keras-available-models-part-1-training/model.h5')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Prediction"},{"metadata":{},"cell_type":"markdown","source":"We can only see 1 data in the test set, however, after submission, all test dataset for public leaderboard (around 15000) will be tested."},{"metadata":{"trusted":true},"cell_type":"code","source":"img_size = 224\ntest_images = os.listdir('/kaggle/input/cassava-leaf-disease-classification/test_images/')\ny_preds = []\n\nfor i in test_images:\n    image = Image.open(f'/kaggle/input/cassava-leaf-disease-classification/test_images/{i}')\n    image = image.resize((img_size, img_size))\n    image = np.expand_dims(image, axis=0)\n    y_preds.append(np.argmax(model.predict(image)))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_sub = pd.DataFrame({'image_id': test_images, 'label': y_preds})\ndisplay(df_sub)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_sub.to_csv('submission.csv',index=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"markdown","source":"## Please upvote this notebook if you find it useful. Thanks!"}],"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}