{"cells":[{"metadata":{"_kg_hide-output":true,"trusted":true},"cell_type":"code","source":"# # !pip install ../input/efficientnet-install-files/scik*.whl\n!pip install ../input/efficientnet-install-files/Ker*.whl\n!pip install ../input/efficientnet-install-files/eff*.whl","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import os\nimport glob\nimport shutil\nimport json\nimport keras\nimport itertools\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport tensorflow as tf\nfrom PIL import Image\nimport matplotlib.pyplot as plt\nimport efficientnet.keras\nfrom keras.models import Sequential\nfrom keras.optimizers import RMSprop, Adam\nfrom tensorflow.keras.applications import ResNet50\nfrom sklearn.model_selection import train_test_split\nfrom keras.preprocessing.image import ImageDataGenerator\nfrom keras.layers import GlobalAveragePooling2D, Flatten, Dense, Dropout\nfrom keras.callbacks import EarlyStopping, ModelCheckpoint, ReduceLROnPlateau\nfrom tensorflow.keras.mixed_precision import experimental as mixed_precision\npolicy = mixed_precision.Policy('mixed_float16')\nmixed_precision.set_policy(policy)\ncwd = os.getcwd()\nos.chdir('../input/bitempered-logistic-loss-direct-upload/')\nfrom tf_bi_tempered_loss import BiTemperedLogisticLoss\nos.chdir(cwd)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"loss = BiTemperedLogisticLoss(t1=0.6, t2=1.4)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"IMG_SIZE = 512\nsize = (IMG_SIZE,IMG_SIZE)\nbest_model = keras.models.load_model('../input/cassava-challenge-models/Cassava_model_effnetb4_mixed_precision_bitemperedloss(29jan).h5',compile=False)\n# img_model = keras.models.load_model('../input/cassava-comp-models/Cassava_model_effnetb4_imagenet.h5',compile=False)\nprint(best_model)\nTEST_DIR = '../input/cassava-leaf-disease-classification/test_images/'\ntest_images = os.listdir(TEST_DIR)\npredictions = []\n\nfor image in test_images:\n    img = Image.open(TEST_DIR + image)\n#     img = keras.preprocessing.image.load_img(TEST_DIR + image, \n#                                                       grayscale=False, \n#                                                       color_mode=\"rgb\", \n#                                                       target_size=size, \n# #                                                       interpolation=\"nearest\"\n#                                             )\n    print(img)\n    img = img.resize(size)\n#     img = keras.preprocessing.image.smart_resize(img, size)\n    print(img)\n    img = np.expand_dims(img, axis=0)\n    print(img.shape)\n    predictions.extend(best_model.predict(img).argmax(axis = 1))\n    print(best_model.predict(img))\n    \n\nsub = pd.DataFrame({'image_id': test_images, 'label': predictions})\nsub.to_csv('submission.csv', index = False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"predictions","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"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}