{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":112509,"databundleVersionId":14254895,"isSourceIdPinned":false,"sourceType":"competition"},{"sourceId":14156308,"sourceType":"datasetVersion","datasetId":8715355},{"sourceId":14157048,"sourceType":"datasetVersion","datasetId":8780493}],"dockerImageVersionId":31192,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# CSIRO - Image2Biomass Prediction\n### Predicting biomass using pasture images\n**Alicia Simmons - DSCI 598**\n\nCompetition Page: https://www.kaggle.com/competitions/csiro-biomass/overview \n\n**Notebook Links**\n- Data Augmentation: https://www.kaggle.com/code/aliciarsimmons/as-csiro-image2biomass-data-preprocessing\n- Model Training: https://www.kaggle.com/code/aliciarsimmons/as-csiro-image2biomass-training-v02\n- Submission: https://www.kaggle.com/code/aliciarsimmons/as-csiro-image2biomass-submission-v02 ","metadata":{}},{"cell_type":"markdown","source":"# 0. Competition and Project Overview\n\n**Competition Overview:**\n\nCompetition Page: https://www.kaggle.com/competitions/csiro-biomass/overview \n\nThe goal of the competition is to create a model that, given an image, will predict 5 measures of pasture biomass:\n* dry_green_g (grams of dry green vegetation, excluding clover)\n* dry_dead_g (grams of dry dead material)\n* dry_clover_g (grams of dry clover biomass)\n* gdm_g (grams of green dry matter)\n* dry_total_g (grams of total dry biomass)\n\nThe training dataset contains 357 images. There is 1 image in the visable test dataset, and submission notebooks are re-run on a hidden test dataset to determine the competition score. The competition score is a weighted R-squared value, with the most weight placed on dry_total_g.\n\n**Project Overview:**\n\nMy final project consists of 3 notebooks and 2 intermediate datasets, with the flow between them working as follows:\n\nData Augmentation Notebook --> Augmented Images Dataset --> Training Notebook --> Models Dataset --> Submission Notebook\n\n","metadata":{}},{"cell_type":"markdown","source":"# 1. Data Augmentation\n\nNotebook: https://www.kaggle.com/code/aliciarsimmons/as-csiro-image2biomass-data-preprocessing\n\nA challenge of this project was the limited dataset size. To address this challenge, I used image transformations to augment the training data. I tried various transformations and combinations thereof, and found the best performance with very controlled changes. I settled on performing the following transformations to each image, creating a bolstered dataset of 1428 images:\n1. No Change\n2. Vertical Flip\n3. Horizontal Flip\n4. Random brightness change between 20% darker and 20% lighter","metadata":{}},{"cell_type":"markdown","source":"# 2. Model Development and Training\nNotebook: https://www.kaggle.com/code/aliciarsimmons/as-csiro-image2biomass-training-v02\n\nMy initial approach was to have 5 seperate training notebooks to create 5 seperate models, one for each of the target variables. The best score I achieved with this approach was a 0.35. However, I quickly realized that this was an inefficient approach. \n\nI switched to a different approach, predicting all 5 targets with one model. While this initially produced lower scores than I had achieved previously, I stuck with it as it would be much easier for me to work on one consolidated model with the limited time I had in this class.\n\nI also realized that there are direct relationships between the 5 target variables, such that 2 of them could be calculated directly using the other 3. So to simplify the model, I only predicted for these 3 component variables.\n\nI utilized transfer learning, starting with a ResNet50 model and building off from there. A key insight that helped me was understanding to first train the layers I added to modify the base model for the regression task, then to unfreeze later blocks and recompile the model using a smaller learning rate and batch size and train again to fine-tune.\n\nWhen I was unable to achieve scores even as high as I had produced with the 5-model approach, I began experimenting with other pretrained models. I tried InceptionV3, VGG16, and EfficientNetB0. The model using EfficientNet was a substantial improvement over the previous models, and I was able to achieve my best score of 0.41 using EfficientNetB0 as a base model to build off of.","metadata":{}},{"cell_type":"markdown","source":"# 3. Submission Formatting\n\nNotebook: https://www.kaggle.com/code/aliciarsimmons/as-csiro-image2biomass-submission-v02\n\nThe final step in my project flow was predicting on the test set and formatting the predictions for submission. This involved a lot of re-organization and re-structuring. It was also difficult to make sure my code would work for the larger hidden test set, since the given test set is only one image. I worked around this by using the train dataset to ensure that the code worked on data with more than one image, before switching back to using the test dataset. I also had to tweak the batch size of the test data object to help the notebook run efficiently during submission.","metadata":{}},{"cell_type":"markdown","source":"# Final Thoughts\n\nThis project was a difficult journey for me. Long training times meant there was only so much I could try in the limited times I had to work on it. I also ran into a number of hurtles and challenges. \n\nA lot of my time went to waste on a scrapped endeveour to develop a classification model to preceed by regression model. I spent the better part of two weeks on this task, but failed to develop a model that gave any useful information; they all ended up classifying all of the images into a single category.\n\nOverall, I am proud of my perserverence and the results it yielded. At time of writing, the highest score on the leaderboard in 0.77 and my best score is 0.41, placing me at 1,510th out of 2,014 entrants. I am satisfied with this result, and proud of all of the time and hard work that went into it. I have gained a new depth of understanding for image processing, neural networks, and project flow.","metadata":{}}]}