Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aaltoes-CV-Hackthon: Surf in Wild Rift

This repository contains a PyTorch-based pipeline for AI-image Detection tasks on a Kaggle competition dataset. It demonstrates how to train and evaluate popular segmentation models. Profile


🏆 This project achieved a 97.2% score and secured 2nd place in the Aaltoes 2025 Computer Vision v1 Hackthon.
👥 Team: Ziyi Wang, Rijie Hao, Zhuchenyang Liu
🙏 Special thanks to the organizers at Aaltoes for hosting this amazing challenge.

📚 Table of Contents

  1. ✨ Features
  2. 💻 Requirements
  3. 🗂️ Dataset
  4. 🚀 Usage
  5. 🤝 Model Ensemble
  6. 📊 Results
  7. ⚙️ Arguments and Options
  8. 📁 Project Structure
  9. 🔗 Related Resources
  10. 📝 License

Features

  • Multiple models in one framework: Easily switch between U-Net, ResUNet, AttentionUNet, SegFormer, and Mask2Former.
  • Flexible device setup: Runs on GPU if available; falls back to CPU automatically otherwise.
  • Configurable hyperparameters: Adjust learning rate, batch size, epochs, threshold, etc.
  • Run-Length Encoding (RLE): Automatically encodes predicted masks in RLE format for Kaggle submissions.
  • Validation: Splits the training dataset into train/val sets for monitoring performance via Dice coefficient.
  • Easy inference: Generate submission files for Kaggle evaluation.

Requirements

You can install the required Python packages via:

pip install -r requirements.txt

Dataset

You can download dataset via

kaggle competitions download -c aaltoes-2025-computer-vision-v-1

Please place your data in Datasets folder.

Overview

This competition provides a dataset of 46836 images, each with its original version and corresponding binary mask indicating inpainted regions. All images are 256×256 pixels in size.

Files

  • train/ - Directory containing training data:
    • images/ - Manipulated versions of the images
    • masks/ - Binary masks indicating inpainted regions
    • originals/ - Original versions of the images
  • test/ - Directory containing test data:
    • images/ - Manipulated versions of the images
  • sample_submission.csv - Example submission file in the correct format

Data Format

Images

  • Format: PNG
  • Resolution: 256×256 pixels
  • Color space: RGB (3 channels)

Masks

  • Format: PNG
  • Resolution: 256×256 pixels
  • Values:
    • 0: Original (non-inpainted) regions
    • 1: Inpainted (manipulated) regions

Usage

Training

To train a model, run the main script with appropriate arguments. You can also you the run.sh to train or inference.

python train.py \
    --model "Mask2Fomer" \
    --batch_size 16 \
    --epochs 30 \
    --lr 1e-4 \
    --num_workers 4 \
    --train_image_dir "../Dataset/train/train/images" \
    --train_mask_dir "../Dataset/train/train/masks" \
    --test_image_dir "../Dataset/test/test/images" \
    --threshold 0.5

Inference

For inference you need add model name and the path to the pretrained model.

python train.py \
    --model "Mask2Former" \
    --test_image_dir "../Dataset/test/test/images" \
    --load_pretrain "/path/to/your/best_model.pth" \
    --threshold 0.5

Threshold Optimization

Validation Set Inference

First, generate the float mask predictions from your target model on the validation set:

python train.py \
    --model "Mask2Former" \
    --predict_validation True \
    --load_pretrain "/path/to/your/best_model.pth" 

Optimization

Next, you can optimize the threshold using Mask2Former/threshold_optimization.ipynb. To adjust the search gap, modify the following line:

thresholds = np.linspace(0.4, 0.7, 20) 

Example output:

Optimal threshold: 0.637 with Dice coefficient: 0.9667

Threshold results:
    Threshold  Mean_Dice
0    0.400000   0.392585
1    0.415789   0.392585
2    0.431579   0.392585
3    0.447368   0.392585
...

阈值优化示例


Models Ensemble

To further improve the prediction score, try the ensemble method.

After gathering multiple encoded submission.csv by different models, you can try the ensemble strategy using Mask2Former/ensemble.ipynb.

Adjust the combination of models and the voting threshold by modifying: VOTE_THRESHOLD.


🏆 Our Result

The final private leaderboard result is based on the ensemble of three fine-tuned models with threshold optimization:

Model Threshold Public Dice Coefficient Private Dice Coefficient
mask2former-swin-small-ade-semantic 0.61 0.9678 0.9651
mask2former-swin-base-ade-semantic 0.62 0.9686 0.9677
mask2former-swin-large-ade-semantic 0.61 0.9659 0.9639
Ensemble / 0.9733 0.9713

Here are some prediction samples:

Prediction Examples

🎉 We achieved second place in the Aaltoes-CV-Hackathon competition!

Leaderboard

License

Shield: License: MIT

This project is licensed under a MIT License.


Related resources

We acknowledge all the open-source contributors for the following projects to make this work possible:

About

No description, website, or topics provided.

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages