{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport tensorflow as tf","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"test_path = \"../input/ranzcr-clip-catheter-line-classification/test/\"\nsample_df = pd.read_csv(\"../input/ranzcr-clip-catheter-line-classification/sample_submission.csv\")\nmodel_path = \"../input/model-for-ranzcr/model_b4.h5\"\ntest_path = test_path + sample_df[\"StudyInstanceUID\"] + \".jpg\"\nimg_size = [244,240,260,300,380,456,528,600]\nprint(test_path[0])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def decoder(size=(300,300)):\n    def decode(path):\n        file = tf.io.read_file(path)\n        img = tf.io.decode_jpeg(file,channels=3)\n        img = tf.cast(img,tf.float32) / 255\n        img = tf.image.resize(img,size)\n        return img\n    return decode\n\n\ndef build_dataset(target,decode_fn = None,bsize=16):\n    if decode_fn is None:\n        decode_fn = decoder()\n    auto = tf.data.experimental.AUTOTUNE\n    dset = tf.data.Dataset.from_tensor_slices(target)\n    dset = dset.map(decode_fn, num_parallel_calls=auto)\n    dset = dset.batch(bsize).prefetch(auto)\n    return dset","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_decode = decoder(size=(img_size[4],img_size[4]))\ntest = build_dataset(test_path,decode_fn=test_decode,bsize=16)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"model = tf.keras.models.load_model(model_path)\nmodel.summary()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"labels = sample_df.columns[1:]\nsample_df[labels] = model.predict(test,verbose=1)\nsample_df.to_csv(\"submission.csv\",index=False)\nsample_df.head()","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}