{"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 numpy as np\nimport csv\nimport os\nimport cv2\n\nmodel1 = tf.keras.models.load_model(\"../input/pre-trained-model/1test_5.h5\")\nmodel2 = tf.keras.models.load_model(\"../input/pre-trained-model/1test_6.h5\")\nmodel3 = tf.keras.models.load_model(\"../input/pre-trained-model/1test_8.h5\")\nl = os.listdir(\"../input/cassava-leaf-disease-classification/test_images\")\nparent = \"../input/cassava-leaf-disease-classification/test_images/\"\npredictions = []\npredictions.append([\"image_id\", \"label\"])\nfor i in l :\n    child = parent + i\n    img = cv2.imread(child)\n    img = cv2.resize(img, (299, 299))\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n    img = tf.keras.applications.xception.preprocess_input(img)\n    img = img.reshape((1, 299, 299, 3))\n    pred = 0.3 * model1.predict(img)\n    pred = pred + 0.4 * model2.predict(img)\n    pred = pred + 0.3 * model3.predict(img)\n    pred = pred.reshape((5,))\n    print(np.argmax(pred))\n    del img\n    predictions.append([i, str(np.argmax(pred))])\n    del pred\n\n\nwith open('submission.csv', 'w', newline='') as file:\n    writer = csv.writer(file)\n    writer.writerows(predictions)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas\nprint(pandas.read_csv(\"submission.csv\"))","metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"execution_count":null,"outputs":[]}]}