{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-02-03T08:36:46.886939Z","iopub.execute_input":"2022-02-03T08:36:46.887293Z","iopub.status.idle":"2022-02-03T08:36:46.926773Z","shell.execute_reply.started":"2022-02-03T08:36:46.887263Z","shell.execute_reply":"2022-02-03T08:36:46.925976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\ncount = 0\nd = \"/kaggle/input/wettruckdata/wet\"\nfor path in os.listdir(d):\n    if os.path.isfile(os.path.join(d, path)):\n        count += 1\nprint (count)\n#OUTPUT","metadata":{"execution":{"iopub.status.busy":"2022-02-03T08:37:12.387896Z","iopub.execute_input":"2022-02-03T08:37:12.388227Z","iopub.status.idle":"2022-02-03T08:37:12.458477Z","shell.execute_reply.started":"2022-02-03T08:37:12.388198Z","shell.execute_reply":"2022-02-03T08:37:12.457496Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install -U efficientnet","metadata":{"execution":{"iopub.status.busy":"2022-02-03T08:27:01.986400Z","iopub.execute_input":"2022-02-03T08:27:01.986718Z","iopub.status.idle":"2022-02-03T08:27:09.613658Z","shell.execute_reply.started":"2022-02-03T08:27:01.986688Z","shell.execute_reply":"2022-02-03T08:27:09.612798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from efficientnet.keras import EfficientNetB7\nfrom keras.preprocessing import image\nfrom efficientnet.keras import preprocess_input\nfrom keras.models import Model\nimport numpy as np\n\nbase_model = EfficientNetB7(weights='imagenet')\n#base_model.summary()\nmodel = Model(inputs=[base_model.input], outputs=[base_model.get_layer('probs').output])\nmodel.summary()","metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","execution":{"iopub.status.busy":"2022-02-03T08:37:21.420009Z","iopub.execute_input":"2022-02-03T08:37:21.420324Z","iopub.status.idle":"2022-02-03T08:37:32.424270Z","shell.execute_reply.started":"2022-02-03T08:37:21.420295Z","shell.execute_reply":"2022-02-03T08:37:32.423480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#os.mkdir('/kaggle/working/rsna_converted_stage_2_train_images/')\n#os.mkdir('/kaggle/working/rsna_converted_stage_2_test_images/')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#import pydicom as dicom\n#import os\n#import cv2\n#import PIL # optional\n# make it True if you want in PNG format\n#PNG = False\n# Specify the .dcm folder path\n#folder_path = \"/kaggle/input/rsna-pneumonia-detection-challenge/stage_2_train_images/\"\n# Specify the output jpg/png folder path\n#jpg_folder_path = \"/kaggle/working/rsna_converted_stage_2_train_images/\"\n#images_path = os.listdir(folder_path)\n#for n, image in enumerate(images_path):\n #   ds = dicom.dcmread(os.path.join(folder_path, image))\n  #  pixel_array_numpy = ds.pixel_array\n   # if PNG == False:\n    #    image = image.replace('.dcm', '.jpg')\n    #else:\n     #   image = image.replace('.dcm', '.png')\n    #cv2.imwrite(os.path.join(jpg_folder_path, image), pixel_array_numpy)\n    #if n % 50 == 0:\n     #   print('{} image converted'.format(n))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from glob import glob\nimagePatches = glob('/kaggle/input/wettruckdata/wet/*.png', recursive=True)#imagePatches = glob('/kaggle/input/chest-xray-pneumonia/chest_xray/train/NORMAL/*.jpeg', recursive=True)\n\nfeatures = []\nimagenumber = []\nfor img in imagePatches:\n        imagenumber.append(img)\n        img_data = image.load_img(img, target_size=(600, 600))\n        img_data = image.img_to_array(img_data)\n        img_data = np.expand_dims(img_data, axis=0)\n        img_data = preprocess_input(img_data)\n        feats = model.predict(img_data)\n        features.append(feats.flatten())\nfeature = np.array(features)\nfeatures_deep = pd.DataFrame(feature)\nnmbr = np.array(imagenumber)\nimg_no = pd.DataFrame(nmbr)\nimg_no.to_csv('img_no_wet_truck_png.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2022-02-03T08:37:53.921302Z","iopub.execute_input":"2022-02-03T08:37:53.921636Z","iopub.status.idle":"2022-02-03T08:38:23.818848Z","shell.execute_reply.started":"2022-02-03T08:37:53.921606Z","shell.execute_reply":"2022-02-03T08:38:23.817859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#imagePatches","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"features_deep","metadata":{"execution":{"iopub.status.busy":"2022-02-03T08:38:28.841807Z","iopub.execute_input":"2022-02-03T08:38:28.842150Z","iopub.status.idle":"2022-02-03T08:38:28.876559Z","shell.execute_reply.started":"2022-02-03T08:38:28.842119Z","shell.execute_reply":"2022-02-03T08:38:28.875527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import MinMaxScaler\ndata = feature\nscaler = MinMaxScaler()\nscaler.fit(data)\nfeatures = scaler.transform(data)\nnormalized = pd.DataFrame(features)","metadata":{"execution":{"iopub.status.busy":"2022-02-03T08:38:40.719549Z","iopub.execute_input":"2022-02-03T08:38:40.719913Z","iopub.status.idle":"2022-02-03T08:38:40.729150Z","shell.execute_reply.started":"2022-02-03T08:38:40.719880Z","shell.execute_reply":"2022-02-03T08:38:40.728276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"normalized","metadata":{"execution":{"iopub.status.busy":"2022-02-03T08:38:52.543715Z","iopub.execute_input":"2022-02-03T08:38:52.544218Z","iopub.status.idle":"2022-02-03T08:38:52.598664Z","shell.execute_reply.started":"2022-02-03T08:38:52.544166Z","shell.execute_reply":"2022-02-03T08:38:52.597799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"normalized.to_csv('normalized_wet_trunk_png.csv',index=False) ","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}