{"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 seaborn as sns\nimport os\nimport torch\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\n#import os\n#for 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 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":"2022-05-16T15:00:49.830355Z","iopub.execute_input":"2022-05-16T15:00:49.830677Z","iopub.status.idle":"2022-05-16T15:00:51.703092Z","shell.execute_reply.started":"2022-05-16T15:00:49.83059Z","shell.execute_reply":"2022-05-16T15:00:51.702274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"project = \"../input/hotel-id-to-combat-human-trafficking-2022-fgvc9/\"\ntest_data = project + \"test_images/\"\ntrain_data = project + 'train_images/'\ntrain_mask = project + 'train_masks/'","metadata":{"execution":{"iopub.status.busy":"2022-05-16T15:01:33.901954Z","iopub.execute_input":"2022-05-16T15:01:33.902236Z","iopub.status.idle":"2022-05-16T15:01:33.907501Z","shell.execute_reply.started":"2022-05-16T15:01:33.902206Z","shell.execute_reply":"2022-05-16T15:01:33.906604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Distribution of Class","metadata":{}},{"cell_type":"code","source":"df_cnt = pd.DataFrame(columns= ['Hotel_ID','Count'])\nfor dirname,_,filenames in os.walk(train_data):\n    cnt = pd.Series([dirname.split('/')[-1],len(filenames)],index=df_cnt.columns)\n    df_cnt = df_cnt.append(cnt,ignore_index=True)\ndf_cnt = df_cnt.iloc[1:,]","metadata":{"execution":{"iopub.status.busy":"2022-04-23T09:02:24.460015Z","iopub.execute_input":"2022-04-23T09:02:24.46028Z","iopub.status.idle":"2022-04-23T09:02:56.478267Z","shell.execute_reply.started":"2022-04-23T09:02:24.460252Z","shell.execute_reply":"2022-04-23T09:02:56.477166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sum(df_cnt['Count'])","metadata":{"execution":{"iopub.status.busy":"2022-04-23T09:02:56.528645Z","iopub.execute_input":"2022-04-23T09:02:56.529235Z","iopub.status.idle":"2022-04-23T09:02:56.542479Z","shell.execute_reply.started":"2022-04-23T09:02:56.52919Z","shell.execute_reply":"2022-04-23T09:02:56.541745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.boxplot(df_cnt.Count)","metadata":{"execution":{"iopub.status.busy":"2022-04-20T17:10:51.243627Z","iopub.status.idle":"2022-04-20T17:10:51.243961Z","shell.execute_reply.started":"2022-04-20T17:10:51.243787Z","shell.execute_reply":"2022-04-20T17:10:51.243807Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Based on the above boxplot, there are definitely imbalance among classes.","metadata":{"execution":{"iopub.status.busy":"2022-04-19T22:46:21.722809Z","iopub.execute_input":"2022-04-19T22:46:21.723505Z","iopub.status.idle":"2022-04-19T22:46:21.737252Z","shell.execute_reply.started":"2022-04-19T22:46:21.723442Z","shell.execute_reply":"2022-04-19T22:46:21.736311Z"}}},{"cell_type":"code","source":"df_cnt = df_cnt.sort_values(by='Count',ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-04-20T17:10:51.245472Z","iopub.status.idle":"2022-04-20T17:10:51.246168Z","shell.execute_reply.started":"2022-04-20T17:10:51.245982Z","shell.execute_reply":"2022-04-20T17:10:51.246003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"hist = sns.histplot(df_cnt.Count)\nhist.set_xlim(0,50)","metadata":{"execution":{"iopub.status.busy":"2022-04-20T17:10:51.247372Z","iopub.status.idle":"2022-04-20T17:10:51.248151Z","shell.execute_reply.started":"2022-04-20T17:10:51.24793Z","shell.execute_reply":"2022-04-20T17:10:51.247956Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"A major of number of observations in each class are distributed between 0 and 20. ","metadata":{}},{"cell_type":"markdown","source":"## Image","metadata":{"execution":{"iopub.status.busy":"2022-04-19T23:02:49.130123Z","iopub.execute_input":"2022-04-19T23:02:49.130514Z","iopub.status.idle":"2022-04-19T23:02:49.135659Z","shell.execute_reply.started":"2022-04-19T23:02:49.130455Z","shell.execute_reply":"2022-04-19T23:02:49.134465Z"}}},{"cell_type":"code","source":"df_add = pd.DataFrame(columns=['Image_ID','Hotel_ID'])\nfor dirname,_,filenames in os.walk(train_data):\n    for filename in filenames:\n        add = pd.Series([filename,dirname.split('/')[-1]],index=df_add.columns)\n        df_add = df_add.append(add,ignore_index=True)","metadata":{"execution":{"iopub.status.busy":"2022-04-20T17:10:51.249303Z","iopub.status.idle":"2022-04-20T17:10:51.249865Z","shell.execute_reply.started":"2022-04-20T17:10:51.249661Z","shell.execute_reply":"2022-04-20T17:10:51.249683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from PIL import Image\ndef get_dims(file):\n    '''Returns dimenstions for an RBG image'''\n    im = Image.open(file)\n    arr = np.array(im)\n    h,w,d = arr.shape\n    return [h,w]","metadata":{"execution":{"iopub.status.busy":"2022-04-20T17:10:51.250873Z","iopub.status.idle":"2022-04-20T17:10:51.251435Z","shell.execute_reply.started":"2022-04-20T17:10:51.251216Z","shell.execute_reply":"2022-04-20T17:10:51.251239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filename = os.path.join(df_add.iloc[0,1],df_add.iloc[0,0])\nget_dims(os.path.join(train_data,filename))","metadata":{"execution":{"iopub.status.busy":"2022-04-20T17:10:51.252503Z","iopub.status.idle":"2022-04-20T17:10:51.253032Z","shell.execute_reply.started":"2022-04-20T17:10:51.252845Z","shell.execute_reply":"2022-04-20T17:10:51.252868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_dim = pd.DataFrame(columns=['Image_ID','Height','Width'])\nfor index,row in df_add.iterrows():\n    filename = os.path.join(row['Hotel_ID'],row['Image_ID'].split('/')[-1])\n    dim = get_dims(os.path.join(train_data,filename))\n    dim.insert(0,filename)\n    id_dim = pd.Series(dim,index=['Image_ID','Height','Width'])\n    df_dim = df_dim.append(id_dim,ignore_index=True)","metadata":{"execution":{"iopub.status.busy":"2022-04-20T17:10:51.254074Z","iopub.status.idle":"2022-04-20T17:10:51.254585Z","shell.execute_reply.started":"2022-04-20T17:10:51.254345Z","shell.execute_reply":"2022-04-20T17:10:51.254373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for id,row in df_dim.iterrows():\n   row['Image_ID'] = row['Image_ID'].split('/')[-1]","metadata":{"execution":{"iopub.status.busy":"2022-04-20T17:10:51.255626Z","iopub.status.idle":"2022-04-20T17:10:51.256009Z","shell.execute_reply.started":"2022-04-20T17:10:51.255783Z","shell.execute_reply":"2022-04-20T17:10:51.255828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_dim['Dim'] = df_dim['Height'].astype('str') + 'x' + df_dim['Width'].astype('str')","metadata":{"execution":{"iopub.status.busy":"2022-04-20T17:10:51.257426Z","iopub.status.idle":"2022-04-20T17:10:51.257758Z","shell.execute_reply.started":"2022-04-20T17:10:51.257587Z","shell.execute_reply":"2022-04-20T17:10:51.257604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_dim['Dim'].value_counts()[1:20]","metadata":{"execution":{"iopub.status.busy":"2022-04-20T17:10:51.258672Z","iopub.status.idle":"2022-04-20T17:10:51.25899Z","shell.execute_reply.started":"2022-04-20T17:10:51.258824Z","shell.execute_reply":"2022-04-20T17:10:51.258843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(os.listdir('../input/checkpoint'))","metadata":{"execution":{"iopub.status.busy":"2022-05-16T15:02:29.279127Z","iopub.execute_input":"2022-05-16T15:02:29.27967Z","iopub.status.idle":"2022-05-16T15:02:29.289945Z","shell.execute_reply.started":"2022-05-16T15:02:29.279621Z","shell.execute_reply":"2022-05-16T15:02:29.289239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"checkpoint = torch.load('../input/checkpoint/checkpoint.pth')","metadata":{"execution":{"iopub.status.busy":"2022-05-02T12:22:27.806089Z","iopub.execute_input":"2022-05-02T12:22:27.80662Z","iopub.status.idle":"2022-05-02T12:22:27.956484Z","shell.execute_reply.started":"2022-05-02T12:22:27.806581Z","shell.execute_reply":"2022-05-02T12:22:27.955635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"checkpoint","metadata":{"execution":{"iopub.status.busy":"2022-05-02T12:22:30.324502Z","iopub.execute_input":"2022-05-02T12:22:30.324779Z","iopub.status.idle":"2022-05-02T12:22:30.444901Z","shell.execute_reply.started":"2022-05-02T12:22:30.324751Z","shell.execute_reply":"2022-05-02T12:22:30.444044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Initial Setup","metadata":{}},{"cell_type":"code","source":"print(os.listdir(project))","metadata":{"execution":{"iopub.status.busy":"2022-05-16T15:02:03.147947Z","iopub.execute_input":"2022-05-16T15:02:03.148251Z","iopub.status.idle":"2022-05-16T15:02:03.154424Z","shell.execute_reply.started":"2022-05-16T15:02:03.148219Z","shell.execute_reply":"2022-05-16T15:02:03.15373Z"},"trusted":true},"execution_count":null,"outputs":[]}]}