{"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":"from fastai.data.all import *\nfrom fastai.vision.all import *\nimport torchvision.transforms as T","metadata":{"execution":{"iopub.execute_input":"2023-07-04T15:24:06.624796Z","iopub.status.busy":"2023-07-04T15:24:06.623932Z","iopub.status.idle":"2023-07-04T15:24:13.788851Z","shell.execute_reply":"2023-07-04T15:24:13.787814Z"},"papermill":{"duration":7.174565,"end_time":"2023-07-04T15:24:13.791802","exception":false,"start_time":"2023-07-04T15:24:06.617237","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = Path('/kaggle/input/contrails-images-ash-color/contrails')","metadata":{"execution":{"iopub.execute_input":"2023-07-04T15:24:13.802445Z","iopub.status.busy":"2023-07-04T15:24:13.801922Z","iopub.status.idle":"2023-07-04T15:24:13.806856Z","shell.execute_reply":"2023-07-04T15:24:13.805476Z"},"papermill":{"duration":0.013187,"end_time":"2023-07-04T15:24:13.809747","exception":false,"start_time":"2023-07-04T15:24:13.79656","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"codes = [\"Background\", \"Contrail\"]","metadata":{"execution":{"iopub.execute_input":"2023-07-04T15:24:13.820047Z","iopub.status.busy":"2023-07-04T15:24:13.819674Z","iopub.status.idle":"2023-07-04T15:24:13.823866Z","shell.execute_reply":"2023-07-04T15:24:13.823007Z"},"papermill":{"duration":0.012011,"end_time":"2023-07-04T15:24:13.826078","exception":false,"start_time":"2023-07-04T15:24:13.814067","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dblock = DataBlock(\n    blocks = (ImageBlock, MaskBlock(codes=codes)),\n#     get_items = get_files,\n    get_x = lambda o: PILImage.create(T.ToPILImage()(T.ToTensor()(np.load(o)[...,:-1]))),\n    get_y = lambda o: PILMask.create(np.load(o)[..., -1].astype('int8')),\n    splitter  = RandomSplitter(),\n#     item_tfms = Resize(256),\n)","metadata":{"execution":{"iopub.execute_input":"2023-07-04T15:24:13.836548Z","iopub.status.busy":"2023-07-04T15:24:13.835864Z","iopub.status.idle":"2023-07-04T15:24:13.844983Z","shell.execute_reply":"2023-07-04T15:24:13.844023Z"},"papermill":{"duration":0.016926,"end_time":"2023-07-04T15:24:13.847373","exception":false,"start_time":"2023-07-04T15:24:13.830447","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fnames = get_files(path)","metadata":{"execution":{"iopub.execute_input":"2023-07-04T15:24:13.857458Z","iopub.status.busy":"2023-07-04T15:24:13.857127Z","iopub.status.idle":"2023-07-04T15:24:20.334495Z","shell.execute_reply":"2023-07-04T15:24:20.333435Z"},"papermill":{"duration":6.485503,"end_time":"2023-07-04T15:24:20.337179","exception":false,"start_time":"2023-07-04T15:24:13.851676","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dls = dblock.dataloaders(fnames[:100], bs=16)","metadata":{"execution":{"iopub.execute_input":"2023-07-04T15:24:20.348099Z","iopub.status.busy":"2023-07-04T15:24:20.347691Z","iopub.status.idle":"2023-07-04T15:24:23.878703Z","shell.execute_reply":"2023-07-04T15:24:23.877599Z"},"papermill":{"duration":3.539695,"end_time":"2023-07-04T15:24:23.881599","exception":false,"start_time":"2023-07-04T15:24:20.341904","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x, y = dls.one_batch()","metadata":{"execution":{"iopub.execute_input":"2023-07-04T15:24:23.892168Z","iopub.status.busy":"2023-07-04T15:24:23.891795Z","iopub.status.idle":"2023-07-04T15:24:24.179034Z","shell.execute_reply":"2023-07-04T15:24:24.178095Z"},"papermill":{"duration":0.295358,"end_time":"2023-07-04T15:24:24.181705","exception":false,"start_time":"2023-07-04T15:24:23.886347","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(x.shape[0]):\n    x[i, ...].show(), y[i, ...].show()","metadata":{"execution":{"iopub.execute_input":"2023-07-04T15:24:24.191947Z","iopub.status.busy":"2023-07-04T15:24:24.191621Z","iopub.status.idle":"2023-07-04T15:24:30.530073Z","shell.execute_reply":"2023-07-04T15:24:30.528826Z"},"papermill":{"duration":6.347337,"end_time":"2023-07-04T15:24:30.533416","exception":false,"start_time":"2023-07-04T15:24:24.186079","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dls.show_batch()","metadata":{"execution":{"iopub.execute_input":"2023-07-04T15:24:30.702895Z","iopub.status.busy":"2023-07-04T15:24:30.702406Z","iopub.status.idle":"2023-07-04T15:24:31.957388Z","shell.execute_reply":"2023-07-04T15:24:31.954714Z"},"papermill":{"duration":1.329906,"end_time":"2023-07-04T15:24:31.962992","exception":false,"start_time":"2023-07-04T15:24:30.633086","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn = unet_learner(dls, resnet34)","metadata":{"execution":{"iopub.execute_input":"2023-07-04T15:24:32.099241Z","iopub.status.busy":"2023-07-04T15:24:32.098743Z","iopub.status.idle":"2023-07-04T15:24:34.672277Z","shell.execute_reply":"2023-07-04T15:24:34.671125Z"},"papermill":{"duration":2.646993,"end_time":"2023-07-04T15:24:34.674954","exception":false,"start_time":"2023-07-04T15:24:32.027961","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn.fine_tune(4)","metadata":{"execution":{"iopub.execute_input":"2023-07-04T15:24:34.837251Z","iopub.status.busy":"2023-07-04T15:24:34.836709Z","iopub.status.idle":"2023-07-04T15:24:55.649305Z","shell.execute_reply":"2023-07-04T15:24:55.648029Z"},"papermill":{"duration":20.895747,"end_time":"2023-07-04T15:24:55.652496","exception":false,"start_time":"2023-07-04T15:24:34.756749","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn.show_results()","metadata":{"execution":{"iopub.execute_input":"2023-07-04T15:24:55.801992Z","iopub.status.busy":"2023-07-04T15:24:55.801422Z","iopub.status.idle":"2023-07-04T15:24:57.918917Z","shell.execute_reply":"2023-07-04T15:24:57.918018Z"},"papermill":{"duration":2.199129,"end_time":"2023-07-04T15:24:57.926131","exception":false,"start_time":"2023-07-04T15:24:55.727002","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"interp = SegmentationInterpretation.from_learner(learn)\ninterp.plot_top_losses(k=3)","metadata":{"execution":{"iopub.execute_input":"2023-07-04T15:24:58.104658Z","iopub.status.busy":"2023-07-04T15:24:58.104212Z","iopub.status.idle":"2023-07-04T15:25:02.057164Z","shell.execute_reply":"2023-07-04T15:25:02.055431Z"},"papermill":{"duration":4.044155,"end_time":"2023-07-04T15:25:02.06022","exception":true,"start_time":"2023-07-04T15:24:58.016065","status":"failed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learner.predict","metadata":{},"execution_count":null,"outputs":[]}]}