{"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 - Leaf Us Alone\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\nFor more resources, feel free to check out the following: \n* [Project Skeleton Code (Repo)](https://github.com/uclaacmai/projects-skeleton-code)\n* [Project Skeleton Notebook (Kaggle)](https://www.kaggle.com/advitdeepak/leaf-us-alone)\n* [Cassava Leaf Disease Challenge (Kaggle)](https://www.kaggle.com/c/cassava-leaf-disease-classification)","metadata":{}},{"cell_type":"code","source":"!git clone \"https://github.com/uclaacmai/leaf-us-alone\"\n\n!ls leaf-us-alone","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-02-11T04:03:30.946543Z","iopub.execute_input":"2022-02-11T04:03:30.946807Z","iopub.status.idle":"2022-02-11T04:03:33.278142Z","shell.execute_reply.started":"2022-02-11T04:03:30.946725Z","shell.execute_reply":"2022-02-11T04:03:33.277324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%cd /kaggle/working/leaf-us-alone\n\nimport torch, os \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-11T04:03:37.296624Z","iopub.execute_input":"2022-02-11T04:03:37.297361Z","iopub.status.idle":"2022-02-11T04:03:39.247846Z","shell.execute_reply.started":"2022-02-11T04:03:37.297318Z","shell.execute_reply":"2022-02-11T04:03:39.24709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import constants\nprint(constants)\n\n%ls","metadata":{"execution":{"iopub.status.busy":"2022-02-11T04:03:43.25812Z","iopub.execute_input":"2022-02-11T04:03:43.258373Z","iopub.status.idle":"2022-02-11T04:03:43.918129Z","shell.execute_reply.started":"2022-02-11T04:03:43.258344Z","shell.execute_reply":"2022-02-11T04:03:43.917342Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"hyperparameters = {\"epochs\": constants.EPOCHS, \"batch_size\": constants.BATCH_SIZE, \"data_dir\": constants.DATA_DIR}\n\n# Create path for training summaries\nsummary_path = None\nif constants.LOG_DIR is not None:\n    summary_path = f\"{constants.SUMMARIES_PATH}/{constants.LOG_DIR}\"\n    os.makedirs(summary_path, exist_ok=True)\n\n# Use GPU, if available\ndevice = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n\n# Print out training information \nprint(\"\\n----------------- Summary Information --------------------\")\nprint(f\"\\nSummary path: {summary_path}\")\nprint(f\"   Data path: {constants.DATA_DIR}\\n\")\nprint(f\"Epochs: {constants.EPOCHS}\")\nprint(f\"    Evaluate: {constants.N_EVAL}\")\nprint(f\"  Save Model: {constants.SAVE_INTERVAL} \\n\")\n\nprint(f\"Training imgs: {constants.TRAIN_NUM * constants.IMG_TYPES}\")\nprint(f\" Testing imgs: {constants.TEST_NUM * constants.IMG_TYPES}\")\nprint(f\"   Batch size: {constants.BATCH_SIZE}\\n\")\nprint(\"----------------------------------------------------------\")\n\nconstants.DATA_DIR = \"/kaggle/input/cassava-leaf-disease-classification/\"\n\n# Initalize dataset and model. Then train the model!\ncsv_path = constants.DATA_DIR +'train.csv'\ntrain_dataset = StartingDataset(csv_path)\nval_dataset = StartingDataset(csv_path, training_set = False)\n\n# Create our model, and begin starting_train()\nmodel = StartingNetwork()\nstarting_train(\n    train_dataset=train_dataset,\n    val_dataset=val_dataset,\n    model=model,\n    hyperparameters=hyperparameters,\n    n_eval=constants.N_EVAL,\n    summary_path=summary_path,\n)","metadata":{"execution":{"iopub.status.busy":"2022-02-11T04:03:47.948143Z","iopub.execute_input":"2022-02-11T04:03:47.948496Z"},"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-02-10T08:27:10.285596Z","iopub.execute_input":"2022-02-10T08:27:10.286067Z","iopub.status.idle":"2022-02-10T08:27:16.872951Z","shell.execute_reply.started":"2022-02-10T08:27:10.285975Z","shell.execute_reply":"2022-02-10T08:27:16.871988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = StartingNetwork()\nmodel = model.to(device)","metadata":{"execution":{"iopub.status.busy":"2022-02-11T03:55:34.442226Z","iopub.execute_input":"2022-02-11T03:55:34.443024Z","iopub.status.idle":"2022-02-11T03:55:34.690476Z","shell.execute_reply.started":"2022-02-11T03:55:34.442972Z","shell.execute_reply":"2022-02-11T03:55:34.68977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"torch.device('cuda:0')","metadata":{"execution":{"iopub.status.busy":"2022-02-11T04:00:42.831077Z","iopub.execute_input":"2022-02-11T04:00:42.831332Z","iopub.status.idle":"2022-02-11T04:00:42.83654Z","shell.execute_reply.started":"2022-02-11T04:00:42.831298Z","shell.execute_reply":"2022-02-11T04:00:42.835856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%cd logs","metadata":{"execution":{"iopub.status.busy":"2022-02-10T08:29:18.144943Z","iopub.execute_input":"2022-02-10T08:29:18.145284Z","iopub.status.idle":"2022-02-10T08:29:18.152835Z","shell.execute_reply.started":"2022-02-10T08:29:18.145252Z","shell.execute_reply":"2022-02-10T08:29:18.151617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%ls","metadata":{"execution":{"iopub.status.busy":"2022-02-10T08:29:24.575392Z","iopub.execute_input":"2022-02-10T08:29:24.575762Z","iopub.status.idle":"2022-02-10T08:29:25.340992Z","shell.execute_reply.started":"2022-02-10T08:29:24.575725Z","shell.execute_reply":"2022-02-10T08:29:25.339807Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import shutil\nshutil.rmtree(\"/kaggle/working/leaf-us-alone\")","metadata":{"execution":{"iopub.status.busy":"2022-02-11T04:02:47.029948Z","iopub.execute_input":"2022-02-11T04:02:47.030504Z","iopub.status.idle":"2022-02-11T04:02:47.038123Z","shell.execute_reply.started":"2022-02-11T04:02:47.030462Z","shell.execute_reply":"2022-02-11T04:02:47.037215Z"},"trusted":true},"execution_count":null,"outputs":[]}]}