{"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":"import tensorflow as tf\nfrom tensorflow import keras","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-09-18T09:26:22.318263Z","iopub.execute_input":"2021-09-18T09:26:22.319104Z","iopub.status.idle":"2021-09-18T09:26:22.323298Z","shell.execute_reply.started":"2021-09-18T09:26:22.319062Z","shell.execute_reply":"2021-09-18T09:26:22.322287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pathlib\ndf='../input/rsna-miccai-brain-tumor-radiogenomic-classification/train'\ndf=pathlib.Path(df)","metadata":{"execution":{"iopub.status.busy":"2021-09-18T09:26:24.292106Z","iopub.execute_input":"2021-09-18T09:26:24.292377Z","iopub.status.idle":"2021-09-18T09:26:24.295976Z","shell.execute_reply.started":"2021-09-18T09:26:24.292349Z","shell.execute_reply":"2021-09-18T09:26:24.29533Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images=sorted(list(df.glob('*')))\nimages=images[0:20]","metadata":{"execution":{"iopub.status.busy":"2021-09-18T09:26:25.952384Z","iopub.execute_input":"2021-09-18T09:26:25.952645Z","iopub.status.idle":"2021-09-18T09:26:25.970221Z","shell.execute_reply.started":"2021-09-18T09:26:25.952612Z","shell.execute_reply":"2021-09-18T09:26:25.969271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t1=[]\nt2=[]\nflair=[]\nt1ce=[]\nfor i in range (0,20):\n    t1.append(list(images[i].glob('T1w/*')))\n    t1ce.append(list(images[i].glob('T1wCE/*')))\n    t2.append(list(images[i].glob('T2w/*')))    \n    flair.apppend(list(images[i].glob('FLAIR/*')))    \n","metadata":{"execution":{"iopub.status.busy":"2021-09-18T09:26:26.998303Z","iopub.execute_input":"2021-09-18T09:26:26.998577Z","iopub.status.idle":"2021-09-18T09:26:27.01056Z","shell.execute_reply.started":"2021-09-18T09:26:26.998551Z","shell.execute_reply":"2021-09-18T09:26:27.009752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2021-09-18T08:55:55.606037Z","iopub.execute_input":"2021-09-18T08:55:55.606248Z","iopub.status.idle":"2021-09-18T08:55:55.713195Z","shell.execute_reply.started":"2021-09-18T08:55:55.606225Z","shell.execute_reply":"2021-09-18T08:55:55.712595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"raw","source":"","metadata":{"execution":{"iopub.status.busy":"2021-09-18T08:02:01.172443Z","iopub.execute_input":"2021-09-18T08:02:01.173001Z","iopub.status.idle":"2021-09-18T08:02:01.400463Z","shell.execute_reply.started":"2021-09-18T08:02:01.172963Z","shell.execute_reply":"2021-09-18T08:02:01.399762Z"}}},{"cell_type":"code","source":"import numpy as np\nflairs=[]\nfor i in flair:\n    flairs=flairs+i","metadata":{"execution":{"iopub.status.busy":"2021-09-18T08:55:55.713988Z","iopub.execute_input":"2021-09-18T08:55:55.714216Z","iopub.status.idle":"2021-09-18T08:55:55.719045Z","shell.execute_reply.started":"2021-09-18T08:55:55.714187Z","shell.execute_reply":"2021-09-18T08:55:55.718499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t1s=[]\nfor i in t1:\n    t1s=t1s+i","metadata":{"execution":{"iopub.status.busy":"2021-09-18T08:55:55.720526Z","iopub.execute_input":"2021-09-18T08:55:55.720976Z","iopub.status.idle":"2021-09-18T08:55:55.727455Z","shell.execute_reply.started":"2021-09-18T08:55:55.720942Z","shell.execute_reply":"2021-09-18T08:55:55.726725Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"raw","source":"","metadata":{"execution":{"iopub.status.busy":"2021-09-18T05:16:38.621934Z","iopub.execute_input":"2021-09-18T05:16:38.622486Z","iopub.status.idle":"2021-09-18T05:16:38.627924Z","shell.execute_reply.started":"2021-09-18T05:16:38.622448Z","shell.execute_reply":"2021-09-18T05:16:38.626771Z"}}},{"cell_type":"code","source":"t2s=[]\nfor i in t2:\n    t2s=t2s+i","metadata":{"execution":{"iopub.status.busy":"2021-09-18T08:55:55.728826Z","iopub.execute_input":"2021-09-18T08:55:55.729329Z","iopub.status.idle":"2021-09-18T08:55:55.736388Z","shell.execute_reply.started":"2021-09-18T08:55:55.729293Z","shell.execute_reply":"2021-09-18T08:55:55.735607Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t1ces=[]\n\nfor i in t1ce:\n    t1ces=t1ces+i","metadata":{"execution":{"iopub.status.busy":"2021-09-18T08:55:55.737835Z","iopub.execute_input":"2021-09-18T08:55:55.738307Z","iopub.status.idle":"2021-09-18T08:55:55.744956Z","shell.execute_reply.started":"2021-09-18T08:55:55.738273Z","shell.execute_reply":"2021-09-18T08:55:55.744251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"np.shape(t1ces)","metadata":{"execution":{"iopub.status.busy":"2021-09-18T08:55:55.748275Z","iopub.execute_input":"2021-09-18T08:55:55.748905Z","iopub.status.idle":"2021-09-18T08:55:55.761835Z","shell.execute_reply.started":"2021-09-18T08:55:55.748869Z","shell.execute_reply":"2021-09-18T08:55:55.761071Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"brain_images_dict={\n    'flair':flairs,\n    't1':t1s,\n    't1ce':t1ces,\n    't2':t2s,\n    \n    \n    \n    \n    \n}","metadata":{"execution":{"iopub.status.busy":"2021-09-18T09:26:33.632884Z","iopub.execute_input":"2021-09-18T09:26:33.633596Z","iopub.status.idle":"2021-09-18T09:26:33.640178Z","shell.execute_reply.started":"2021-09-18T09:26:33.633559Z","shell.execute_reply":"2021-09-18T09:26:33.639376Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nnp.shape(t1ces)\n        \n         ","metadata":{"execution":{"iopub.status.busy":"2021-09-18T08:55:55.771787Z","iopub.execute_input":"2021-09-18T08:55:55.772268Z","iopub.status.idle":"2021-09-18T08:55:55.786643Z","shell.execute_reply.started":"2021-09-18T08:55:55.772233Z","shell.execute_reply":"2021-09-18T08:55:55.785798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"brain_labels_dict={\n'flair':0,\n't1':1,\n't2':2,\n't1ce':3\n\n}","metadata":{"execution":{"iopub.status.busy":"2021-09-18T09:26:38.896658Z","iopub.execute_input":"2021-09-18T09:26:38.896931Z","iopub.status.idle":"2021-09-18T09:26:38.901757Z","shell.execute_reply.started":"2021-09-18T09:26:38.896902Z","shell.execute_reply":"2021-09-18T09:26:38.900629Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X, y = [], []\nimport pydicom as dicom\nfrom skimage import exposure\n\nimport cv2\nfor brain_name, images in brain_images_dict.items():\n    for image in images:\n            ds=dicom.dcmread(str(image))\n            dcm=ds.pixel_array\n            dcm=exposure.equalize_adapthist(dcm)\n            resized_img = cv2.resize(dcm,(120,120))\n            X.append(resized_img)\n            y.append(brain_labels_dict[brain_name])","metadata":{"execution":{"iopub.status.busy":"2021-09-18T09:26:41.148661Z","iopub.execute_input":"2021-09-18T09:26:41.148923Z","iopub.status.idle":"2021-09-18T09:27:03.309844Z","shell.execute_reply.started":"2021-09-18T09:26:41.148896Z","shell.execute_reply":"2021-09-18T09:27:03.309035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np","metadata":{"execution":{"iopub.status.busy":"2021-09-18T09:27:06.268793Z","iopub.execute_input":"2021-09-18T09:27:06.269337Z","iopub.status.idle":"2021-09-18T09:27:06.273015Z","shell.execute_reply.started":"2021-09-18T09:27:06.269298Z","shell.execute_reply":"2021-09-18T09:27:06.271961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=np.array(X)\ny=np.array(y)","metadata":{"execution":{"iopub.status.busy":"2021-09-18T09:27:07.406798Z","iopub.execute_input":"2021-09-18T09:27:07.4075Z","iopub.status.idle":"2021-09-18T09:27:07.477092Z","shell.execute_reply.started":"2021-09-18T09:27:07.407457Z","shell.execute_reply":"2021-09-18T09:27:07.476305Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.shape","metadata":{"execution":{"iopub.status.busy":"2021-09-18T09:27:10.238835Z","iopub.execute_input":"2021-09-18T09:27:10.239091Z","iopub.status.idle":"2021-09-18T09:27:10.243993Z","shell.execute_reply.started":"2021-09-18T09:27:10.239063Z","shell.execute_reply":"2021-09-18T09:27:10.24335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=x.reshape(678,120,120,1)","metadata":{"execution":{"iopub.status.busy":"2021-09-18T09:27:20.413052Z","iopub.execute_input":"2021-09-18T09:27:20.413349Z","iopub.status.idle":"2021-09-18T09:27:20.419441Z","shell.execute_reply.started":"2021-09-18T09:27:20.41332Z","shell.execute_reply":"2021-09-18T09:27:20.417691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.unique(y)","metadata":{"execution":{"iopub.status.busy":"2021-09-18T09:27:25.129028Z","iopub.execute_input":"2021-09-18T09:27:25.129675Z","iopub.status.idle":"2021-09-18T09:27:25.136077Z","shell.execute_reply.started":"2021-09-18T09:27:25.129639Z","shell.execute_reply":"2021-09-18T09:27:25.135203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.models import load_model\nmodels=load_model('./g.h5')","metadata":{"execution":{"iopub.status.busy":"2021-09-18T09:27:52.582821Z","iopub.execute_input":"2021-09-18T09:27:52.583729Z","iopub.status.idle":"2021-09-18T09:27:52.848388Z","shell.execute_reply.started":"2021-09-18T09:27:52.583681Z","shell.execute_reply":"2021-09-18T09:27:52.847665Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2021-09-18T09:28:11.070245Z","iopub.execute_input":"2021-09-18T09:28:11.070919Z","iopub.status.idle":"2021-09-18T09:28:11.496492Z","shell.execute_reply.started":"2021-09-18T09:28:11.070886Z","shell.execute_reply":"2021-09-18T09:28:11.495831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(tf.keras.optimizers.Adam(lr=0.001),loss='sparse_categorical_crossentropy',metrics='accuracy')","metadata":{"execution":{"iopub.status.busy":"2021-09-18T09:05:51.719626Z","iopub.execute_input":"2021-09-18T09:05:51.719826Z","iopub.status.idle":"2021-09-18T09:05:51.734699Z","shell.execute_reply.started":"2021-09-18T09:05:51.719803Z","shell.execute_reply":"2021-09-18T09:05:51.733964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(x,y,epochs=100)","metadata":{"execution":{"iopub.status.busy":"2021-09-18T09:05:51.736137Z","iopub.execute_input":"2021-09-18T09:05:51.736452Z","iopub.status.idle":"2021-09-18T09:19:59.455575Z","shell.execute_reply.started":"2021-09-18T09:05:51.736417Z","shell.execute_reply":"2021-09-18T09:19:59.45465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2021-09-18T09:20:58.533348Z","iopub.execute_input":"2021-09-18T09:20:58.533919Z","iopub.status.idle":"2021-09-18T09:20:58.5999Z","shell.execute_reply.started":"2021-09-18T09:20:58.533879Z","shell.execute_reply":"2021-09-18T09:20:58.599216Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}