{
  "id": 704991,
  "title": "ResNet50 Transfer Learning with 15-Fold Soft Voting Ensemble",
  "url": "/competitions/anime-gender-classification/discussion/704991",
  "author_name": "Jeki Wan Taufik",
  "post_date": "2026-06-08T08:46:54.361000",
  "votes": 0,
  "comment_count": 0,
  "views": 0,
  "content": "<h2>Overview</h2>\n<p>The goal of this competition was to classify anime character images into two categories: male and female. My solution was based on transfer learning using a pretrained ResNet50 model combined with extensive data augmentation, 15-fold stratified cross-validation, and a soft-voting ensemble.</p>\n<p>The final pipeline focused on maximizing generalization while reducing prediction variance through model ensembling.</p>\n<hr>\n<h2>Data Preparation</h2>\n<p>The competition provided separate training and validation datasets. To maximize the amount of labeled data available for model development, I merged both datasets into a single training pool.</p>\n<ul>\n<li>Original train set + validation set</li>\n<li>Total labeled images: 5,400</li>\n</ul>\n<p>Before training, I performed a simple visual inspection of samples from both classes to verify image quality and label consistency.</p>\n<hr>\n<h2>Data Augmentation</h2>\n<p>To improve robustness and reduce overfitting, I applied several augmentation techniques during training:</p>\n<ul>\n<li>Random Resized Crop (224×224)</li>\n<li>Random Horizontal Flip</li>\n<li>Random Rotation</li>\n<li>Color Jitter</li>\n<li>Random Erasing</li>\n</ul>\n<p>For validation and inference, a deterministic preprocessing pipeline was used:</p>\n<ul>\n<li>Resize to 256</li>\n<li>Center Crop to 224</li>\n<li>ImageNet normalization</li>\n</ul>\n<p>The normalization statistics followed the standard ImageNet mean and standard deviation because the backbone model was initialized with ImageNet pretrained weights.</p>\n<hr>\n<h2>Model Architecture</h2>\n<p>I used ResNet50 pretrained on ImageNet as the backbone.</p>\n<p>Instead of using the original classification layer, I replaced it with a custom classification head:</p>\n<ul>\n<li>Linear layer (2048 → 512)</li>\n<li>GELU activation</li>\n<li>Dropout (0.2)</li>\n<li>Linear layer (512 → 2)</li>\n</ul>\n<p>This modification allowed the model to better adapt to the anime image domain while maintaining the benefits of transfer learning.</p>\n<hr>\n<h2>Cross Validation Strategy</h2>\n<p>To obtain robust model estimates and reduce the risk of overfitting to a single validation split, I used Stratified K-Fold Cross Validation with:</p>\n<ul>\n<li>15 folds</li>\n<li>Shuffle enabled</li>\n<li>Random seed = 42</li>\n</ul>\n<p>Stratification ensured that both gender classes remained balanced across folds.</p>\n<p>For each fold, the best checkpoint was selected according to validation loss.</p>\n<hr>\n<h2>Training Configuration</h2>\n<p>Training settings:</p>\n<ul>\n<li>Optimizer: Adam</li>\n<li>Learning Rate: 1e-4</li>\n<li>Epochs: 18 (maximum)</li>\n<li>Batch Size: 32 (train), 64 (validation)</li>\n<li>Loss Function: Cross Entropy Loss with Label Smoothing (0.01)</li>\n</ul>\n<p>To improve optimization stability, I used a cosine learning rate schedule with warmup:</p>\n<ul>\n<li>Warmup Ratio: 4%</li>\n</ul>\n<p>In addition, early stopping with a patience of 3 epochs was applied to avoid unnecessary training and reduce overfitting.</p>\n<hr>\n<h2>Validation Performance</h2>\n<p>The model achieved consistently high validation accuracy across folds.</p>\n<p>Most folds achieved validation accuracy above 99%, and several folds reached perfect validation accuracy (100%).</p>\n<p>The combination of transfer learning, strong augmentation, and cross-validation proved highly effective for this dataset.</p>\n<hr>\n<h2>Ensemble Inference</h2>\n<p>After training, I loaded the best model from each fold and performed ensemble inference.</p>\n<p>A total of 15 fold models were used.</p>\n<p>For every test image:</p>\n<ol>\n<li>Each model produced class probabilities using Softmax.</li>\n<li>Probabilities from all fold models were summed.</li>\n<li>The average probability was computed.</li>\n<li>The final prediction was obtained from the class with the highest averaged probability.</li>\n</ol>\n<p>This soft-voting ensemble reduced variance between folds and produced more stable predictions than relying on a single model.</p>\n<hr>\n<h2>Final Pipeline</h2>\n<ol>\n<li>Merge train and validation datasets.</li>\n<li>Apply extensive image augmentation.</li>\n<li>Train ResNet50 with a custom classification head.</li>\n<li>Use 15-fold stratified cross-validation.</li>\n<li>Save the best checkpoint from each fold.</li>\n<li>Perform soft-voting ensemble across all fold models.</li>\n<li>Generate final predictions for submission.</li>\n</ol>\n<hr>\n<h2>Conclusion</h2>\n<p>My final solution combined transfer learning, strong data augmentation, cross-validation, cosine learning rate scheduling, label smoothing, and a 15-model ensemble. The most significant contributors to performance were the pretrained ResNet50 backbone and the soft-voting ensemble built from all cross-validation folds.</p>",
  "messages": [
    {
      "id": 3468026,
      "postDate": "2026-06-08T08:46:54.363Z",
      "content": "<h2>Overview</h2>\n<p>The goal of this competition was to classify anime character images into two categories: male and female. My solution was based on transfer learning using a pretrained ResNet50 model combined with extensive data augmentation, 15-fold stratified cross-validation, and a soft-voting ensemble.</p>\n<p>The final pipeline focused on maximizing generalization while reducing prediction variance through model ensembling.</p>\n<hr>\n<h2>Data Preparation</h2>\n<p>The competition provided separate training and validation datasets. To maximize the amount of labeled data available for model development, I merged both datasets into a single training pool.</p>\n<ul>\n<li>Original train set + validation set</li>\n<li>Total labeled images: 5,400</li>\n</ul>\n<p>Before training, I performed a simple visual inspection of samples from both classes to verify image quality and label consistency.</p>\n<hr>\n<h2>Data Augmentation</h2>\n<p>To improve robustness and reduce overfitting, I applied several augmentation techniques during training:</p>\n<ul>\n<li>Random Resized Crop (224×224)</li>\n<li>Random Horizontal Flip</li>\n<li>Random Rotation</li>\n<li>Color Jitter</li>\n<li>Random Erasing</li>\n</ul>\n<p>For validation and inference, a deterministic preprocessing pipeline was used:</p>\n<ul>\n<li>Resize to 256</li>\n<li>Center Crop to 224</li>\n<li>ImageNet normalization</li>\n</ul>\n<p>The normalization statistics followed the standard ImageNet mean and standard deviation because the backbone model was initialized with ImageNet pretrained weights.</p>\n<hr>\n<h2>Model Architecture</h2>\n<p>I used ResNet50 pretrained on ImageNet as the backbone.</p>\n<p>Instead of using the original classification layer, I replaced it with a custom classification head:</p>\n<ul>\n<li>Linear layer (2048 → 512)</li>\n<li>GELU activation</li>\n<li>Dropout (0.2)</li>\n<li>Linear layer (512 → 2)</li>\n</ul>\n<p>This modification allowed the model to better adapt to the anime image domain while maintaining the benefits of transfer learning.</p>\n<hr>\n<h2>Cross Validation Strategy</h2>\n<p>To obtain robust model estimates and reduce the risk of overfitting to a single validation split, I used Stratified K-Fold Cross Validation with:</p>\n<ul>\n<li>15 folds</li>\n<li>Shuffle enabled</li>\n<li>Random seed = 42</li>\n</ul>\n<p>Stratification ensured that both gender classes remained balanced across folds.</p>\n<p>For each fold, the best checkpoint was selected according to validation loss.</p>\n<hr>\n<h2>Training Configuration</h2>\n<p>Training settings:</p>\n<ul>\n<li>Optimizer: Adam</li>\n<li>Learning Rate: 1e-4</li>\n<li>Epochs: 18 (maximum)</li>\n<li>Batch Size: 32 (train), 64 (validation)</li>\n<li>Loss Function: Cross Entropy Loss with Label Smoothing (0.01)</li>\n</ul>\n<p>To improve optimization stability, I used a cosine learning rate schedule with warmup:</p>\n<ul>\n<li>Warmup Ratio: 4%</li>\n</ul>\n<p>In addition, early stopping with a patience of 3 epochs was applied to avoid unnecessary training and reduce overfitting.</p>\n<hr>\n<h2>Validation Performance</h2>\n<p>The model achieved consistently high validation accuracy across folds.</p>\n<p>Most folds achieved validation accuracy above 99%, and several folds reached perfect validation accuracy (100%).</p>\n<p>The combination of transfer learning, strong augmentation, and cross-validation proved highly effective for this dataset.</p>\n<hr>\n<h2>Ensemble Inference</h2>\n<p>After training, I loaded the best model from each fold and performed ensemble inference.</p>\n<p>A total of 15 fold models were used.</p>\n<p>For every test image:</p>\n<ol>\n<li>Each model produced class probabilities using Softmax.</li>\n<li>Probabilities from all fold models were summed.</li>\n<li>The average probability was computed.</li>\n<li>The final prediction was obtained from the class with the highest averaged probability.</li>\n</ol>\n<p>This soft-voting ensemble reduced variance between folds and produced more stable predictions than relying on a single model.</p>\n<hr>\n<h2>Final Pipeline</h2>\n<ol>\n<li>Merge train and validation datasets.</li>\n<li>Apply extensive image augmentation.</li>\n<li>Train ResNet50 with a custom classification head.</li>\n<li>Use 15-fold stratified cross-validation.</li>\n<li>Save the best checkpoint from each fold.</li>\n<li>Perform soft-voting ensemble across all fold models.</li>\n<li>Generate final predictions for submission.</li>\n</ol>\n<hr>\n<h2>Conclusion</h2>\n<p>My final solution combined transfer learning, strong data augmentation, cross-validation, cosine learning rate scheduling, label smoothing, and a 15-model ensemble. The most significant contributors to performance were the pretrained ResNet50 backbone and the soft-voting ensemble built from all cross-validation folds.</p>",
      "rawMarkdown": "## Overview\n\nThe goal of this competition was to classify anime character images into two categories: male and female. My solution was based on transfer learning using a pretrained ResNet50 model combined with extensive data augmentation, 15-fold stratified cross-validation, and a soft-voting ensemble.\n\nThe final pipeline focused on maximizing generalization while reducing prediction variance through model ensembling.\n\n---\n\n## Data Preparation\n\nThe competition provided separate training and validation datasets. To maximize the amount of labeled data available for model development, I merged both datasets into a single training pool.\n\n* Original train set + validation set\n* Total labeled images: 5,400\n\nBefore training, I performed a simple visual inspection of samples from both classes to verify image quality and label consistency.\n\n---\n\n## Data Augmentation\n\nTo improve robustness and reduce overfitting, I applied several augmentation techniques during training:\n\n* Random Resized Crop (224×224)\n* Random Horizontal Flip\n* Random Rotation\n* Color Jitter\n* Random Erasing\n\nFor validation and inference, a deterministic preprocessing pipeline was used:\n\n* Resize to 256\n* Center Crop to 224\n* ImageNet normalization\n\nThe normalization statistics followed the standard ImageNet mean and standard deviation because the backbone model was initialized with ImageNet pretrained weights.\n\n---\n\n## Model Architecture\n\nI used ResNet50 pretrained on ImageNet as the backbone.\n\nInstead of using the original classification layer, I replaced it with a custom classification head:\n\n* Linear layer (2048 → 512)\n* GELU activation\n* Dropout (0.2)\n* Linear layer (512 → 2)\n\nThis modification allowed the model to better adapt to the anime image domain while maintaining the benefits of transfer learning.\n\n---\n\n## Cross Validation Strategy\n\nTo obtain robust model estimates and reduce the risk of overfitting to a single validation split, I used Stratified K-Fold Cross Validation with:\n\n* 15 folds\n* Shuffle enabled\n* Random seed = 42\n\nStratification ensured that both gender classes remained balanced across folds.\n\nFor each fold, the best checkpoint was selected according to validation loss.\n\n---\n\n## Training Configuration\n\nTraining settings:\n\n* Optimizer: Adam\n* Learning Rate: 1e-4\n* Epochs: 18 (maximum)\n* Batch Size: 32 (train), 64 (validation)\n* Loss Function: Cross Entropy Loss with Label Smoothing (0.01)\n\nTo improve optimization stability, I used a cosine learning rate schedule with warmup:\n\n* Warmup Ratio: 4%\n\nIn addition, early stopping with a patience of 3 epochs was applied to avoid unnecessary training and reduce overfitting.\n\n---\n\n## Validation Performance\n\nThe model achieved consistently high validation accuracy across folds.\n\nMost folds achieved validation accuracy above 99%, and several folds reached perfect validation accuracy (100%).\n\nThe combination of transfer learning, strong augmentation, and cross-validation proved highly effective for this dataset.\n\n---\n\n## Ensemble Inference\n\nAfter training, I loaded the best model from each fold and performed ensemble inference.\n\nA total of 15 fold models were used.\n\nFor every test image:\n\n1. Each model produced class probabilities using Softmax.\n2. Probabilities from all fold models were summed.\n3. The average probability was computed.\n4. The final prediction was obtained from the class with the highest averaged probability.\n\nThis soft-voting ensemble reduced variance between folds and produced more stable predictions than relying on a single model.\n\n---\n\n## Final Pipeline\n\n1. Merge train and validation datasets.\n2. Apply extensive image augmentation.\n3. Train ResNet50 with a custom classification head.\n4. Use 15-fold stratified cross-validation.\n5. Save the best checkpoint from each fold.\n6. Perform soft-voting ensemble across all fold models.\n7. Generate final predictions for submission.\n\n---\n\n## Conclusion\n\nMy final solution combined transfer learning, strong data augmentation, cross-validation, cosine learning rate scheduling, label smoothing, and a 15-model ensemble. The most significant contributors to performance were the pretrained ResNet50 backbone and the soft-voting ensemble built from all cross-validation folds."
    }
  ],
  "comments": [],
  "raw_markdown_by_id": {
    "3468026": "## Overview\n\nThe goal of this competition was to classify anime character images into two categories: male and female. My solution was based on transfer learning using a pretrained ResNet50 model combined with extensive data augmentation, 15-fold stratified cross-validation, and a soft-voting ensemble.\n\nThe final pipeline focused on maximizing generalization while reducing prediction variance through model ensembling.\n\n---\n\n## Data Preparation\n\nThe competition provided separate training and validation datasets. To maximize the amount of labeled data available for model development, I merged both datasets into a single training pool.\n\n* Original train set + validation set\n* Total labeled images: 5,400\n\nBefore training, I performed a simple visual inspection of samples from both classes to verify image quality and label consistency.\n\n---\n\n## Data Augmentation\n\nTo improve robustness and reduce overfitting, I applied several augmentation techniques during training:\n\n* Random Resized Crop (224×224)\n* Random Horizontal Flip\n* Random Rotation\n* Color Jitter\n* Random Erasing\n\nFor validation and inference, a deterministic preprocessing pipeline was used:\n\n* Resize to 256\n* Center Crop to 224\n* ImageNet normalization\n\nThe normalization statistics followed the standard ImageNet mean and standard deviation because the backbone model was initialized with ImageNet pretrained weights.\n\n---\n\n## Model Architecture\n\nI used ResNet50 pretrained on ImageNet as the backbone.\n\nInstead of using the original classification layer, I replaced it with a custom classification head:\n\n* Linear layer (2048 → 512)\n* GELU activation\n* Dropout (0.2)\n* Linear layer (512 → 2)\n\nThis modification allowed the model to better adapt to the anime image domain while maintaining the benefits of transfer learning.\n\n---\n\n## Cross Validation Strategy\n\nTo obtain robust model estimates and reduce the risk of overfitting to a single validation split, I used Stratified K-Fold Cross Validation with:\n\n* 15 folds\n* Shuffle enabled\n* Random seed = 42\n\nStratification ensured that both gender classes remained balanced across folds.\n\nFor each fold, the best checkpoint was selected according to validation loss.\n\n---\n\n## Training Configuration\n\nTraining settings:\n\n* Optimizer: Adam\n* Learning Rate: 1e-4\n* Epochs: 18 (maximum)\n* Batch Size: 32 (train), 64 (validation)\n* Loss Function: Cross Entropy Loss with Label Smoothing (0.01)\n\nTo improve optimization stability, I used a cosine learning rate schedule with warmup:\n\n* Warmup Ratio: 4%\n\nIn addition, early stopping with a patience of 3 epochs was applied to avoid unnecessary training and reduce overfitting.\n\n---\n\n## Validation Performance\n\nThe model achieved consistently high validation accuracy across folds.\n\nMost folds achieved validation accuracy above 99%, and several folds reached perfect validation accuracy (100%).\n\nThe combination of transfer learning, strong augmentation, and cross-validation proved highly effective for this dataset.\n\n---\n\n## Ensemble Inference\n\nAfter training, I loaded the best model from each fold and performed ensemble inference.\n\nA total of 15 fold models were used.\n\nFor every test image:\n\n1. Each model produced class probabilities using Softmax.\n2. Probabilities from all fold models were summed.\n3. The average probability was computed.\n4. The final prediction was obtained from the class with the highest averaged probability.\n\nThis soft-voting ensemble reduced variance between folds and produced more stable predictions than relying on a single model.\n\n---\n\n## Final Pipeline\n\n1. Merge train and validation datasets.\n2. Apply extensive image augmentation.\n3. Train ResNet50 with a custom classification head.\n4. Use 15-fold stratified cross-validation.\n5. Save the best checkpoint from each fold.\n6. Perform soft-voting ensemble across all fold models.\n7. Generate final predictions for submission.\n\n---\n\n## Conclusion\n\nMy final solution combined transfer learning, strong data augmentation, cross-validation, cosine learning rate scheduling, label smoothing, and a 15-model ensemble. The most significant contributors to performance were the pretrained ResNet50 backbone and the soft-voting ensemble built from all cross-validation folds."
  }
}