{"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":"markdown","source":"Imports & installs.","metadata":{}},{"cell_type":"code","source":"!pip install py7zr","metadata":{"execution":{"iopub.status.busy":"2023-10-04T17:15:52.341313Z","iopub.execute_input":"2023-10-04T17:15:52.341608Z","iopub.status.idle":"2023-10-04T17:16:02.713082Z","shell.execute_reply.started":"2023-10-04T17:15:52.341530Z","shell.execute_reply":"2023-10-04T17:16:02.712179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport os\nimport copy\nimport matplotlib.pyplot as plt\nfrom PIL import Image\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport torch.optim as optim\nimport torchvision.transforms as transforms\nfrom torchvision import models\nimport torchvision\nfrom torch.utils.data import DataLoader, Dataset, Subset\n\nfrom sklearn.model_selection import train_test_split\n\ndevice = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\n\nimport warnings\nwarnings.filterwarnings(\"ignore\")\n\nfrom py7zr import unpack_7zarchive\nimport shutil\nshutil.register_unpack_format('7zip', ['.7z'], unpack_7zarchive)","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:15:41.248591Z","iopub.execute_input":"2023-10-04T15:15:41.249126Z","iopub.status.idle":"2023-10-04T15:15:43.972185Z","shell.execute_reply.started":"2023-10-04T15:15:41.249090Z","shell.execute_reply":"2023-10-04T15:15:43.971414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Hyperparameters\nnum_epochs = 3\nbatch_size = 32\nlr = 0.01","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:15:43.973518Z","iopub.execute_input":"2023-10-04T15:15:43.973918Z","iopub.status.idle":"2023-10-04T15:15:43.978019Z","shell.execute_reply.started":"2023-10-04T15:15:43.973883Z","shell.execute_reply":"2023-10-04T15:15:43.976995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Load data.","metadata":{}},{"cell_type":"code","source":"#Custom dataset class\n\nclass CifarLoader(Dataset):\n  def __init__(self, root_dir, csv_file = None, transform = None):\n\n    # images directory \n    self.root_dir = root_dir\n    # transformations if any\n    self.transform = transform\n\n    if csv_file:\n      # read csv file\n      self.df = pd.read_csv(csv_file)\n\n      # {class: lbl}\n      self.annot_dict = {}\n\n      for i, lbl in enumerate(self.df['label'].unique()):\n        self.annot_dict[lbl] = i\n\n      # {lbl: class}\n      self.annot_dict_reversed = {v:k for k,v in self.annot_dict.items()}\n\n      # add a column with decoded labels\n      self.df['encoded'] = self.df['label'].map(self.annot_dict)\n\n    else: \n      # if no csv file provided -> create a df, fill labels with 0's\n      self.df = pd.DataFrame({\n          'id': list(range(1, len(os.listdir(self.root_dir)) + 1)),\n          'label': np.zeros(len(os.listdir(self.root_dir))),\n          'encoded': np.zeros(len(os.listdir(self.root_dir)))\n      })\n\n\n  def __len__(self):\n    # num of records in the df\n    return len(self.df)\n\n  def __getitem__(self, index):\n    # path to the image\n    img_path = os.path.join(self.root_dir, str(self.df.iloc[index, 0]) + '.png')\n    # read image\n    image = np.array(Image.open(img_path).convert('RGB'))\n    # get label\n    y_label = torch.tensor(int(self.df.iloc[index, 2]))\n\n    # apply transformations\n    if self.transform:\n      image = self.transform(image)\n    \n    return (image, y_label)\n","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:15:43.980020Z","iopub.execute_input":"2023-10-04T15:15:43.980426Z","iopub.status.idle":"2023-10-04T15:15:43.992468Z","shell.execute_reply.started":"2023-10-04T15:15:43.980393Z","shell.execute_reply":"2023-10-04T15:15:43.991781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# transform tensors to normalized range form [0, 1] to [-1, 1]\nmean = np.array([0.5, 0.5, 0.5])\nstd = np.array([0.5, 0.5, 0.5])\n\ntr = transforms.Compose([\n        transforms.ToPILImage(),\n        transforms.Resize((224, 224)),  \n        transforms.ToTensor(),        \n        transforms.Normalize(mean, std)\n    ])","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:15:43.993611Z","iopub.execute_input":"2023-10-04T15:15:43.994004Z","iopub.status.idle":"2023-10-04T15:15:44.008465Z","shell.execute_reply.started":"2023-10-04T15:15:43.993972Z","shell.execute_reply":"2023-10-04T15:15:44.007778Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# unzip train and test data\nshutil.unpack_archive('../input/cifar-10/train.7z')","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:15:44.009526Z","iopub.execute_input":"2023-10-04T15:15:44.010319Z","iopub.status.idle":"2023-10-04T15:16:28.534088Z","shell.execute_reply.started":"2023-10-04T15:15:44.010286Z","shell.execute_reply":"2023-10-04T15:16:28.533297Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset = CifarLoader(csv_file = '../input/cifar-10/trainLabels.csv', \n                      root_dir = './train',\n                      transform = tr)\n\nprint(dataset.df.head())","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:16:28.535462Z","iopub.execute_input":"2023-10-04T15:16:28.535890Z","iopub.status.idle":"2023-10-04T15:16:28.590475Z","shell.execute_reply.started":"2023-10-04T15:16:28.535853Z","shell.execute_reply":"2023-10-04T15:16:28.589693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#split the data\nindexes = list(range(len(dataset)))\n\ntrain_indexes, val_indexes = train_test_split(indexes, test_size=0.2)\n\ndata = {}\ndata['train'] = Subset(dataset, train_indexes)\ndata['val'] = Subset(dataset, val_indexes)\n\ndataloader_train = DataLoader(dataset = data['train'], batch_size = batch_size, shuffle=False)\ndataloader_val = DataLoader(dataset = data['val'], batch_size = batch_size, shuffle=False)","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:16:28.591511Z","iopub.execute_input":"2023-10-04T15:16:28.592282Z","iopub.status.idle":"2023-10-04T15:16:28.611924Z","shell.execute_reply.started":"2023-10-04T15:16:28.592245Z","shell.execute_reply":"2023-10-04T15:16:28.611190Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(train_indexes), len(val_indexes))","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:16:28.613329Z","iopub.execute_input":"2023-10-04T15:16:28.613577Z","iopub.status.idle":"2023-10-04T15:16:28.623383Z","shell.execute_reply.started":"2023-10-04T15:16:28.613545Z","shell.execute_reply":"2023-10-04T15:16:28.622516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"################################ SHOW IMAGES ##################################\n\ndef images_show(images, lbls=None):\n  # show only 4 first images from each batch\n  for i in range(4):\n    plt.subplot(1, 4, i + 1)\n    # convert to numpy\n    img = images[i].numpy().transpose((1, 2, 0))\n    # unnormalize\n    img = img * std + mean \n    img = np.clip(img, a_min=0, a_max=1)\n    plt.imshow(img)\n \n    if lbls != None:\n      # decode labels using reversed annotation dictionary\n      plt.title(dataset.annot_dict_reversed[lbls[i].item()])\n    plt.axis('off')\n  plt.tight_layout(pad=0.5)\n  plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:16:28.626476Z","iopub.execute_input":"2023-10-04T15:16:28.626674Z","iopub.status.idle":"2023-10-04T15:16:28.635630Z","shell.execute_reply.started":"2023-10-04T15:16:28.626646Z","shell.execute_reply":"2023-10-04T15:16:28.634913Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataiter = iter(dataloader_train)\nimages, labels = dataiter.next()\n\nprint(f'Shape: {images.shape}')\nprint(f'Max: {torch.max(images[0]):.2f}')\nprint(f'Min: {torch.min(images[0]):.2f}')\n\nfor i in range(3):\n  images, labels = dataiter.next()\n  images_show(images, labels)","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:16:28.636885Z","iopub.execute_input":"2023-10-04T15:16:28.637436Z","iopub.status.idle":"2023-10-04T15:16:29.943205Z","shell.execute_reply.started":"2023-10-04T15:16:28.637402Z","shell.execute_reply":"2023-10-04T15:16:29.942537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Load pretrained DenseNet-121.","metadata":{}},{"cell_type":"code","source":"################################ FINETUNING ##################################\n\n# Load a pretrained model and reset final fully connected layer\n\n# load a pretrained model \nmodel = models.densenet121(pretrained=True)\n\n# reset final fully connected layer\nnum_ftrs = model.classifier.in_features\n\nmodel.classifier = nn.Sequential(\n                        nn.Linear(num_ftrs, 256),  \n                        nn.ReLU(), \n                        nn.Dropout(0.3),\n                        nn.Linear(256, 10))\n\n# copy weights for futher retraining on full train dataset\nmodel_wts = copy.deepcopy(model.state_dict())\n\n# move model to a device\nmodel = model.to(device)\n\n# loss\ncriterion = nn.CrossEntropyLoss()\n\n# all parameters are being optimized\noptimizer = optim.SGD(model.parameters(), lr=lr)","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:16:29.944584Z","iopub.execute_input":"2023-10-04T15:16:29.945033Z","iopub.status.idle":"2023-10-04T15:16:34.457312Z","shell.execute_reply.started":"2023-10-04T15:16:29.944999Z","shell.execute_reply":"2023-10-04T15:16:34.456528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"################################ TRAINING FUNC ################################\n\ndef train(model, criterion, optimizer, num_epochs, \n          dataloader_train, dataloader_val = None):\n\n  history = {\n        'loss': [],\n        'accuracy': [],\n        'val_loss': [],\n        'val_accuracy': [],\n        'best train acc': (0, 0)\n        }\n\n  best_model_wts = copy.deepcopy(model.state_dict())\n  best_acc = 0.0\n\n\n  for epoch in range(num_epochs):\n    print('Epoch {}/{}'.format(epoch + 1, num_epochs))\n\n    # set model to the training mode\n    model.train()\n\n    n_samples = 0\n    correct_train = 0\n    epoch_loss_train = 0\n    epoch_loss_val = 0\n\n\n    for i, (images, labels) in enumerate(dataloader_train):\n      # origin shape: [4, 3, 32, 32] = 4, 3, 1024\n    \n      images = images.to(device)\n      labels = labels.to(device)\n\n      # forward pass (pred)\n      pred = model(images)\n\n      # loss\n      loss = criterion(pred, labels)\n\n      # mean loss * num samples in batch\n      epoch_loss_train += labels.shape[0] * loss.item()\n\n      # empty gradients\n      optimizer.zero_grad()\n\n      # gradient (backpropagation)\n      loss.backward()\n\n      # update weights\n      optimizer.step()\n\n      # values, indexes\n      value, predicted = torch.max(pred, 1)\n\n      # += batch_size\n      n_samples += labels.shape[0]\n      # num of correctly predicted in this batch\n      correct_train += (predicted==labels).sum().item()\n\n    # train acc per epoch\n    train_acc = 100 * correct_train / n_samples\n    # train loss per epoch\n    epoch_loss_train = epoch_loss_train / n_samples\n\n    print(f'Train accuracy: {train_acc:.2f}, loss: {epoch_loss_train:.2f}')\n    #print(f'Best accuracy: {best_acc:.2f}')\n\n    history['accuracy'].append(train_acc)\n    history['loss'].append(epoch_loss_train)\n\n    # find best accuracy on training data\n    if train_acc > best_acc:\n\n      #print('*New best accuracy*')\n      best_acc = train_acc\n\n      # copy current model weights\n      best_model_wts = copy.deepcopy(model.state_dict())\n      history['best train acc'] = (epoch, best_acc)\n\n\n    if dataloader_val:\n\n      # evaluation mode\n      model.eval()\n\n      with torch.no_grad():\n        correct_val = 0\n        n_samples = 0\n\n        for images, labels in dataloader_val: \n          images = images.to(device)\n          labels = labels.to(device)\n\n          outputs = model(images)\n\n          loss = criterion(outputs, labels)\n          epoch_loss_val += labels.shape[0] * loss.item()\n\n          # value, index\n          _, pred = torch.max(outputs, 1)\n          n_samples += labels.shape[0]\n          correct_val += (pred==labels).sum().item()\n\n        # calculate validation accuracy and loss for each epoch\n        val_acc = 100 * correct_val / len(data['val'])\n        epoch_loss_val = epoch_loss_val / len(data['val'])\n\n        print(f'Val accuracy: {val_acc:.2f}, loss: {epoch_loss_val:.2f}')\n\n        history['val_accuracy'].append(val_acc)\n        history['val_loss'].append(epoch_loss_val)\n      \n    print('=' * 80)\n\n\n  print('Best train acc: {:2f}'.format(best_acc))\n\n  # load best weights\n  model.load_state_dict(best_model_wts)\n\n  return model, history","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:16:34.458771Z","iopub.execute_input":"2023-10-04T15:16:34.459185Z","iopub.status.idle":"2023-10-04T15:16:34.472502Z","shell.execute_reply.started":"2023-10-04T15:16:34.459146Z","shell.execute_reply":"2023-10-04T15:16:34.471779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model, history = train(model, criterion, optimizer, num_epochs, \n                       dataloader_train, dataloader_val)","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:16:34.473882Z","iopub.execute_input":"2023-10-04T15:16:34.474307Z","iopub.status.idle":"2023-10-04T15:33:30.627749Z","shell.execute_reply.started":"2023-10-04T15:16:34.474269Z","shell.execute_reply":"2023-10-04T15:33:30.626967Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_history(history):\n   \n    loss = history['loss']\n    accuracy = history['accuracy']\n    val_loss = history['val_loss']\n    val_accuracy = history['val_accuracy']\n    x = range(len(loss))\n\n    plt.figure(figsize=(12, 5))\n    plt.subplot(1, 2, 1)\n    plt.plot(x, accuracy, label='Training acc', color='#03045e', linewidth=2)\n    if len(val_loss) != 0:\n      plt.plot(x, val_accuracy, label='Validation acc', color='#48cae4', linewidth=2)\n    plt.plot(history['best train acc'][0], \n             history['best train acc'][1], \n             'bo', label='Best train acc', markersize=7, color='black')\n    plt.title('Accuracy')\n    plt.grid(True)\n    plt.legend()\n    \n    plt.subplot(1, 2, 2)\n    plt.plot(x, loss, label='Training loss', color='#03045e', linewidth=2)\n    if len(val_loss) != 0:\n      plt.plot(x, val_loss, label='Validation loss', color='#48cae4', linewidth=2)\n    plt.title('Loss')\n    plt.grid(True)\n    plt.legend()","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:33:30.629624Z","iopub.execute_input":"2023-10-04T15:33:30.630157Z","iopub.status.idle":"2023-10-04T15:33:30.638238Z","shell.execute_reply.started":"2023-10-04T15:33:30.630118Z","shell.execute_reply":"2023-10-04T15:33:30.637528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_history(history)","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:33:30.639370Z","iopub.execute_input":"2023-10-04T15:33:30.640246Z","iopub.status.idle":"2023-10-04T15:33:31.049222Z","shell.execute_reply.started":"2023-10-04T15:33:30.640210Z","shell.execute_reply":"2023-10-04T15:33:31.048540Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"################################## EVALUATE ##################################\ndef evaluate(model, dataloader):\n\n  with torch.no_grad():\n    model.eval()\n    n_correct = 0\n    n_samples = 0\n\n    for images, labels in dataloader: \n      images = images.to(device)\n      labels = labels.to(device)\n\n      outputs = model(images)\n\n      # value, index\n      v, pred = torch.max(outputs, 1)\n\n      n_samples += labels.shape[0]\n      n_correct += (pred==labels).sum().item()\n\n    acc = 100.0 * n_correct / n_samples\n    print(acc)","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:33:31.050487Z","iopub.execute_input":"2023-10-04T15:33:31.050916Z","iopub.status.idle":"2023-10-04T15:33:31.057813Z","shell.execute_reply.started":"2023-10-04T15:33:31.050877Z","shell.execute_reply":"2023-10-04T15:33:31.057015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"evaluate(model, dataloader_val)","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:33:31.059259Z","iopub.execute_input":"2023-10-04T15:33:31.059655Z","iopub.status.idle":"2023-10-04T15:34:04.629955Z","shell.execute_reply.started":"2023-10-04T15:33:31.059621Z","shell.execute_reply":"2023-10-04T15:34:04.629181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Retrain model on full training set.","metadata":{}},{"cell_type":"code","source":"############################## COMPLETE DATASET ###############################\n\ndataloader = DataLoader(dataset = dataset, batch_size = batch_size, shuffle=False)","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:34:04.631091Z","iopub.execute_input":"2023-10-04T15:34:04.631800Z","iopub.status.idle":"2023-10-04T15:34:04.636553Z","shell.execute_reply.started":"2023-10-04T15:34:04.631763Z","shell.execute_reply":"2023-10-04T15:34:04.635786Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shutil.unpack_archive('../input/cifar-10/test.7z')\ndataset_test = CifarLoader(root_dir = './test',\n                      transform = tr)\n\ndataloader_test = DataLoader(dataset = dataset_test, \n                             batch_size = batch_size, shuffle=False)","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:34:04.637987Z","iopub.execute_input":"2023-10-04T15:34:04.638500Z","iopub.status.idle":"2023-10-04T15:47:46.955788Z","shell.execute_reply.started":"2023-10-04T15:34:04.638439Z","shell.execute_reply":"2023-10-04T15:47:46.955022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"################################# RESET MODEL ##################################\n\nmodel.load_state_dict(model_wts)\n\n# loss\ncriterion = nn.CrossEntropyLoss()\n\n# all parameters are being optimized\noptimizer = optim.SGD(model.parameters(), lr=lr)","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:47:46.957185Z","iopub.execute_input":"2023-10-04T15:47:46.957599Z","iopub.status.idle":"2023-10-04T15:47:47.034782Z","shell.execute_reply.started":"2023-10-04T15:47:46.957548Z","shell.execute_reply":"2023-10-04T15:47:47.033993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model, history = train(model, criterion, optimizer, 3, dataloader)","metadata":{"execution":{"iopub.status.busy":"2023-10-04T15:47:47.036168Z","iopub.execute_input":"2023-10-04T15:47:47.036432Z","iopub.status.idle":"2023-10-04T16:06:17.086620Z","shell.execute_reply.started":"2023-10-04T15:47:47.036401Z","shell.execute_reply":"2023-10-04T16:06:17.085885Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(dataset_test))","metadata":{"execution":{"iopub.status.busy":"2023-10-04T16:06:17.088228Z","iopub.execute_input":"2023-10-04T16:06:17.088651Z","iopub.status.idle":"2023-10-04T16:06:17.093684Z","shell.execute_reply.started":"2023-10-04T16:06:17.088614Z","shell.execute_reply":"2023-10-04T16:06:17.093015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"################################### PREDICT ####################################\n\npredictions = np.array([])\n\nwith torch.no_grad():\n    model.eval()\n\n    for images, _ in dataloader_test:\n      images = images.to(device)\n\n      outputs = model(images)\n\n      # value, index\n      v, pred = torch.max(outputs, 1)\n\n      pred = pred.cpu().numpy()\n\n      predictions = np.concatenate((predictions, pred), axis = None)","metadata":{"execution":{"iopub.status.busy":"2023-10-04T16:06:17.094913Z","iopub.execute_input":"2023-10-04T16:06:17.095582Z","iopub.status.idle":"2023-10-04T16:23:00.515066Z","shell.execute_reply.started":"2023-10-04T16:06:17.095548Z","shell.execute_reply":"2023-10-04T16:23:00.514292Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_test.df['encoded'] = predictions.astype(int)","metadata":{"execution":{"iopub.status.busy":"2023-10-04T16:23:00.516404Z","iopub.execute_input":"2023-10-04T16:23:00.516824Z","iopub.status.idle":"2023-10-04T16:23:00.523155Z","shell.execute_reply.started":"2023-10-04T16:23:00.516789Z","shell.execute_reply":"2023-10-04T16:23:00.522374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_test.df['label'] = dataset_test.df['encoded'].map(dataset.annot_dict_reversed)","metadata":{"execution":{"iopub.status.busy":"2023-10-04T16:23:00.524440Z","iopub.execute_input":"2023-10-04T16:23:00.524879Z","iopub.status.idle":"2023-10-04T16:23:00.542307Z","shell.execute_reply.started":"2023-10-04T16:23:00.524845Z","shell.execute_reply":"2023-10-04T16:23:00.541504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_test.df.head()","metadata":{"execution":{"iopub.status.busy":"2023-10-04T16:23:00.543284Z","iopub.execute_input":"2023-10-04T16:23:00.543538Z","iopub.status.idle":"2023-10-04T16:23:00.555456Z","shell.execute_reply.started":"2023-10-04T16:23:00.543497Z","shell.execute_reply":"2023-10-04T16:23:00.554642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataiter = iter(dataloader_test)\nimages, labels = dataiter.next()\n\nfor i in range(3):\n  images, labels = dataiter.next()\n  images_show(images, labels)","metadata":{"execution":{"iopub.status.busy":"2023-10-04T16:23:00.559610Z","iopub.execute_input":"2023-10-04T16:23:00.559948Z","iopub.status.idle":"2023-10-04T16:23:01.671594Z","shell.execute_reply.started":"2023-10-04T16:23:00.559924Z","shell.execute_reply":"2023-10-04T16:23:01.670920Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Submission file:","metadata":{}},{"cell_type":"code","source":"dataset_test.df.drop(columns ='encoded', inplace=True)\ndataset_test.df.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-10-04T16:23:01.672631Z","iopub.execute_input":"2023-10-04T16:23:01.673014Z","iopub.status.idle":"2023-10-04T16:23:01.998242Z","shell.execute_reply.started":"2023-10-04T16:23:01.672980Z","shell.execute_reply":"2023-10-04T16:23:01.997294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%rm -rf ./train\n%rm -rf ./test","metadata":{"execution":{"iopub.status.busy":"2023-10-04T16:23:01.999414Z","iopub.execute_input":"2023-10-04T16:23:01.999824Z","iopub.status.idle":"2023-10-04T16:23:15.457640Z","shell.execute_reply.started":"2023-10-04T16:23:01.999789Z","shell.execute_reply":"2023-10-04T16:23:15.456542Z"},"trusted":true},"execution_count":null,"outputs":[]}]}