{"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)\nimport matplotlib.pyplot as plt\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#Other necessary libraries\n\nimport cv2\nimport tensorflow as tf\nfrom tensorflow.keras.preprocessing.image import load_img, img_to_array\nfrom sklearn.metrics import f1_score\nimport pyarrow.parquet as pq\n\n'''import torch\nfrom torch import nn\nimport torchvision\nfrom torchvision import transforms\nimport albumentations as A\nimport gc\nimport cv2\nfrom tqdm import tqdm\nimport sklearn.metrics\nimport json\n\nfrom tqdm.auto import tqdm\nimport sys\nfrom PIL import Image\nfrom joblib import Parallel, delayed'''\n\n\n# You can write up to 20GB 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":"2023-03-25T07:57:41.407293Z","iopub.execute_input":"2023-03-25T07:57:41.407617Z","iopub.status.idle":"2023-03-25T07:57:50.667780Z","shell.execute_reply.started":"2023-03-25T07:57:41.407586Z","shell.execute_reply":"2023-03-25T07:57:50.666797Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Load the parquet files into separate dataframes\ntrain_data_1 = pq.read_table('/kaggle/input/bengaliai-cv19/train_image_data_0.parquet').to_pandas()\ntrain_data_2 = pq.read_table('/kaggle/input/bengaliai-cv19/train_image_data_1.parquet').to_pandas()\ntrain_data_3 = pq.read_table('/kaggle/input/bengaliai-cv19/train_image_data_2.parquet').to_pandas()\ntrain_data_4 = pq.read_table('/kaggle/input/bengaliai-cv19/train_image_data_3.parquet').to_pandas()\n\n# Concatenate the dataframes into a single dataframe\ntrain_data = pd.concat([train_data_1, train_data_2, train_data_3, train_data_4])\n","metadata":{"execution":{"iopub.status.busy":"2023-03-25T07:58:09.544840Z","iopub.execute_input":"2023-03-25T07:58:09.546291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"execution":{"iopub.status.busy":"2023-03-25T08:04:42.215186Z","iopub.execute_input":"2023-03-25T08:04:42.215932Z","iopub.status.idle":"2023-03-25T08:04:42.288723Z","shell.execute_reply.started":"2023-03-25T08:04:42.215887Z","shell.execute_reply":"2023-03-25T08:04:42.287337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Extract image data from the dataframe\ntrain_images = np.asarray([np.asarray(x).reshape(137, 236) for x in train_data['image']])\n\n# Extract labels from the dataframe\ntrain_labels = train_data['label'].values","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_img0 = pd.read_parquet('../input/bengaliai-cv19/train_image_data_0.parquet')\ntrain_img1 = pd.read_parquet('../input/bengaliai-cv19/train_image_data_1.parquet')\ntrain_img2 = pd.read_parquet('../input/bengaliai-cv19/train_image_data_2.parquet')\ntrain_img3 = pd.read_parquet('../input/bengaliai-cv19/train_image_data_3.parquet')\n\n\ntrain_img0.shape","metadata":{"execution":{"iopub.status.busy":"2023-03-24T20:00:20.466392Z","iopub.execute_input":"2023-03-24T20:00:20.467363Z","iopub.status.idle":"2023-03-24T20:01:59.629069Z","shell.execute_reply.started":"2023-03-24T20:00:20.467318Z","shell.execute_reply":"2023-03-24T20:01:59.627822Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_img0.head()","metadata":{"execution":{"iopub.status.busy":"2023-03-24T20:01:59.630679Z","iopub.execute_input":"2023-03-24T20:01:59.631060Z","iopub.status.idle":"2023-03-24T20:01:59.679321Z","shell.execute_reply.started":"2023-03-24T20:01:59.631024Z","shell.execute_reply":"2023-03-24T20:01:59.677866Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img2 = train_img0.iloc[:,1:].values.reshape((-1,137,236,1))\n\nrow=3; col=4;\nplt.figure(figsize=(20,(row/col)*12))\nfor x in range(row*col):\n    plt.subplot(row,col,x+1)\n    plt.imshow(img2[x,:,:,0])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-24T20:01:59.680701Z","iopub.execute_input":"2023-03-24T20:01:59.681005Z","iopub.status.idle":"2023-03-24T20:02:05.052270Z","shell.execute_reply.started":"2023-03-24T20:01:59.680976Z","shell.execute_reply":"2023-03-24T20:02:05.050823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Sometimes we may want to resize the images for future analysis. We can use cv2 package.","metadata":{}},{"cell_type":"code","source":"DIM = 64\n\nimg3 = np.zeros((img2.shape[0],DIM,DIM,1),dtype='float32')\nfor j in range(img2.shape[0]):\n    img3[j,:,:,0] = cv2.resize(img2[j,],(DIM,DIM),interpolation = cv2.INTER_AREA)\n\nrow=3; col=4;\nplt.figure(figsize=(20,(row/col)*12))\nfor x in range(row*col):\n    plt.subplot(row,col,x+1)\n    plt.imshow(img3[x,:,:,0])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-24T20:02:05.055800Z","iopub.execute_input":"2023-03-24T20:02:05.056288Z","iopub.status.idle":"2023-03-24T20:03:13.104645Z","shell.execute_reply.started":"2023-03-24T20:02:05.056242Z","shell.execute_reply":"2023-03-24T20:03:13.103631Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/bengaliai-cv19/train.csv')","metadata":{"execution":{"iopub.status.busy":"2023-03-24T20:03:13.106073Z","iopub.execute_input":"2023-03-24T20:03:13.107041Z","iopub.status.idle":"2023-03-24T20:03:13.391682Z","shell.execute_reply.started":"2023-03-24T20:03:13.107004Z","shell.execute_reply":"2023-03-24T20:03:13.390368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2023-03-24T20:03:13.393083Z","iopub.execute_input":"2023-03-24T20:03:13.393474Z","iopub.status.idle":"2023-03-24T20:03:13.406550Z","shell.execute_reply.started":"2023-03-24T20:03:13.393430Z","shell.execute_reply":"2023-03-24T20:03:13.405300Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}