{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-10-01T08:01:28.331258Z","iopub.execute_input":"2023-10-01T08:01:28.331638Z","iopub.status.idle":"2023-10-01T08:01:28.624277Z","shell.execute_reply.started":"2023-10-01T08:01:28.331613Z","shell.execute_reply":"2023-10-01T08:01:28.623409Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Python package to open .7z archives\n!pip install py7zr;","metadata":{"execution":{"iopub.status.busy":"2023-10-01T08:11:24.877888Z","iopub.execute_input":"2023-10-01T08:11:24.878359Z","iopub.status.idle":"2023-10-01T08:11:36.585159Z","shell.execute_reply.started":"2023-10-01T08:11:24.878319Z","shell.execute_reply":"2023-10-01T08:11:36.584087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import libraries\nimport torch\nfrom torch.utils.data import DataLoader, Dataset\nimport torchvision\nimport torchvision.transforms as transforms\nfrom torch.utils.data.sampler import SubsetRandomSampler\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\n# import extract libraries\nimport glob\nimport py7zr","metadata":{"execution":{"iopub.status.busy":"2023-10-01T08:13:03.980741Z","iopub.execute_input":"2023-10-01T08:13:03.981054Z","iopub.status.idle":"2023-10-01T08:13:07.863164Z","shell.execute_reply.started":"2023-10-01T08:13:03.981028Z","shell.execute_reply":"2023-10-01T08:13:07.862230Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Class labels\nCLASS_NAMES = {'airplane':0, 'automobile':1, 'bird':2, 'cat':3, 'deer':4,\n               'dog':5, 'frog':6, 'horse':7, 'ship':8, 'truck':9}","metadata":{"execution":{"iopub.status.busy":"2023-10-01T08:15:36.641653Z","iopub.execute_input":"2023-10-01T08:15:36.642154Z","iopub.status.idle":"2023-10-01T08:15:36.647229Z","shell.execute_reply.started":"2023-10-01T08:15:36.642127Z","shell.execute_reply":"2023-10-01T08:15:36.646148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Open training archive file\nwith py7zr.SevenZipFile('/kaggle/input/cifar-10/train.7z', mode='r') as z:\n        z.extractall('/kaggle/working/data')","metadata":{"execution":{"iopub.status.busy":"2023-10-01T08:13:24.729421Z","iopub.execute_input":"2023-10-01T08:13:24.729899Z","iopub.status.idle":"2023-10-01T08:14:05.806849Z","shell.execute_reply.started":"2023-10-01T08:13:24.729873Z","shell.execute_reply":"2023-10-01T08:14:05.805892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Convert the filepath to an integer image ID\ndef filename_to_id(filename):\n    return int(filename.split('/')[-1].split('.')[0])\n# Load all of the images into an array, also return the image IDs\ndef load_imgs_and_ids(img_directory_path):\n    image_filenames = glob.glob(img_directory_path + '/*.png')\n    image_ids = []\n    image_paths = []\n    for f in image_filenames:\n        image_id = filename_to_id(f) # E.G. '/kaggle/working/train/44240.png' -> 44240\n        image_ids.append(image_id)\n        image_paths.append(f)\n    df = pd.DataFrame({'id':image_ids,'path':image_paths})\n    \n    return df","metadata":{"execution":{"iopub.status.busy":"2023-10-01T08:15:39.689413Z","iopub.execute_input":"2023-10-01T08:15:39.689793Z","iopub.status.idle":"2023-10-01T08:15:39.695425Z","shell.execute_reply.started":"2023-10-01T08:15:39.689767Z","shell.execute_reply":"2023-10-01T08:15:39.694539Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_data = load_imgs_and_ids('./data/train')\nlabels = pd.read_csv('../input/cifar-10/trainLabels.csv')","metadata":{"execution":{"iopub.status.busy":"2023-10-01T08:15:53.436794Z","iopub.execute_input":"2023-10-01T08:15:53.437117Z","iopub.status.idle":"2023-10-01T08:15:53.605016Z","shell.execute_reply.started":"2023-10-01T08:15:53.437092Z","shell.execute_reply":"2023-10-01T08:15:53.604140Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.merge(image_data,labels, on='id', how='inner')\ndata.drop('id',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T08:15:55.831963Z","iopub.execute_input":"2023-10-01T08:15:55.832599Z","iopub.status.idle":"2023-10-01T08:15:55.867383Z","shell.execute_reply.started":"2023-10-01T08:15:55.832569Z","shell.execute_reply":"2023-10-01T08:15:55.866535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train = data.copy()\nx_train.label = x_train.label.map(CLASS_NAMES)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T08:15:56.724573Z","iopub.execute_input":"2023-10-01T08:15:56.725195Z","iopub.status.idle":"2023-10-01T08:15:56.739469Z","shell.execute_reply.started":"2023-10-01T08:15:56.725168Z","shell.execute_reply":"2023-10-01T08:15:56.738452Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train","metadata":{"execution":{"iopub.status.busy":"2023-10-01T08:15:59.144805Z","iopub.execute_input":"2023-10-01T08:15:59.145414Z","iopub.status.idle":"2023-10-01T08:15:59.161436Z","shell.execute_reply.started":"2023-10-01T08:15:59.145385Z","shell.execute_reply":"2023-10-01T08:15:59.160389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from PIL import Image\nfrom sklearn.model_selection import train_test_split\n\n# define a data class\nclass ClassificationDataset:\n    def __init__(self, data, data_path, transform, training=True):\n        \"\"\"Define the dataset for classification problems\n\n        Args:\n            data ([dataframe]): [a dataframe that contain 2 columns: image name and label]\n            data_path ([str]): [path/to/folder that contains image file]\n            transform : [augmentation methods and transformation of images]\n            training (bool, optional): []. Defaults to True.\n        \"\"\"\n        self.data = data\n        self.imgs = data[\"path\"].unique().tolist()\n        self.data_path = data_path\n        self.training = training\n        self.transform = transform\n\n    def __getitem__(self, idx):\n        img = Image.open(os.path.join(self.data_path, self.data.iloc[idx, 0]))\n        if self.transform is not None:\n            img = self.transform(img)\n        if self.training:\n            label = self.data.iloc[idx, 1]\n            return img, label\n        else:\n            return img\n\n    def __len__(self):\n        return len(self.imgs)\n\n\ndef make_loader(dataset, train_batch_size, validation_split=0.2):\n    \"\"\"make dataloader for pytorch training\n\n    Args:\n        dataset ([object]): [the dataset object]\n        train_batch_size ([int]): [training batch size]\n        validation_split (float, optional): [validation ratio]. Defaults to 0.2.\n\n    Returns:\n        [type]: [description]\n    \"\"\"\n    # number of samples in train and test set\n    train_len = int(len(dataset) * (1 - validation_split))\n    test_len = len(dataset) - train_len\n    train_set, test_set = torch.utils.data.random_split(dataset, [train_len, test_len])\n    # create train_loader\n    train_loader = torch.utils.data.DataLoader(\n        train_set, batch_size=train_batch_size, shuffle=True,\n    )\n    # create test_loader\n    test_loader = torch.utils.data.DataLoader(test_set, batch_size=1, shuffle=False,)\n    return train_loader, test_loader\n\n\ndef data_split(data, test_size):\n    x_train, x_test, y_train, y_test = train_test_split(\n        data, data[\"label\"], test_size=test_size, stratify = data.iloc[:,1]\n    )\n    return x_train, x_test, y_train, y_test","metadata":{"execution":{"iopub.status.busy":"2023-10-01T08:16:00.597105Z","iopub.execute_input":"2023-10-01T08:16:00.597631Z","iopub.status.idle":"2023-10-01T08:16:01.013781Z","shell.execute_reply.started":"2023-10-01T08:16:00.597595Z","shell.execute_reply":"2023-10-01T08:16:01.012904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"IMAGE_SIZE = 32\n\nmean, std = [0.4914, 0.4822, 0.4465], [0.247, 0.243, 0.261]\n# These values are mostly used by researchers as found to very useful in fast convergence\n\n\n# https://pytorch.org/vision/stable/transforms.html\n# We can try various transformation for good generalization of model\ncomposed_train = transforms.Compose([transforms.Resize((IMAGE_SIZE, IMAGE_SIZE)), # Resize the image in a 32X32 shape\n                                     transforms.RandomRotation(20), # Randomly rotate some images by 20 degrees\n                                     transforms.RandomHorizontalFlip(0.1), # Randomly horizontal flip the images\n                                     transforms.ColorJitter(brightness = 0.1, # Randomly adjust color jitter of the images\n                                                            contrast = 0.1, \n                                                            saturation = 0.1), \n                                     transforms.RandomAdjustSharpness(sharpness_factor = 2,\n                                                                      p = 0.1), # Randomly adjust sharpness\n                                     transforms.ToTensor(),   # Converting image to tensor\n                                     transforms.Normalize(mean, std), # Normalizing with standard mean and standard deviation\n                                     transforms.RandomErasing(p=0.75,scale=(0.02, 0.1),value=1.0, inplace=False)])\n\n\ncomposed_test = transforms.Compose([transforms.Resize((IMAGE_SIZE,IMAGE_SIZE)),\n                                    transforms.ToTensor(),\n                                    transforms.Normalize(mean, std)])","metadata":{"execution":{"iopub.status.busy":"2023-10-01T08:16:05.542219Z","iopub.execute_input":"2023-10-01T08:16:05.542571Z","iopub.status.idle":"2023-10-01T08:16:05.549903Z","shell.execute_reply.started":"2023-10-01T08:16:05.542539Z","shell.execute_reply":"2023-10-01T08:16:05.548370Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset = ClassificationDataset(x_train,data_path = \"\",transform=composed_train,training=True)\ntrain_loader,val_loader = make_loader(dataset, train_batch_size=100, validation_split=0.2)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T08:16:14.661218Z","iopub.execute_input":"2023-10-01T08:16:14.661996Z","iopub.status.idle":"2023-10-01T08:16:14.699266Z","shell.execute_reply.started":"2023-10-01T08:16:14.661965Z","shell.execute_reply":"2023-10-01T08:16:14.698406Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch.nn as nn\nimport torch.nn.functional as F\n\n# define the NN architecture\nclass Net(nn.Module):\n    def __init__(self):\n        super(Net, self).__init__()\n        # number of hidden nodes in each layer (512)\n        hidden_1 = 2048\n        hidden_2 = 1024\n        hidden_3 = 1024\n        hidden_4 = 512\n        # linear layer (784 -> hidden_1)\n        self.fc1 = nn.Linear(32*32*3, hidden_1)\n        # linear layer (n_hidden -> hidden_2)\n        self.fc2 = nn.Linear(hidden_1, hidden_2)\n        self.fc3 = nn.Linear(hidden_2, hidden_3)\n        self.fc4 = nn.Linear(hidden_3, hidden_4)\n        # linear layer (n_hidden -> 10)\n        self.fc5 = nn.Linear(hidden_4, 10)\n\n\n    def forward(self, x):\n        # flatten image input\n        x = x.view(-1, 32*32*3)\n        # add hidden layer, with relu activation function\n        x = F.relu(self.fc1(x))\n        # add hidden layer, with relu activation function\n        x = F.relu(self.fc2(x))\n        x = F.relu(self.fc3(x))\n        x = F.relu(self.fc4(x))\n        # add output layer\n        x = self.fc5(x)\n        return x\n\n# initialize the NN\ndevice = torch.device(\"cuda\")\n\nmodel = Net().to(device)\nprint(model)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T08:16:16.584269Z","iopub.execute_input":"2023-10-01T08:16:16.584617Z","iopub.status.idle":"2023-10-01T08:16:19.608807Z","shell.execute_reply.started":"2023-10-01T08:16:16.584590Z","shell.execute_reply":"2023-10-01T08:16:19.607755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\nfrom torch import nn\nimport torch.nn.functional as F\ncriterion =  nn.CrossEntropyLoss()\noptimizer = torch.optim.Adam(model.parameters(), lr=0.0001)\nscheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(\n        optimizer, \"min\", patience=2, factor=0.5\n    )","metadata":{"execution":{"iopub.status.busy":"2023-10-01T08:16:22.399431Z","iopub.execute_input":"2023-10-01T08:16:22.400069Z","iopub.status.idle":"2023-10-01T08:16:22.405424Z","shell.execute_reply.started":"2023-10-01T08:16:22.400040Z","shell.execute_reply":"2023-10-01T08:16:22.404528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score\ndef train_one_epoch(\n    model,\n    train_loader,\n    test_loader,\n    device,\n    optimizer,\n    criterion\n):\n\n    # training-the-model\n    train_loss = 0\n    valid_loss = 0\n    all_labels = []\n    all_preds = []\n    model.train()\n    for data, target in train_loader:\n        # move-tensors-to-GPU\n        data = data.type(torch.FloatTensor).to(device)\n        # target=torch.Tensor(target)\n        target = target.float().to(device)\n        # clear-the-gradients-of-all-optimized-variables\n        optimizer.zero_grad()\n        # forward-pass: compute-predicted-outputs-by-passing-inputs-to-the-model\n        output = model(data)\n        # get the prediction label and target label\n        output = model(data)\n        preds = torch.argmax(output, axis=1).cpu().detach().numpy()\n        labels = target.cpu().numpy()\n        # calculate-the-batch-loss\n        loss = criterion(output.type(torch.FloatTensor), target.type(torch.LongTensor))\n        # backward-pass: compute-gradient-of-the-loss-wrt-model-parameters\n        loss.backward()\n        # perform-a-ingle-optimization-step (parameter-update)\n        optimizer.step()\n        # update-training-loss\n        train_loss += loss.item() * data.size(0)\n        # calculate training metrics\n        all_labels.extend(labels)\n        all_preds.extend(preds)\n    \n    acc = accuracy_score(all_labels, all_preds)\n\n    # validate-the-model\n    model.eval()\n    all_labels = []\n    all_preds = []\n    with torch.no_grad():\n        for data, target in test_loader:\n            data = data.type(torch.FloatTensor).to(device)\n            target = target.to(device)\n            output = model(data)\n            preds = torch.argmax(output, axis=1).tolist()\n            labels = target.tolist()\n            all_labels.extend(labels)\n            all_preds.extend(preds)\n            loss = criterion(output, target)\n\n            # update-average-validation-loss\n            valid_loss += loss.item() * data.size(0)\n\n    val_acc = accuracy_score(all_labels, all_preds)\n    train_loss = train_loss / len(train_loader.sampler)\n    valid_loss = valid_loss / len(test_loader.sampler)\n\n    return (\n        train_loss,\n        valid_loss,\n        acc,\n        val_acc,\n    )","metadata":{"execution":{"iopub.status.busy":"2023-10-01T08:16:25.909151Z","iopub.execute_input":"2023-10-01T08:16:25.909469Z","iopub.status.idle":"2023-10-01T08:16:25.920796Z","shell.execute_reply.started":"2023-10-01T08:16:25.909443Z","shell.execute_reply":"2023-10-01T08:16:25.919658Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tqdm import tqdm","metadata":{"execution":{"iopub.status.busy":"2023-10-01T08:17:04.979311Z","iopub.execute_input":"2023-10-01T08:17:04.979794Z","iopub.status.idle":"2023-10-01T08:17:04.984581Z","shell.execute_reply.started":"2023-10-01T08:17:04.979757Z","shell.execute_reply":"2023-10-01T08:17:04.983465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!nvidia-smi","metadata":{"execution":{"iopub.status.busy":"2023-10-01T08:17:05.290595Z","iopub.execute_input":"2023-10-01T08:17:05.291149Z","iopub.status.idle":"2023-10-01T08:17:06.310428Z","shell.execute_reply.started":"2023-10-01T08:17:05.291124Z","shell.execute_reply":"2023-10-01T08:17:06.309358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_epoch = 20\nbest_val_acc = 0\nimport logging\nimport numpy as np\nprint(\"begin training process\")\nfor i in tqdm(range(0, num_epoch)):\n    loss, val_loss, train_result, val_result = train_one_epoch(\n        model,\n        train_loader,\n        val_loader,\n        device,\n        optimizer,\n        criterion,\n    )\n\n    scheduler.step(val_loss)\n    print(\n        \"Epoch {} / {} \\n Training loss: {} -  training acc: {}\".format(\n            i + 1, num_epoch, loss,train_result\n        )\n    )\n    print(\n        \" \\n Validation loss : {} -  validation acc: {}\".format(val_loss,val_result)\n    )\n    print(\"\\n\")\n    # saving epoch with best validation accuracy\n    if best_val_acc < float(val_result):\n        print(\n            \"Validation accuracy= \"+\n            str(val_result)+\n            \"===> Save best epoch\"\n        )\n        best_val_acc = val_result\n        torch.save(\n            model,\n            \"./\" +  \"best.pt\",\n        )\n    else:\n        print(\n            \"Validation accuracy= \"+ str(val_result)+ \"===> No saving\"\n        )\n        continue","metadata":{"execution":{"iopub.status.busy":"2023-10-01T02:57:20.951065Z","iopub.execute_input":"2023-10-01T02:57:20.951543Z","iopub.status.idle":"2023-10-01T03:18:44.269900Z","shell.execute_reply.started":"2023-10-01T02:57:20.951509Z","shell.execute_reply":"2023-10-01T03:18:44.268706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import classification_report","metadata":{"execution":{"iopub.status.busy":"2023-10-01T03:18:44.271311Z","iopub.execute_input":"2023-10-01T03:18:44.272098Z","iopub.status.idle":"2023-10-01T03:18:44.278225Z","shell.execute_reply.started":"2023-10-01T03:18:44.272044Z","shell.execute_reply":"2023-10-01T03:18:44.277257Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import copy\ntest_model = torch.load(\"/kaggle/working/best.pt\")\ntest_model = test_model.to(device)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T03:18:44.279746Z","iopub.execute_input":"2023-10-01T03:18:44.280710Z","iopub.status.idle":"2023-10-01T03:18:44.321933Z","shell.execute_reply.started":"2023-10-01T03:18:44.280678Z","shell.execute_reply":"2023-10-01T03:18:44.320949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Open training archive file\nwith py7zr.SevenZipFile('/kaggle/input/cifar-10/test.7z', mode='r') as z:\n        z.extractall('/kaggle/working/data')","metadata":{"execution":{"iopub.status.busy":"2023-10-01T03:18:44.327188Z","iopub.execute_input":"2023-10-01T03:18:44.329728Z","iopub.status.idle":"2023-10-01T03:32:02.475982Z","shell.execute_reply.started":"2023-10-01T03:18:44.329667Z","shell.execute_reply":"2023-10-01T03:32:02.474906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data = load_imgs_and_ids('./test')\ntest_data = test_data.sort_values(by='id')","metadata":{"execution":{"iopub.status.busy":"2023-10-01T03:32:02.477666Z","iopub.execute_input":"2023-10-01T03:32:02.477990Z","iopub.status.idle":"2023-10-01T03:32:03.413532Z","shell.execute_reply.started":"2023-10-01T03:32:02.477960Z","shell.execute_reply":"2023-10-01T03:32:03.412421Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_dataset = test_data.drop('id',axis=1)\n","metadata":{"execution":{"iopub.status.busy":"2023-10-01T03:32:03.414822Z","iopub.execute_input":"2023-10-01T03:32:03.415177Z","iopub.status.idle":"2023-10-01T03:32:03.434601Z","shell.execute_reply.started":"2023-10-01T03:32:03.415147Z","shell.execute_reply":"2023-10-01T03:32:03.433701Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_Tensor = ClassificationDataset(test_dataset,data_path = \"\",transform=composed_test,training=False)\ntest_loader = torch.utils.data.DataLoader(test_Tensor, batch_size=1, num_workers=0)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T03:32:03.435831Z","iopub.execute_input":"2023-10-01T03:32:03.436388Z","iopub.status.idle":"2023-10-01T03:32:03.542370Z","shell.execute_reply.started":"2023-10-01T03:32:03.436338Z","shell.execute_reply":"2023-10-01T03:32:03.541417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def predict(model, dataloader):\n    prediction_list = []\n    for i, batch in enumerate(dataloader):\n        data = batch\n        data = data.to(device)\n        outputs = model(data)\n        _, predicted = torch.max(outputs.data, 1) \n        prediction_list.append(predicted.cpu())\n    return prediction_list","metadata":{"execution":{"iopub.status.busy":"2023-10-01T03:32:03.543831Z","iopub.execute_input":"2023-10-01T03:32:03.544126Z","iopub.status.idle":"2023-10-01T03:32:03.549926Z","shell.execute_reply.started":"2023-10-01T03:32:03.544096Z","shell.execute_reply":"2023-10-01T03:32:03.548977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = predict(test_model,test_loader)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T03:32:03.551268Z","iopub.execute_input":"2023-10-01T03:32:03.551965Z","iopub.status.idle":"2023-10-01T03:37:18.070118Z","shell.execute_reply.started":"2023-10-01T03:32:03.551935Z","shell.execute_reply":"2023-10-01T03:37:18.069139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" predictions_array = [tensor.numpy() for tensor in predictions]","metadata":{"execution":{"iopub.status.busy":"2023-10-01T03:37:18.074888Z","iopub.execute_input":"2023-10-01T03:37:18.075480Z","iopub.status.idle":"2023-10-01T03:37:19.620509Z","shell.execute_reply.started":"2023-10-01T03:37:18.075431Z","shell.execute_reply":"2023-10-01T03:37:19.619389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions_ = np.array(predictions_array)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T03:37:19.622047Z","iopub.execute_input":"2023-10-01T03:37:19.622389Z","iopub.status.idle":"2023-10-01T03:37:19.782868Z","shell.execute_reply.started":"2023-10-01T03:37:19.622358Z","shell.execute_reply":"2023-10-01T03:37:19.781817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission =  test_data.drop('path',axis=1)\nsubmission['label'] = predictions_\nsubmission.to_csv(\"submission.csv\", index=None)","metadata":{"execution":{"iopub.status.busy":"2023-10-01T03:47:46.409879Z","iopub.execute_input":"2023-10-01T03:47:46.410206Z","iopub.status.idle":"2023-10-01T03:47:46.707075Z","shell.execute_reply.started":"2023-10-01T03:47:46.410178Z","shell.execute_reply":"2023-10-01T03:47:46.706026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}