{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":45867,"databundleVersionId":6924515,"sourceType":"competition"}],"dockerImageVersionId":30587,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"## Read test_images instaed of test_thumbnails cost a lot of time, how to work it out ?","metadata":{}},{"cell_type":"markdown","source":"My Model was Trained on WSIs.\n\nHere is the preditions on TMAs(in trainset)\n\nFirst row: Ground Truth\n\nSecond row: Predicted","metadata":{}},{"cell_type":"markdown","source":"![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1846070%2F6ce4d6e704a15b6169b1689169ff8669%2Fres.png?generation=1700100680792501&alt=media)","metadata":{}},{"cell_type":"markdown","source":"However, it is not possible to preform predictions on the hidden testset in 12 hours.\n\nTIME...","metadata":{}},{"cell_type":"code","source":"import os\n\nfrom PIL import Image\nImage.MAX_IMAGE_PIXELS = None\njpeg_quality=80","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-11-16T06:17:31.724573Z","iopub.execute_input":"2023-11-16T06:17:31.72488Z","iopub.status.idle":"2023-11-16T06:17:31.730168Z","shell.execute_reply.started":"2023-11-16T06:17:31.724856Z","shell.execute_reply":"2023-11-16T06:17:31.729012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def center_crop(tma_path,label,save_dir, target_size=2000):\n    wsi_name = tma_path.split('/')[-1].split('.')[0]\n\n    tma_image = Image.open(tma_path)\n    tma_width, tma_height = tma_image.size\n\n    if isinstance(target_size, int):\n        target_size = (target_size, target_size)\n\n    left = (tma_width - target_size[0]) // 2\n    upper = (tma_height - target_size[1]) // 2\n    right = left + target_size[0]\n    lower = upper + target_size[1]\n\n    # center crop\n    cropped_image = tma_image.crop((left, upper, right, lower))\n\n    # cropped_image.save(os.path.join(save_dir, f'{wsi_name}_{label}_centercropped.jpg'))\n    \n    return cropped_image","metadata":{"execution":{"iopub.status.busy":"2023-11-16T06:17:43.878849Z","iopub.execute_input":"2023-11-16T06:17:43.879167Z","iopub.status.idle":"2023-11-16T06:17:43.88627Z","shell.execute_reply.started":"2023-11-16T06:17:43.879144Z","shell.execute_reply":"2023-11-16T06:17:43.884939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\nx=center_crop('/kaggle/input/UBC-OCEAN/test_images/41.png','d','./')","metadata":{"execution":{"iopub.status.busy":"2023-11-16T06:33:01.433481Z","iopub.execute_input":"2023-11-16T06:33:01.4338Z","iopub.status.idle":"2023-11-16T06:33:14.31581Z","shell.execute_reply.started":"2023-11-16T06:33:01.433773Z","shell.execute_reply":"2023-11-16T06:33:14.314937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\nx=center_crop('/kaggle/input/UBC-OCEAN/train_images/10077.png','d','./')","metadata":{"execution":{"iopub.status.busy":"2023-11-16T06:33:19.245815Z","iopub.execute_input":"2023-11-16T06:33:19.246143Z","iopub.status.idle":"2023-11-16T06:34:40.655796Z","shell.execute_reply.started":"2023-11-16T06:33:19.246119Z","shell.execute_reply":"2023-11-16T06:34:40.654824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"15*1000//3600","metadata":{"execution":{"iopub.status.busy":"2023-11-16T06:34:40.664353Z","iopub.execute_input":"2023-11-16T06:34:40.664652Z","iopub.status.idle":"2023-11-16T06:34:40.670365Z","shell.execute_reply.started":"2023-11-16T06:34:40.664629Z","shell.execute_reply":"2023-11-16T06:34:40.669427Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"60*1000//3600","metadata":{"execution":{"iopub.status.busy":"2023-11-16T06:35:03.93486Z","iopub.execute_input":"2023-11-16T06:35:03.935206Z","iopub.status.idle":"2023-11-16T06:35:03.941447Z","shell.execute_reply.started":"2023-11-16T06:35:03.935178Z","shell.execute_reply":"2023-11-16T06:35:03.940439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"...","metadata":{}}]}