{
  "fetched_at": "2026-10-19T10:52:04Z",
  "source_url": "https://www.kaggle.com/competitions/dnn-xm/data",
  "pages": [
    {
      "name": "data-description",
      "content": "In this competition, we provide the augmented version of CIFAR-10 images in train.zip and test.zip.  \nWe also provide train.csv which shows the mapping of the train images to their true label.  \n\n## Files\n*   **train** - Folder that contains the training set images\n**test** - Folder that contains the testing set images\n*   **train.csv** - contains the training  images id mapping to their ground truth \n*   **test.csv** - contains the testing images id \n*   **sample_submission.csv** - a sample submission file in the correct format\n\n## Data source citation and copyright\n\nThe CIFAR-10 and CIFAR-100 are labeled subsets of the 80 million tiny images dataset. They were collected by Alex Krizhevsky, Vinod Nair, and Geoffrey Hinton.\n\nLearning Multiple Layers of Features from Tiny Images, Alex Krizhevsky, 2009.\n\nMIT License\n\nCopyright (c) 2017 Baptiste Wicht\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n",
      "isPublished": false,
      "hasIsPublished": false,
      "postTitle": "",
      "hasPostTitle": false,
      "mimeType": "",
      "hasMimeType": false
    },
    {
      "name": "Description",
      "content": "For this competition, use a three-layer neural network. To train the multilayer neural network, use the PyTorch deep learning library.  The net has an input dimension of N, a hidden layer dimension of H, and performs classification over 10 classes of the CIFAR-10 dataset.\n\nIn other words, the network has the following architecture:\nInput - fully connected layer - ReLU - Fully connected layer - ReLU - Fully connected layer -  Softmax \nThe outputs of the third fully connected layer are the scores for each class.\n\nTo start working on this Project, follow the below steps:\n\n**Step 1: Prepare the dataset:**\n\nPrepare the CIFAR-10 dataset in PyTorch format and Develop train, val, and test dataloader for training and testing. \n\nPyTorch’s `Dataset` and `DataLoader `classes help us fetch the training batches in the background using multiple processes. To avoid computational bottlenecks, using these background processes ensures that the next batch of data is ready when the model finishes its backward pass. \nThe code for this will be provided to you. \n\n```\n# Preparing your pytorch custom dataset.\nimport torch\nimport torch.nn as nn\nimport torch.optim as optim\nfrom torchvision import datasets, transforms\nfrom torch.utils.data import DataLoader, Dataset, random_split\nimport pandas as pd\nimport os\nfrom PIL import Image\nfrom tqdm import tqdm\nimport random\nimport numpy as np\n\n# Set random seed for reproducibility\nseed = 42\nrandom.seed(seed)\nnp.random.seed(seed)\ntorch.manual_seed(seed)\nif torch.cuda.is_available():\n    torch.cuda.manual_seed(seed)\n    torch.cuda.manual_seed_all(seed)\n\nclass CustomDataset(Dataset):\n    def __init__(self, csv_file, img_dir, transform=None):\n        self.labels_df = pd.read_csv(csv_file)\n        self.img_dir = img_dir\n        self.transform = transform\n\n    def __len__(self):\n        return len(self.labels_df)\n\n    def __getitem__(self, idx):\n        img_id = self.labels_df.iloc[idx, 1]\n        img_path = os.path.join(self.img_dir, img_id)\n        image = Image.open(img_path)\n        label = self.labels_df.iloc[idx, 2] if 'labels' in self.labels_df.columns else -1\n\n        if self.transform:\n            image = self.transform(image)\n\n        return image, label\n\ntransform = transforms.Compose([\n    #transforms.RandomHorizontalFlip(),  # Randomly flip the image horizontally\n    #transforms.RandomCrop(32, padding=4),  # Randomly crop the image with padding\n    #transforms.ColorJitter(brightness=0.2, contrast=0.2, saturation=0.2, hue=0.2),  # Randomly change the brightness, contrast, saturation, and hue\n    transforms.ToTensor(),\n    #transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))  # Normalize the image\n])\n\n\n\n\n\n\n\n```\n```\n# Read the image name and label from the train.csv and test.csv files \ntrain_dataset = CustomDataset(csv_file='/kaggle/input/dnn-xm/train.csv', img_dir='/kaggle/input/dnn-xm/train/train', transform=transform)\ntest_dataset = CustomDataset(csv_file='/kaggle/input/dnn-xm/test.csv', img_dir='/kaggle/input/dnn-xm/test/test', transform=transform)\n```\n```\n# Create data loaders\n# Define dataset sizes for training and validation\nvalidation_split = 0.2  # 20% of the data for validation\ntrain_size = int((1 - validation_split) * len(train_dataset))\nvalid_size = len(train_dataset) - train_size\n\n# Split the training dataset into train and validation datasets\ntrain_subset, valid_subset = random_split(train_dataset, [train_size, valid_size])\n\nbatch_size = 64\n\n# Create data loaders for train and validation sets\ntrain_loader = DataLoader(train_subset, batch_size=batch_size, shuffle=True)\nvalid_loader = DataLoader(valid_subset, batch_size=batch_size, shuffle=False)\ntest_loader = DataLoader(test_dataset, batch_size=batch_size, shuffle=False)\n```\n\n**Step 2: Build a three-layer neural network Pipeline:**\n\n```\nclass ThreeLayer_DNN(torch.nn.Module):\n    ......\n```\n\n**Step 3: Start training**\n\n```\n# Initialize variables to track the best model\nbest_val_accuracy = 0.0\nbest_model_path = 'best_model.pth'\n\n# Training loop with optimal hyperparameters\nepochs = 20\nfor epoch in range(epochs):\n    print(f'Epoch {epoch + 1}/{epochs}')\n    \n    # Training phase\n    model.train()\n    running_loss = 0.0\n    for images, labels in tqdm(train_loader, desc=\"Training\"):\n        images, labels = images.to(device), labels.to(device)\n\n        # Zero gradients\n        optimizer.zero_grad()\n\n        # Forward pass\n        outputs = model(images)\n        loss = criterion(outputs, labels)\n        running_loss += loss.item()\n\n        # Backward pass\n        loss.backward()\n        optimizer.step()\n    \n    print(f'Training loss: {running_loss / len(train_loader)}')\n    \n    # Validation phase\n    model.eval()\n    val_loss = 0.0\n    correct = 0\n    total = 0\n    with torch.no_grad():\n        for images, labels in tqdm(valid_loader, desc=\"Validation\"):\n            images, labels = images.to(device), labels.to(device)\n\n            # Forward pass\n            outputs = model(images)\n            loss = criterion(outputs, labels)\n            val_loss += loss.item()\n\n            # Calculate accuracy\n            _, predicted = torch.max(outputs, 1)\n            total += labels.size(0)\n            correct += (predicted == labels).sum().item()\n\n    val_loss /= len(valid_loader)\n    val_accuracy = 100 * correct / total\n    print(f'Validation loss: {val_loss}, Validation accuracy: {val_accuracy}%')\n\n    # Save the model if it has the best validation accuracy\n    if val_accuracy > best_val_accuracy:\n        best_val_accuracy = val_accuracy\n        torch.save(model.state_dict(), best_model_path)\n        print('Best model saved.')\n```\n\n**Step 4: Inference using the trained model**\n\n```\n# Load the best model weights\nmodel.load_state_dict(torch.load(best_model_path))\nprint('Best model loaded for test predictions.')\n\n# Make predictions on the test dataset\nmodel.eval()\npredictions = []\nwith torch.no_grad():\n    for images, _ in test_loader:\n        images = images.to(device)\n        outputs = model(images)\n        _, predicted = torch.max(outputs.data, 1)\n        predictions.extend(predicted.cpu().numpy())\n\n# Create a DataFrame with IDs and predictions\nsubmission_df = pd.DataFrame({\n    'ID': range(len(predictions)),\n    'prediction': predictions\n})\nsubmission_df.to_csv('submission.csv', index=False)\nprint('submission file is created')\n```\n\n**Additional resources:**\n [Datasets & DataLoaders] (https://pytorch.org/tutorials/beginner/basics/data_tutorial.html)",
      "isPublished": false,
      "hasIsPublished": false,
      "postTitle": "",
      "hasPostTitle": false,
      "mimeType": "",
      "hasMimeType": false
    },
    {
      "name": "Evaluation",
      "content": "**To Evaluate your model performance, use accuracy:**\n Accuracy is calculated as the sum of correct predictions divided by the total number of predictions, respectively.\n\n ACC = (TP + TN)/(FP + FN + TP + TN)\n\n## Submission File\nFor each Image_id in the test set, you must predict the class of the image. The file should contain a header and have the following format:\n```\n ID, prediction\n\n1, 2\n2, 4\n3, 6\n4, 7\n5, 1\netc.\n```\n",
      "isPublished": false,
      "hasIsPublished": false,
      "postTitle": "",
      "hasPostTitle": false,
      "mimeType": "",
      "hasMimeType": false
    },
    {
      "name": "rules",
      "content": "This is a page where you can include rules that participants must accept before joining. You may wish to include rules like:\n\n - Don't cheat!\n - Apply yourself!\n - Have fun!\n- Do not share your code with others \n",
      "isPublished": false,
      "hasIsPublished": false,
      "postTitle": "",
      "hasPostTitle": false,
      "mimeType": "",
      "hasMimeType": false
    },
    {
      "name": "abstract",
      "content": "In this Kaggle competition, you will develop a Deep neural network (DNN) with fully connected layers to perform image classification and test it out on the modified version of the CIFAR-10 image dataset. \n\n**Goal:** The main objective of this project is to make you practice, deep neural networks using Pytorch deep learning library.",
      "isPublished": false,
      "hasIsPublished": false,
      "postTitle": "",
      "hasPostTitle": false,
      "mimeType": "",
      "hasMimeType": false
    }
  ]
}