{"cells":[{"metadata":{},"cell_type":"markdown","source":"Inference for EfficientNetB0 trained on 224x224 resizings"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nfrom tqdm import tqdm\nfrom tqdm.notebook import tqdm_notebook\ntqdm_notebook.pandas()\nfrom zipfile import ZipFile\nfrom io import StringIO\nimport cv2 as cv\nimport matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\nnp.random.seed(42)\nimport tensorflow as tf\nfrom tensorflow import keras\nimport os","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"filenames = os.listdir('../input/ranzcr-clip-catheter-line-classification/test/')\nstudy_instances = [filename[:-4] for filename in filenames]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def get_and_resize_all_images(X):\n  all_img = []\n  for image_name in tqdm_notebook(X):\n    img = get_image(image_name)\n    all_img.append(cv.resize(img,(224,224)))\n  return np.asarray(all_img)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def get_image(image_name):\n  return mpimg.imread('../input/ranzcr-clip-catheter-line-classification/test/'+image_name+'.jpg')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"X_test_images = get_and_resize_all_images(study_instances)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def three_channel_images(X):\n  X2 = X.reshape(X.shape + (1,))\n  return np.concatenate([X2,X2,X2],axis=3)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"X_test_images_three_channel = three_channel_images(X_test_images)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"X_test_images_three_channel.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"efficientnetb0 = keras.models.load_model('../input/efficientnetb0-21/efficientnetb0_2')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"efficientnetb0.compile(loss='binary_crossentropy',\n              optimizer=tf.optimizers.Nadam(learning_rate=1e-05),\n              metrics=[keras.metrics.AUC(multi_label=True,name='averaged_auc')])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"predictions = efficientnetb0.predict(X_test_images_three_channel)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_sub = pd.read_csv('../input/ranzcr-clip-catheter-line-classification/sample_submission.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_sub['StudyInstanceUID'] = study_instances","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_sub.iloc[:, 1:] = predictions","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_sub.to_csv('submission.csv',index=False)","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}