{"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":"!pip install -q efficientnet_pytorch > /dev/null","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-03-23T07:33:44.695613Z","iopub.execute_input":"2022-03-23T07:33:44.695989Z","iopub.status.idle":"2022-03-23T07:33:54.115806Z","shell.execute_reply.started":"2022-03-23T07:33:44.695958Z","shell.execute_reply":"2022-03-23T07:33:54.114821Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" '/opt/conda/bin/python3.7 -m pip install --upgrade pip'","metadata":{"execution":{"iopub.status.busy":"2022-03-23T07:34:00.797799Z","iopub.execute_input":"2022-03-23T07:34:00.798159Z","iopub.status.idle":"2022-03-23T07:34:00.804063Z","shell.execute_reply.started":"2022-03-23T07:34:00.798127Z","shell.execute_reply":"2022-03-23T07:34:00.803238Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from glob import glob\nfrom sklearn.model_selection import GroupKFold\nimport cv2\nfrom skimage import io\nimport torch\nfrom torch import nn\nimport os\nfrom datetime import datetime\nimport time\nimport random\nimport cv2\nimport pandas as pd\nimport numpy as np\nimport albumentations as A\nimport matplotlib.pyplot as plt\nfrom albumentations.pytorch.transforms import ToTensorV2\nfrom torch.utils.data import Dataset,DataLoader\nfrom torch.utils.data.sampler import SequentialSampler, RandomSampler\nimport sklearn\nimport warnings\nwarnings.filterwarnings('ignore')\n\nSEED = 42\n\ndef seed_everything(seed):\n    random.seed(seed)\n    os.environ['PYTHONHASHSEED'] = str(seed)\n    np.random.seed(seed)\n    torch.manual_seed(seed)\n    torch.cuda.manual_seed(seed)\n    torch.backends.cudnn.deterministic = True\n    torch.backends.cudnn.benchmark = True\n\nseed_everything(SEED)","metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","execution":{"iopub.status.busy":"2022-03-23T07:33:08.742932Z","iopub.execute_input":"2022-03-23T07:33:08.743168Z","iopub.status.idle":"2022-03-23T07:33:11.540066Z","shell.execute_reply.started":"2022-03-23T07:33:08.743145Z","shell.execute_reply":"2022-03-23T07:33:11.53928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"GroupKFold splitting","metadata":{}},{"cell_type":"code","source":"%%time\n\ndataset = []\n\nfor label, kind in enumerate(['Cover', 'JMiPOD', 'JUNIWARD', 'UERD']):\n    for path in glob('../input/alaska2-image-steganalysis/Cover/*.jpg'):\n        dataset.append({\n            'kind': kind,\n            'image_name': path.split('/')[-1],\n            'label': label\n        })","metadata":{"execution":{"iopub.status.busy":"2022-03-23T07:33:11.541788Z","iopub.execute_input":"2022-03-23T07:33:11.542128Z","iopub.status.idle":"2022-03-23T07:33:14.015898Z","shell.execute_reply.started":"2022-03-23T07:33:11.5421Z","shell.execute_reply":"2022-03-23T07:33:14.015068Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_small = dataset[0:5000]+dataset[75000:80000]+dataset[150000:155000]+dataset[225000:223000]\nrandom.shuffle(dataset_small)\ndataset = pd.DataFrame(dataset_small)\n\ngkf = GroupKFold(n_splits=5)\n\ndataset.loc[:, 'fold'] = 0\nfor fold_number, (train_index, val_index) in enumerate(gkf.split(X=dataset.index, y=dataset['label'], groups=dataset['image_name'])):\n    dataset.loc[dataset.iloc[val_index].index, 'fold'] = fold_number","metadata":{"execution":{"iopub.status.busy":"2022-03-23T07:33:14.018738Z","iopub.execute_input":"2022-03-23T07:33:14.019329Z","iopub.status.idle":"2022-03-23T07:33:14.160913Z","shell.execute_reply.started":"2022-03-23T07:33:14.019283Z","shell.execute_reply":"2022-03-23T07:33:14.160112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_train_transforms():\n    return A.Compose([\n            A.HorizontalFlip(p=0.5),\n            A.VerticalFlip(p=0.5),\n            A.Resize(height=512, width=512, p=1.0),\n            ToTensorV2(p=1.0),\n        ], p=1.0)\n\ndef get_valid_transforms():\n    return A.Compose([\n            A.Resize(height=512, width=512, p=1.0),\n            ToTensorV2(p=1.0),\n        ], p=1.0)","metadata":{"execution":{"iopub.status.busy":"2022-03-23T07:33:14.164323Z","iopub.execute_input":"2022-03-23T07:33:14.164613Z","iopub.status.idle":"2022-03-23T07:33:14.171648Z","shell.execute_reply.started":"2022-03-23T07:33:14.164584Z","shell.execute_reply":"2022-03-23T07:33:14.170714Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DATA_ROOT_PATH = '../input/alaska2-image-steganalysis'\n\ndef onehot(size, target):\n    vec = torch.zeros(size, dtype=torch.float32)\n    vec[target] = 1.\n    return vec\n\nclass DatasetRetriever(Dataset):\n\n    def __init__(self, kinds, image_names, labels, transforms=None):\n        super().__init__()\n        self.kinds = kinds\n        self.image_names = image_names\n        self.labels = labels\n        self.transforms = transforms\n\n    def __getitem__(self, index: int):\n        kind, image_name, label = self.kinds[index], self.image_names[index], self.labels[index]\n        image = cv2.imread(f'{DATA_ROOT_PATH}/{kind}/{image_name}', cv2.IMREAD_COLOR)\n        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB).astype(np.float32)\n        image /= 255.0\n        if self.transforms:\n            sample = {'image': image}\n            sample = self.transforms(**sample)\n            image = sample['image']\n            \n        target = onehot(4, label)\n        return image, target\n\n    def __len__(self) -> int:\n        return self.image_names.shape[0]\n\n    def get_labels(self):\n        return list(self.labels)","metadata":{"execution":{"iopub.status.busy":"2022-03-23T07:33:14.174891Z","iopub.execute_input":"2022-03-23T07:33:14.175546Z","iopub.status.idle":"2022-03-23T07:33:14.189775Z","shell.execute_reply.started":"2022-03-23T07:33:14.175505Z","shell.execute_reply":"2022-03-23T07:33:14.188921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fold_number = 0\n\ntrain_dataset = DatasetRetriever(\n    kinds=dataset[dataset['fold'] != fold_number].kind.values,\n    image_names=dataset[dataset['fold'] != fold_number].image_name.values,\n    labels=dataset[dataset['fold'] != fold_number].label.values,\n    transforms=get_train_transforms(),\n)\n\nvalidation_dataset = DatasetRetriever(\n    kinds=dataset[dataset['fold'] == fold_number].kind.values,\n    image_names=dataset[dataset['fold'] == fold_number].image_name.values,\n    labels=dataset[dataset['fold'] == fold_number].label.values,\n    transforms=get_valid_transforms(),\n)","metadata":{"execution":{"iopub.status.busy":"2022-03-23T07:33:14.191783Z","iopub.execute_input":"2022-03-23T07:33:14.19229Z","iopub.status.idle":"2022-03-23T07:33:14.20935Z","shell.execute_reply.started":"2022-03-23T07:33:14.19225Z","shell.execute_reply":"2022-03-23T07:33:14.208355Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image, target = train_dataset[0]\nnumpy_image = image.permute(1,2,0).cpu().numpy()\n\nfig, ax = plt.subplots(1, 1, figsize=(16, 8))\n    \nax.set_axis_off()\nax.imshow(numpy_image);\n","metadata":{"execution":{"iopub.status.busy":"2022-03-23T07:33:14.210807Z","iopub.execute_input":"2022-03-23T07:33:14.211184Z","iopub.status.idle":"2022-03-23T07:33:14.562284Z","shell.execute_reply.started":"2022-03-23T07:33:14.211146Z","shell.execute_reply":"2022-03-23T07:33:14.561423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn import metrics\n\nclass AverageMeter(object):\n    \"\"\"Computes and stores the average and current value\"\"\"\n    def __init__(self):\n        self.reset()\n\n    def reset(self):\n        self.val = 0\n        self.avg = 0\n        self.sum = 0\n        self.count = 0\n\n    def update(self, val, n=1):\n        self.val = val\n        self.sum += val * n\n        self.count += n\n        self.avg = self.sum / self.count\n        \n        \ndef alaska_weighted_auc(y_true, y_valid):\n    \"\"\"\n    https://www.kaggle.com/anokas/weighted-auc-metric-updated\n    \"\"\"\n    tpr_thresholds = [0.0, 0.4, 1.0]\n    weights = [2, 1]\n\n    fpr, tpr, thresholds = metrics.roc_curve(y_true, y_valid, pos_label=1)\n\n    # size of subsets\n    areas = np.array(tpr_thresholds[1:]) - np.array(tpr_thresholds[:-1])\n\n    # The total area is normalized by the sum of weights such that the final weighted AUC is between 0 and 1.\n    normalization = np.dot(areas, weights)\n\n    competition_metric = 0\n    for idx, weight in enumerate(weights):\n        y_min = tpr_thresholds[idx]\n        y_max = tpr_thresholds[idx + 1]\n        mask = (y_min < tpr) & (tpr < y_max)\n        # pdb.set_trace()\n\n        x_padding = np.linspace(fpr[mask][-1], 1, 100)\n\n        x = np.concatenate([fpr[mask], x_padding])\n        y = np.concatenate([tpr[mask], [y_max] * len(x_padding)])\n        y = y - y_min  # normalize such that curve starts at y=0\n        score = metrics.auc(x, y)\n        submetric = score * weight\n        best_subscore = (y_max - y_min) * weight\n        competition_metric += submetric\n\n    return competition_metric / normalization\n        \nclass RocAucMeter(object):\n    def __init__(self):\n        self.reset()\n\n    def reset(self):\n        self.y_true = np.array([0,1])\n        self.y_pred = np.array([0.5,0.5])\n        self.score = 0\n\n    def update(self, y_true, y_pred):\n        y_true = y_true.cpu().numpy().argmax(axis=1).clip(min=0, max=1).astype(int)\n        y_pred = 1 - nn.functional.softmax(y_pred, dim=1).data.cpu().numpy()[:,0]\n        self.y_true = np.hstack((self.y_true, y_true))\n        self.y_pred = np.hstack((self.y_pred, y_pred))\n        self.score = alaska_weighted_auc(self.y_true, self.y_pred)\n    \n    @property\n    def avg(self):\n        return self.score","metadata":{"execution":{"iopub.status.busy":"2022-03-23T07:33:14.56345Z","iopub.execute_input":"2022-03-23T07:33:14.563781Z","iopub.status.idle":"2022-03-23T07:33:14.587279Z","shell.execute_reply.started":"2022-03-23T07:33:14.563748Z","shell.execute_reply":"2022-03-23T07:33:14.58649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class LabelSmoothing(nn.Module):\n    def __init__(self, smoothing = 0.05):\n        super(LabelSmoothing, self).__init__()\n        self.confidence = 1.0 - smoothing\n        self.smoothing = smoothing\n\n    def forward(self, x, target):\n        if self.training:\n            x = x.float()\n            target = target.float()\n            logprobs = torch.nn.functional.log_softmax(x, dim = -1)\n\n            nll_loss = -logprobs * target\n            nll_loss = nll_loss.sum(-1)\n    \n            smooth_loss = -logprobs.mean(dim=-1)\n\n            loss = self.confidence * nll_loss + self.smoothing * smooth_loss\n\n            return loss.mean()\n        else:\n            return torch.nn.functional.cross_entropy(x, target)","metadata":{"execution":{"iopub.status.busy":"2022-03-23T07:33:14.59027Z","iopub.execute_input":"2022-03-23T07:33:14.59057Z","iopub.status.idle":"2022-03-23T07:33:14.600964Z","shell.execute_reply.started":"2022-03-23T07:33:14.590542Z","shell.execute_reply":"2022-03-23T07:33:14.600137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import warnings\n\nwarnings.filterwarnings(\"ignore\")\n\nclass Fitter:\n    \n    def __init__(self, model, device, config):\n        self.config = config\n        self.epoch = 0\n        \n        self.base_dir = './'\n        self.log_path = f'{self.base_dir}/log.txt'\n        self.best_summary_loss = 10**5\n\n        self.model = model\n        self.device = device\n\n        param_optimizer = list(self.model.named_parameters())\n        no_decay = ['bias', 'LayerNorm.bias', 'LayerNorm.weight']\n        optimizer_grouped_parameters = [\n            {'params': [p for n, p in param_optimizer if not any(nd in n for nd in no_decay)], 'weight_decay': 0.001},\n            {'params': [p for n, p in param_optimizer if any(nd in n for nd in no_decay)], 'weight_decay': 0.0}\n        ] \n\n        self.optimizer = torch.optim.AdamW(self.model.parameters(), lr=config.lr)\n        self.scheduler = config.SchedulerClass(self.optimizer, **config.scheduler_params)\n        self.criterion = LabelSmoothing().to(self.device)\n        self.log(f'Fitter prepared. Device is {self.device}')\n\n    def fit(self, train_loader, validation_loader):\n        for e in range(self.config.n_epochs):\n            if self.config.verbose:\n                lr = self.optimizer.param_groups[0]['lr']\n                timestamp = datetime.utcnow().isoformat()\n                self.log(f'\\n{timestamp}\\nLR: {lr}')\n\n            t = time.time()\n            summary_loss, final_scores = self.train_one_epoch(train_loader)\n\n            self.log(f'[RESULT]: Train. Epoch: {self.epoch}, summary_loss: {summary_loss.avg:.5f}, final_score: {final_scores.avg:.5f}, time: {(time.time() - t):.5f}')\n            self.save(f'{self.base_dir}/last-checkpoint.bin')\n\n            t = time.time()\n            summary_loss, final_scores = self.validation(validation_loader)\n\n            self.log(f'[RESULT]: Val. Epoch: {self.epoch}, summary_loss: {summary_loss.avg:.5f}, final_score: {final_scores.avg:.5f}, time: {(time.time() - t):.5f}')\n            if summary_loss.avg < self.best_summary_loss:\n                self.best_summary_loss = summary_loss.avg\n                self.model.eval()\n                self.save(f'{self.base_dir}/best-checkpoint-{str(self.epoch).zfill(3)}epoch.bin')\n                for path in sorted(glob(f'{self.base_dir}/best-checkpoint-*epoch.bin'))[:-3]:\n                    os.remove(path)\n\n            if self.config.validation_scheduler:\n                self.scheduler.step(metrics=summary_loss.avg)\n\n            self.epoch += 1\n\n    def validation(self, val_loader):\n        self.model.eval()\n        summary_loss = AverageMeter()\n        final_scores = RocAucMeter()\n        t = time.time()\n        for step, (images, targets) in enumerate(val_loader):\n            if self.config.verbose:\n                if step % self.config.verbose_step == 0:\n                    print(\n                        f'Val Step {step}/{len(val_loader)}, ' + \\\n                        f'summary_loss: {summary_loss.avg:.5f}, final_score: {final_scores.avg:.5f}, ' + \\\n                        f'time: {(time.time() - t):.5f}', end='\\r'\n                    )\n            with torch.no_grad():\n                targets = targets.to(self.device).float()\n                batch_size = images.shape[0]\n                images = images.to(self.device).float()\n                outputs = self.model(images)\n                loss = self.criterion(outputs, targets)\n                final_scores.update(targets, outputs)\n                summary_loss.update(loss.detach().item(), batch_size)\n\n        return summary_loss, final_scores\n\n    def train_one_epoch(self, train_loader):\n        self.model.train()\n        summary_loss = AverageMeter()\n        final_scores = RocAucMeter()\n        t = time.time()\n        for step, (images, targets) in enumerate(train_loader):\n            if self.config.verbose:\n                if step % self.config.verbose_step == 0:\n                    print(\n                        f'Train Step {step}/{len(train_loader)}, ' + \\\n                        f'summary_loss: {summary_loss.avg:.5f}, final_score: {final_scores.avg:.5f}, ' + \\\n                        f'time: {(time.time() - t):.5f}', end='\\r'\n                    )\n            \n            targets = targets.to(self.device).float()\n            images = images.to(self.device).float()\n            batch_size = images.shape[0]\n\n            self.optimizer.zero_grad()\n            outputs = self.model(images)\n            loss = self.criterion(outputs, targets)\n            loss.backward()\n            \n            final_scores.update(targets, outputs)\n            summary_loss.update(loss.detach().item(), batch_size)\n\n            self.optimizer.step()\n\n            if self.config.step_scheduler:\n                self.scheduler.step()\n\n        return summary_loss, final_scores\n    \n    def save(self, path):\n        self.model.eval()\n        torch.save({\n            'model_state_dict': self.model.state_dict(),\n            'optimizer_state_dict': self.optimizer.state_dict(),\n            'scheduler_state_dict': self.scheduler.state_dict(),\n            'best_summary_loss': self.best_summary_loss,\n            'epoch': self.epoch,\n        }, path)\n\n    def load(self, path):\n        checkpoint = torch.load(path)\n        self.model.load_state_dict(checkpoint['model_state_dict'])\n        self.optimizer.load_state_dict(checkpoint['optimizer_state_dict'])\n        self.scheduler.load_state_dict(checkpoint['scheduler_state_dict'])\n        self.best_summary_loss = checkpoint['best_summary_loss']\n        self.epoch = checkpoint['epoch'] + 1\n        \n    def log(self, message):\n        if self.config.verbose:\n            print(message)\n        with open(self.log_path, 'a+') as logger:\n            logger.write(f'{message}\\n')","metadata":{"execution":{"iopub.status.busy":"2022-03-23T07:33:14.602577Z","iopub.execute_input":"2022-03-23T07:33:14.603312Z","iopub.status.idle":"2022-03-23T07:33:14.639925Z","shell.execute_reply.started":"2022-03-23T07:33:14.603272Z","shell.execute_reply":"2022-03-23T07:33:14.639183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from efficientnet_pytorch import EfficientNet\n\ndef get_net():\n    net = EfficientNet.from_pretrained('efficientnet-b2')\n    net._fc = nn.Linear(in_features=1408, out_features=4, bias=True)\n    return net\n\nnet = get_net().cuda()","metadata":{"execution":{"iopub.status.busy":"2022-03-23T07:34:13.563224Z","iopub.execute_input":"2022-03-23T07:34:13.563571Z","iopub.status.idle":"2022-03-23T07:34:20.543883Z","shell.execute_reply.started":"2022-03-23T07:34:13.563541Z","shell.execute_reply":"2022-03-23T07:34:20.542952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Model 1 : Baseline Model Configuration","metadata":{}},{"cell_type":"code","source":"class TrainGlobalConfig:\n    num_workers = 4\n    batch_size = 16 \n    n_epochs = 1\n    lr = 0.001\n    verbose = True\n    verbose_step = 1\n\n    step_scheduler = False  # do scheduler.step after optimizer.step\n    validation_scheduler = True  # do scheduler.step after validation stage loss\n    \n    SchedulerClass = torch.optim.lr_scheduler.ReduceLROnPlateau\n    scheduler_params = dict(\n        mode='min',\n        factor=0.5,\n        patience=1,\n        verbose=False, \n        threshold=0.0001,\n        threshold_mode='abs',\n        cooldown=0, \n        min_lr=1e-8,\n        eps=1e-08\n    )","metadata":{"execution":{"iopub.status.busy":"2022-03-23T07:34:49.59834Z","iopub.execute_input":"2022-03-23T07:34:49.598695Z","iopub.status.idle":"2022-03-23T07:34:49.607797Z","shell.execute_reply.started":"2022-03-23T07:34:49.598659Z","shell.execute_reply":"2022-03-23T07:34:49.606638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from catalyst.data.sampler import BalanceClassSampler\n\ndef run_training():\n    device = torch.device('cuda:0')\n\n    train_loader = torch.utils.data.DataLoader(\n        train_dataset,\n        sampler=BalanceClassSampler(labels=train_dataset.get_labels(), mode=\"downsampling\"),\n        batch_size=TrainGlobalConfig.batch_size,\n        pin_memory=False,\n        drop_last=True,\n        num_workers=TrainGlobalConfig.num_workers,\n    )\n    val_loader = torch.utils.data.DataLoader(\n        validation_dataset, \n        batch_size=TrainGlobalConfig.batch_size,\n        num_workers=TrainGlobalConfig.num_workers,\n        shuffle=False,\n        sampler=SequentialSampler(validation_dataset),\n        pin_memory=False,\n    )\n\n    fitter = Fitter(model=net, device=device, config=TrainGlobalConfig)\n    fitter.fit(train_loader, val_loader)","metadata":{"execution":{"iopub.status.busy":"2022-03-23T07:34:52.699595Z","iopub.execute_input":"2022-03-23T07:34:52.699962Z","iopub.status.idle":"2022-03-23T07:34:53.447327Z","shell.execute_reply.started":"2022-03-23T07:34:52.699932Z","shell.execute_reply":"2022-03-23T07:34:53.446336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"run_training()","metadata":{"execution":{"iopub.status.busy":"2022-03-23T07:34:57.987245Z","iopub.execute_input":"2022-03-23T07:34:57.987589Z","iopub.status.idle":"2022-03-23T07:42:58.593215Z","shell.execute_reply.started":"2022-03-23T07:34:57.987556Z","shell.execute_reply":"2022-03-23T07:42:58.592355Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"net.save(\"version 1\") ","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Проверяем модель на тестовых данных**","metadata":{}},{"cell_type":"code","source":"sample = pd.read_csv(\"/kaggle/input/alaska2-image-steganalysis/sample_submission.csv\")\nBATCH_SIZE = 8 * tpu_strategy.num_replicas_in_sync # batch size in tpu\nEPOCHS = 1","metadata":{"execution":{"iopub.status.busy":"2022-03-23T07:43:13.660008Z","iopub.execute_input":"2022-03-23T07:43:13.660339Z","iopub.status.idle":"2022-03-23T07:43:13.67122Z","shell.execute_reply.started":"2022-03-23T07:43:13.660307Z","shell.execute_reply":"2022-03-23T07:43:13.670244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n\ntest_dataset = []\n\nfor label, kind in enumerate(['Cover', 'JMiPOD', 'JUNIWARD', 'UERD']):\n    for path in glob('../input/alaska2-image-steganalysis/Cover/*.jpg'):\n        test_dataset.append({\n            'kind': kind,\n            'image_name': path.split('/')[-1],\n            'label': label\n        })","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = net.predict(test_dataset, verbose=1)","metadata":{"execution":{"iopub.status.busy":"2022-03-23T07:43:32.476159Z","iopub.execute_input":"2022-03-23T07:43:32.476489Z","iopub.status.idle":"2022-03-23T07:43:32.481847Z","shell.execute_reply.started":"2022-03-23T07:43:32.476451Z","shell.execute_reply":"2022-03-23T07:43:32.480964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"my_sample = sample.copy()\nmy_sample[\"Label\"] = pred\nmy_sample.to_csv(\"my_sample.csv\", index=False)\nmy_sample.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-23T07:43:18.865558Z","iopub.execute_input":"2022-03-23T07:43:18.865931Z","iopub.status.idle":"2022-03-23T07:43:18.883177Z","shell.execute_reply.started":"2022-03-23T07:43:18.865901Z","shell.execute_reply":"2022-03-23T07:43:18.882067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#my_sample.to_csv('1_sub.csv', index=False)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#!kaggle competitions submit -c alaska2-image-steganalysis -f 1_sub.csv -m \"EfficientNet\"\n","metadata":{"execution":{"iopub.status.busy":"2022-03-23T07:43:41.657787Z","iopub.execute_input":"2022-03-23T07:43:41.65813Z","iopub.status.idle":"2022-03-23T07:43:41.741103Z","shell.execute_reply.started":"2022-03-23T07:43:41.658098Z","shell.execute_reply":"2022-03-23T07:43:41.739648Z"},"trusted":true},"execution_count":null,"outputs":[]}]}