{"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\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-03T02:46:33.028761Z","iopub.execute_input":"2022-05-03T02:46:33.029183Z","iopub.status.idle":"2022-05-03T02:46:33.059471Z","shell.execute_reply.started":"2022-05-03T02:46:33.029086Z","shell.execute_reply":"2022-05-03T02:46:33.058756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls\n# !rm -r \"acm-ai-project-2022-spring\"\n!git clone \"https://github.com/yuesha-yc/acm-ai-project-2022-spring\"","metadata":{"execution":{"iopub.status.busy":"2022-05-03T02:46:33.062246Z","iopub.execute_input":"2022-05-03T02:46:33.063893Z","iopub.status.idle":"2022-05-03T02:46:35.178893Z","shell.execute_reply.started":"2022-05-03T02:46:33.063863Z","shell.execute_reply":"2022-05-03T02:46:35.178104Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\n\nDATA_PATH = \"/kaggle/input/humpback-whale-identification\"\n\ntrain_df = pd.read_csv(DATA_PATH + \"/train.csv\")\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-03T02:46:35.181132Z","iopub.execute_input":"2022-05-03T02:46:35.181399Z","iopub.status.idle":"2022-05-03T02:46:35.236167Z","shell.execute_reply.started":"2022-05-03T02:46:35.181362Z","shell.execute_reply":"2022-05-03T02:46:35.235469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%cd /kaggle/working/acm-ai-project-2022-spring\n\nimport torch\n\nimport constants\nfrom data.StartingDataset import StartingDataset\nfrom networks.StartingNetwork import StartingNetwork\nfrom train_functions.starting_train import starting_train","metadata":{"execution":{"iopub.status.busy":"2022-05-03T02:46:35.237508Z","iopub.execute_input":"2022-05-03T02:46:35.237755Z","iopub.status.idle":"2022-05-03T02:46:36.935241Z","shell.execute_reply.started":"2022-05-03T02:46:35.237722Z","shell.execute_reply":"2022-05-03T02:46:36.934493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"if torch.cuda.is_available(): # Check if GPU is available\n    device = torch.device('cuda:0')\n    print(\"Using GPU\")\nelse:\n    device = torch.device('cpu')\n    print(\"Using CPU\")","metadata":{"execution":{"iopub.status.busy":"2022-05-03T02:46:36.93731Z","iopub.execute_input":"2022-05-03T02:46:36.937528Z","iopub.status.idle":"2022-05-03T02:46:37.019785Z","shell.execute_reply.started":"2022-05-03T02:46:36.937496Z","shell.execute_reply":"2022-05-03T02:46:37.018839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"HYPERPARAMETERS = {\n    \"epochs\": 5,\n    \"batch_size\": 32,\n}\nN_EVAL = 100\n\ntrain = train_df.iloc[0:1000]\ntest = train_df.iloc[1001:2000]\ntrain_dataset = StartingDataset(train)\nval_dataset = StartingDataset(test)","metadata":{"execution":{"iopub.status.busy":"2022-05-03T02:46:37.021348Z","iopub.execute_input":"2022-05-03T02:46:37.021658Z","iopub.status.idle":"2022-05-03T02:47:23.672451Z","shell.execute_reply.started":"2022-05-03T02:46:37.021616Z","shell.execute_reply":"2022-05-03T02:47:23.671727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = StartingNetwork()\nstarting_train(\n    train_dataset=train_dataset,\n    val_dataset=val_dataset,\n    model=model,\n    hyperparameters=HYPERPARAMETERS,\n    n_eval=N_EVAL,\n)","metadata":{"execution":{"iopub.status.busy":"2022-05-03T02:47:23.673913Z","iopub.execute_input":"2022-05-03T02:47:23.674161Z","iopub.status.idle":"2022-05-03T02:47:38.736711Z","shell.execute_reply.started":"2022-05-03T02:47:23.674129Z","shell.execute_reply":"2022-05-03T02:47:38.735749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Use Tensorboard to save a log file\n\nimport numpy as np\nfrom torch.utils.tensorboard import SummaryWriter\n\nOUTPUT_DIR = \"/kaggle/working\"\n\nwriter = SummaryWriter(OUTPUT_DIR + \"/logs\")\nfor i in range(100):\n    writer.add_scalar(\"Test\", np.random.random(), i)","metadata":{"execution":{"iopub.status.busy":"2022-05-03T02:47:38.738175Z","iopub.execute_input":"2022-05-03T02:47:38.738894Z","iopub.status.idle":"2022-05-03T02:47:43.23775Z","shell.execute_reply.started":"2022-05-03T02:47:38.738853Z","shell.execute_reply":"2022-05-03T02:47:43.23699Z"},"trusted":true},"execution_count":null,"outputs":[]}]}