{"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":"markdown","source":"# ACM AI Projects Kaggle Skeleton\n\nTo turn on the GPU, click the three dots in the top-right corner and select “Accelerator” > “GPU.” To run the notebook without needing to keep your browser open, click “Save Version.” Once your notebook is done running, you should be able to view any output files from the “Data” tab after clicking on your notebook.\n\n## Clone GitHub repository\n\nGitHub link: https://github.com/uclaacmai/projects-skeleton-code","metadata":{}},{"cell_type":"code","source":"!git clone \"https://github.com/RadEagle/projects-skeleton-code.git\"\n\n!ls projects-skeleton-code","metadata":{"execution":{"iopub.status.busy":"2022-02-11T05:26:21.020794Z","iopub.execute_input":"2022-02-11T05:26:21.021269Z","iopub.status.idle":"2022-02-11T05:26:23.146073Z","shell.execute_reply.started":"2022-02-11T05:26:21.021234Z","shell.execute_reply":"2022-02-11T05:26:23.145319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Sample Code\n\n### Reading `train.csv`\n\nAccessing data from this notebook is the same as how you would do it on your local machine! All the data is placed in the `\"/kaggle/input/cassava-leaf-disease-classification\"` folder.","metadata":{}},{"cell_type":"code","source":"import pandas as pd\n\nDATA_PATH = \"/kaggle/input/cassava-leaf-disease-classification\"\n\ntrain_df = pd.read_csv(DATA_PATH + \"/train.csv\")\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-11T05:26:23.147931Z","iopub.execute_input":"2022-02-11T05:26:23.148206Z","iopub.status.idle":"2022-02-11T05:26:23.173713Z","shell.execute_reply.started":"2022-02-11T05:26:23.148167Z","shell.execute_reply":"2022-02-11T05:26:23.173093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Running Your Code\n\nYou can also import directly from Python files! Just make sure your current directory is your GitHub repository before you make any imports.","metadata":{}},{"cell_type":"code","source":"%cd /kaggle/working/projects-skeleton-code\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-02-11T05:26:25.890397Z","iopub.execute_input":"2022-02-11T05:26:25.89068Z","iopub.status.idle":"2022-02-11T05:26:27.999371Z","shell.execute_reply.started":"2022-02-11T05:26:25.890645Z","shell.execute_reply":"2022-02-11T05:26:27.998589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install tqdm","metadata":{"execution":{"iopub.status.busy":"2022-02-08T02:27:05.349083Z","iopub.execute_input":"2022-02-08T02:27:05.349674Z","iopub.status.idle":"2022-02-08T02:27:13.871804Z","shell.execute_reply.started":"2022-02-08T02:27:05.349635Z","shell.execute_reply":"2022-02-08T02:27:13.871005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")","metadata":{"execution":{"iopub.status.busy":"2022-02-11T05:26:30.213788Z","iopub.execute_input":"2022-02-11T05:26:30.214496Z","iopub.status.idle":"2022-02-11T05:26:30.265727Z","shell.execute_reply.started":"2022-02-11T05:26:30.214456Z","shell.execute_reply":"2022-02-11T05:26:30.264809Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!python main.py","metadata":{"execution":{"iopub.status.busy":"2022-02-11T05:26:33.313275Z","iopub.execute_input":"2022-02-11T05:26:33.314117Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"HYPERPARAMETERS = {\n    \"epochs\": 5,\n    \"batch_size\": 32,\n}\nN_EVAL = 100\n\ntrain_dataset = StartingDataset()\nval_dataset = StartingDataset()\nmodel = 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":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Output\n\nIf you would like to save anything after your training is done (e.g., log files, model parameters, etc.), make sure to save it into the `\"/kaggle/working\"` folder.","metadata":{}},{"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":{"trusted":true},"execution_count":null,"outputs":[]}]}