Git Product home page Git Product logo

albertopirillo / anndl-challenges-2023 Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 17.38 MB

Collection of two projects applying Deep Neural Networks on real-world problems. The first one with CNNs for image recognition and the other with RNNs and 1D-CNNs for timeseries forecasting.

License: MIT License

Jupyter Notebook 99.92% Python 0.08%
deep-neural-networks image-recognition timeseries-forecasting

anndl-challenges-2023's Introduction

Deep Neural Networks Competitions

This repository contains the code used in the two competitions of the Artificial Neural Networks and Deep Learning (ANNDL) course during the academic year 2023-2024 at Politecnico di Milano. The code for both projects is implemented in Python and relies mainly on the Keras and TensorFlow libraries.

The two topics are:

Image classification

This project focuses on an image recognition problem, a sub-field of computer vision that involves building Machine Learning models capable of interpreting and understanding the semantic information contained in an image. More in detail, the task is to develop Convolutional Neural Networks (CNNs) to classify the health condition of plants based on a picture. Thus, this can be considered a binary classification problem, where the goal is to distinguish between healthy and unhealthy plants.

Data Preprocessing

The first step inspecting and cleaning the dataset, removing outliers that did not represent plants. The dataset was split into training and validation sets using stratified sampling to maintain class distribution, with the final evaluation conducted on a hidden test set. Several data augmentation techniques were applied, including translations, rotations, zooms, flips, and adjustments to contrast and brightness.

Model Development

Initially, baseline models based on LeNet and VGG architectures were developed, achieving a validation accuracy of around $0.80$. To enhance performance, techniques like Dropout, Batch Normalization, and the AdamW optimizer were incorporated. Recognizing the need for more sophisticated models, the Transfer Learning parading was employed, leading to the re-use of the feature extractor of advanced architectures like EfficientNetV2 and ConvNeXt. These pre-trained models were also fine-tuned using the task's dataset, significantly improving accuracy.

Prediction

Ensemble Methods

To further boost performance, eventually ensemble methods were explored, combining multiple models to enhance prediction accuracy. The final ensemble, consisting of EfficientNetV2B0, EfficientNetV2L, and ConvNeXtBase, achieved the best results with a validation accuracy of $0.89$.

Confusion matrix

Timeseries forecasting

This projects consists in a timeseries forecasting problem, which involves analyzing timeseries data using statistics and modelling to predict the future values of a variable of interest based on its historical observations. The dataset consisted of multiple univariate timeseries from six different domains: demography, finance, industry, macroeconomy, microeconomy, and others. The objective was to build a model that could generalize well across different timeseries, predicting the next values in the sequence accurately. Specifically, the model needed to process a timeseries of length 200 and predict the next 9-18 values.

Data Preprocessing

The first step was cleaning the dataset and removing padding from the timeseries. On average, the valid length of the timeseries was found to be about 198, with most of the timeseries having a length smaller than 500.

Dataset inspection

Each timeseries was split into input-output pairs using a sliding window approach, with a window of 200 time steps and a forecast horizon of 9 steps. This process involved creating overlapping segments of the data to ensure the model could learn from various parts of each timeseries.

Model Development

Several architectures were experimented with:

  • Recurrent Neural Networks (RNNs): initially LSTM-based and GRU-based models were tested, finding GRUs (specifically bidirectional GRUs) more effective in capturing temporal dependencies

  • 1D Convolutional Neural Networks (1D-CNNs): this architecture was tested for its ability to capture local patterns within the sequence. A combination of 1D-CNNs and GRUs yielded significant improvements

  • Temporal Convolutional Networks (TCNs): these networks, based on dilated causal convolutions, were explored but ultimately abandoned due to lower test set performance

  • LSTMs with Attention: implementing an attention mechanism improved the model's performance, allowing it to place more focus on the most important parts of the input sequence

  • Transformers: despite their potential, transformers did not perform well on the test set and had high training times, and therefore they were not used in the final model

Autoregressive Model

To handle varying prediction horizons between phases, an autoregressive model was developed. This model generates predictions iteratively, using its output as the input for the next prediction batch. This allowed to extend the prediction horizon to 18 values without retraining the model.

Autoregressive prediction

Ensemble Methods

Combining different models through ensemble techniques significantly boosted performance. The final model was an ensemble of the following architectures: Bidirectional GRUs with 1D Convolutions, ResNet-like 1D-CNN, and LSTMs with Attention. This ensemble achieved an MSE of $0.0043$ on the hidden test set.

Setup

The projects were developed using Python 3.10 and Tensorflow/Keras 2.14.0 and 2.15.0.

Clone the repository and install all the required packages with:

pip install -r requirements.txt

Software

License

Licensed under MIT License

anndl-challenges-2023's People

Contributors

albertopirillo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.