{"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 -r /kaggle/input/github-benetech-dd/requirements.txt --no-index --find-links=file:///kaggle/input/benetech-sub-pip2 -q","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","papermill":{"duration":30.069969,"end_time":"2023-06-19T12:21:47.214539","exception":false,"start_time":"2023-06-19T12:21:17.144570","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:33:45.848967Z","iopub.execute_input":"2023-06-21T14:33:45.849653Z","iopub.status.idle":"2023-06-21T14:34:16.088818Z","shell.execute_reply.started":"2023-06-21T14:33:45.849618Z","shell.execute_reply":"2023-06-21T14:34:16.087666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install transformers  --no-index --find-links=file:///kaggle/input/benetech-sub-pip -q ","metadata":{"papermill":{"duration":11.293928,"end_time":"2023-06-19T12:21:58.530258","exception":false,"start_time":"2023-06-19T12:21:47.236330","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:34:16.091784Z","iopub.execute_input":"2023-06-21T14:34:16.093276Z","iopub.status.idle":"2023-06-21T14:34:27.241237Z","shell.execute_reply.started":"2023-06-21T14:34:16.093237Z","shell.execute_reply":"2023-06-21T14:34:27.240055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!cp -r /kaggle/input/github-benetech-dd/* ./","metadata":{"papermill":{"duration":2.659907,"end_time":"2023-06-19T12:22:01.211150","exception":false,"start_time":"2023-06-19T12:21:58.551243","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:34:27.243165Z","iopub.execute_input":"2023-06-21T14:34:27.243813Z","iopub.status.idle":"2023-06-21T14:34:28.275871Z","shell.execute_reply.started":"2023-06-21T14:34:27.243775Z","shell.execute_reply":"2023-06-21T14:34:28.274627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport scipy as sp\nimport os\nimport json\nimport sys\nimport importlib\nimport multiprocessing as mp\nimport gc\nfrom tqdm.auto import tqdm\nimport glob\nimport torch\nfrom copy import copy\n#from torch.cuda.amp import GradScaler, autocast\nfrom torch.utils.data import DataLoader\nimport timm\nfrom PIL import Image\nimport transformers\nimport torch.nn.functional as F\nimport os\nos.environ[\"TOKENIZERS_PARALLELISM\"] = \"false\"\ngc.collect()","metadata":{"papermill":{"duration":5.983157,"end_time":"2023-06-19T12:22:07.215178","exception":false,"start_time":"2023-06-19T12:22:01.232021","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:37:15.122051Z","iopub.execute_input":"2023-06-21T14:37:15.123032Z","iopub.status.idle":"2023-06-21T14:37:20.820983Z","shell.execute_reply.started":"2023-06-21T14:37:15.122995Z","shell.execute_reply":"2023-06-21T14:37:20.819985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"torch.backends.cudnn.benchmark = True\n\nsys.path.append('./configs')\nsys.path.append('./data')\nsys.path.append('./models')\nsys.path.append('./postprocess')\nsys.path.append('./scripts')","metadata":{"papermill":{"duration":0.030289,"end_time":"2023-06-19T12:22:07.266861","exception":false,"start_time":"2023-06-19T12:22:07.236572","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:37:20.823016Z","iopub.execute_input":"2023-06-21T14:37:20.823715Z","iopub.status.idle":"2023-06-21T14:37:20.830381Z","shell.execute_reply.started":"2023-06-21T14:37:20.823682Z","shell.execute_reply":"2023-06-21T14:37:20.829431Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"COMP_FOLDER = '/kaggle/input/benetech-making-graphs-accessible/'\nDATA_FOLDER = COMP_FOLDER + 'test/'\nMETA_DF = COMP_FOLDER + 'test.csv'\n#train_df = pd.read_csv(COMP_FOLDER + 'train.csv')\n#test_df = pd.read_csv(COMP_FOLDER + 'test.csv')\nsample_submission = pd.read_csv(COMP_FOLDER + 'sample_submission.csv')\ntest_files = pd.Series(glob.glob(f'{COMP_FOLDER}/test/images/*.*g')).str.replace('.jpg', '').str.split('/').str[-1]\ntrain_files = pd.Series(glob.glob(f'{COMP_FOLDER}/train/images/*.*g')).str.replace('.jpg', '').str.split('/').str[-1]\ntest_df = pd.DataFrame({'id':test_files,'chart_type':'scatter','source_type':'extracted','flattened_label':'Jan;Feb;Mar||line||34.1;31.7;31.3||line'})\ntest_df['fold'] = -1\ntrain_df = pd.DataFrame({'id':train_files,'chart_type':'scatter','source_type':'extracted','flattened_label':'Jan;Feb;Mar||line||34.1;31.7;31.3||line'})\ntrain_df['fold'] = -1\nPUBLIC_RUN = len(test_df) == 5\nN_CORES = mp.cpu_count()\nMIXED_PRECISION = False\nPIN_MEMORY = False\n\nRAM_CHECK = False\nOOF_CHECK = False\nFOLD = 0\nMAX_FOLDS = 99\nDL_PREFETCH_FACTOR = 2\n\nassert (RAM_CHECK + OOF_CHECK) <= 1\n\nDEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'\n\nif PUBLIC_RUN is False:\n    RAM_CHECK = False\n    OOF_CHECK = False\n    \nif RAM_CHECK is True:\n    pass\n    \nif OOF_CHECK is True:\n    pass\n\nprint(train_df.shape)\nprint(test_df.shape)\ngc.collect()","metadata":{"papermill":{"duration":1.824224,"end_time":"2023-06-19T12:22:09.111927","exception":false,"start_time":"2023-06-19T12:22:07.287703","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:37:20.831877Z","iopub.execute_input":"2023-06-21T14:37:20.832183Z","iopub.status.idle":"2023-06-21T14:37:22.172367Z","shell.execute_reply.started":"2023-06-21T14:37:20.832152Z","shell.execute_reply":"2023-06-21T14:37:22.171474Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df","metadata":{"papermill":{"duration":0.040906,"end_time":"2023-06-19T12:22:09.175776","exception":false,"start_time":"2023-06-19T12:22:09.134870","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:37:22.175109Z","iopub.execute_input":"2023-06-21T14:37:22.175739Z","iopub.status.idle":"2023-06-21T14:37:22.191697Z","shell.execute_reply.started":"2023-06-21T14:37:22.175704Z","shell.execute_reply":"2023-06-21T14:37:22.190765Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_cfg(CFG):\n    cfg = importlib.import_module('default_config')\n    importlib.reload(cfg)\n    cfg = importlib.import_module(CFG)\n    importlib.reload(cfg)\n    cfg = copy(cfg.cfg)\n    cfg.post_process_pipeline = None #importlib.import_module(cfg.post_process_pipeline).post_process_pipeline\n\n    cfg.data_dir = COMP_FOLDER\n    cfg.data_folder = DATA_FOLDER\n    cfg.test_data_folder = DATA_FOLDER\n    cfg.mixed_precision = MIXED_PRECISION\n    cfg.pretrained = False\n    cfg.pretrained_weights = False\n    cfg.batch_size = cfg.batch_size\n    cfg.offline_inference = True\n\n    print(CFG, cfg.model, cfg.dataset, cfg.backbone, cfg.pretrained_weights, cfg.post_process_pipeline)\n    \n    return cfg\n\ndef get_dl(test_df, cfg):\n    ds = importlib.import_module(cfg.dataset)\n    importlib.reload(ds)\n\n    CustomDataset = ds.CustomDataset\n    batch_to_device = ds.batch_to_device\n\n    test_ds = CustomDataset(test_df, cfg, cfg.val_aug, mode=\"test\")\n    test_dl = DataLoader(test_ds, shuffle=False, batch_size=cfg.batch_size, collate_fn=ds.val_collate_fn, num_workers=N_CORES, pin_memory=PIN_MEMORY, prefetch_factor = DL_PREFETCH_FACTOR)\n\n    return test_dl, batch_to_device\n\ndef get_state_dict(sd_fp):\n    sd = torch.load(sd_fp, map_location=\"cpu\")\n    if \"model\" in sd.keys():\n        sd = sd[\"model\"]\n    sd = {k.replace(\"module.\", \"\"):v for k,v in sd.items()}\n    return sd\n\ndef get_nets(cfg,state_dicts):\n    model = importlib.import_module(cfg.model)\n    importlib.reload(model)\n    Net = model.Net\n\n    nets = []\n\n    for i,state_dict in enumerate(state_dicts):\n        net = Net(cfg).eval().to(DEVICE)\n        print(\"loading dict\")\n        sd = get_state_dict(state_dict)\n        net.load_state_dict(sd, strict=cfg.pretrained_weights_strict)\n        #nets += [net.half()]\n        nets += [net]\n        del sd\n        gc.collect()\n    return nets","metadata":{"papermill":{"duration":0.037208,"end_time":"2023-06-19T12:22:09.235869","exception":false,"start_time":"2023-06-19T12:22:09.198661","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:37:22.193073Z","iopub.execute_input":"2023-06-21T14:37:22.193693Z","iopub.status.idle":"2023-06-21T14:37:22.207830Z","shell.execute_reply.started":"2023-06-21T14:37:22.193659Z","shell.execute_reply":"2023-06-21T14:37:22.206823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"CFG = 'cfg_ch_ct_1c'\nstate_dicts = sorted(glob.glob('/kaggle/input/benetech-cfg-ch-ct-1c-ff/*/*.pth'))\nprint(state_dicts)\n\ncfg = get_cfg(CFG)\n# cfg.batch_size = 2\ntest_dl, batch_to_device = get_dl(test_df, cfg)\nnets = get_nets(cfg,state_dicts)","metadata":{"papermill":{"duration":14.85605,"end_time":"2023-06-19T12:22:24.173150","exception":false,"start_time":"2023-06-19T12:22:09.317100","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:37:22.209410Z","iopub.execute_input":"2023-06-21T14:37:22.210725Z","iopub.status.idle":"2023-06-21T14:37:28.931878Z","shell.execute_reply.started":"2023-06-21T14:37:22.210677Z","shell.execute_reply":"2023-06-21T14:37:28.930744Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with torch.inference_mode():\n\n    preds = []\n    for batch in tqdm(test_dl):\n        batch = batch_to_device(batch, 'cuda')\n        batch_preds = []\n        for i, net in enumerate(nets):\n            logits = net(batch)['logits'].float().detach().cpu().numpy()\n            batch_preds += [logits]\n        preds += [np.stack(batch_preds, axis=1)]\n    preds = np.concatenate(preds)\n    preds.shape","metadata":{"papermill":{"duration":15.601713,"end_time":"2023-06-19T12:22:39.899814","exception":false,"start_time":"2023-06-19T12:22:24.298101","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:37:28.933244Z","iopub.execute_input":"2023-06-21T14:37:28.933604Z","iopub.status.idle":"2023-06-21T14:37:34.372838Z","shell.execute_reply.started":"2023-06-21T14:37:28.933556Z","shell.execute_reply":"2023-06-21T14:37:34.371576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds = preds.mean(1).argmax(1)\n","metadata":{"papermill":{"duration":0.031568,"end_time":"2023-06-19T12:22:39.953222","exception":false,"start_time":"2023-06-19T12:22:39.921654","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:37:34.375450Z","iopub.execute_input":"2023-06-21T14:37:34.375866Z","iopub.status.idle":"2023-06-21T14:37:34.381667Z","shell.execute_reply.started":"2023-06-21T14:37:34.375824Z","shell.execute_reply":"2023-06-21T14:37:34.380521Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"chart_type_pred = np.array(cfg.chart_map)[preds]","metadata":{"papermill":{"duration":0.03011,"end_time":"2023-06-19T12:22:40.005896","exception":false,"start_time":"2023-06-19T12:22:39.975786","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:37:34.383190Z","iopub.execute_input":"2023-06-21T14:37:34.383788Z","iopub.status.idle":"2023-06-21T14:37:34.393554Z","shell.execute_reply.started":"2023-06-21T14:37:34.383755Z","shell.execute_reply":"2023-06-21T14:37:34.392631Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['chart_type_pred'] = chart_type_pred","metadata":{"papermill":{"duration":0.030649,"end_time":"2023-06-19T12:22:40.057810","exception":false,"start_time":"2023-06-19T12:22:40.027161","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:37:34.399347Z","iopub.execute_input":"2023-06-21T14:37:34.399637Z","iopub.status.idle":"2023-06-21T14:37:34.407539Z","shell.execute_reply.started":"2023-06-21T14:37:34.399613Z","shell.execute_reply":"2023-06-21T14:37:34.406425Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(test_df['chart_type'] == test_df['chart_type_pred']).mean()","metadata":{"papermill":{"duration":0.033892,"end_time":"2023-06-19T12:22:40.113337","exception":false,"start_time":"2023-06-19T12:22:40.079445","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:37:34.409060Z","iopub.execute_input":"2023-06-21T14:37:34.410184Z","iopub.status.idle":"2023-06-21T14:37:34.421130Z","shell.execute_reply.started":"2023-06-21T14:37:34.410022Z","shell.execute_reply":"2023-06-21T14:37:34.420151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del nets, preds, test_dl\ngc.collect()\ntorch.cuda.empty_cache()","metadata":{"papermill":{"duration":10.488884,"end_time":"2023-06-19T12:22:50.623192","exception":false,"start_time":"2023-06-19T12:22:40.134308","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:37:34.422936Z","iopub.execute_input":"2023-06-21T14:37:34.423642Z","iopub.status.idle":"2023-06-21T14:37:39.798445Z","shell.execute_reply.started":"2023-06-21T14:37:34.423608Z","shell.execute_reply":"2023-06-21T14:37:39.797396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_chart_types = test_df['chart_type_pred'].unique()","metadata":{"papermill":{"duration":0.038893,"end_time":"2023-06-19T12:22:50.721189","exception":false,"start_time":"2023-06-19T12:22:50.682296","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:37:39.800267Z","iopub.execute_input":"2023-06-21T14:37:39.800942Z","iopub.status.idle":"2023-06-21T14:37:39.806239Z","shell.execute_reply.started":"2023-06-21T14:37:39.800908Z","shell.execute_reply":"2023-06-21T14:37:39.805324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_chart_types","metadata":{"papermill":{"duration":0.031677,"end_time":"2023-06-19T12:22:50.778341","exception":false,"start_time":"2023-06-19T12:22:50.746664","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:37:39.810185Z","iopub.execute_input":"2023-06-21T14:37:39.810995Z","iopub.status.idle":"2023-06-21T14:37:39.829660Z","shell.execute_reply.started":"2023-06-21T14:37:39.810961Z","shell.execute_reply":"2023-06-21T14:37:39.828694Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df = []","metadata":{"papermill":{"duration":0.028954,"end_time":"2023-06-19T12:22:50.829681","exception":false,"start_time":"2023-06-19T12:22:50.800727","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:37:39.831123Z","iopub.execute_input":"2023-06-21T14:37:39.831930Z","iopub.status.idle":"2023-06-21T14:37:39.838167Z","shell.execute_reply.started":"2023-06-21T14:37:39.831898Z","shell.execute_reply":"2023-06-21T14:37:39.837120Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from typing import Any, Dict\n\nimport torch\nimport torch.nn.functional as F\nfrom torch import nn\nfrom torch.nn.parameter import Parameter\nimport timm\nfrom torch.distributions import Beta\nfrom torch.nn.utils.rnn import pad_packed_sequence, pad_sequence\nfrom transformers import DetrConfig, DetrForObjectDetection#, DetrHungarianMatcher\nfrom transformers.models.detr.modeling_detr import DetrHungarianMatcher, generalized_box_iou, center_to_corners_format\nimport torch\nimport torch\nfrom torch import Tensor\nfrom transformers import DetrImageProcessor\nfrom transformers.models.detr.image_processing_detr import center_to_corners_format\nimport imagesize\nfrom transformers import Pix2StructForConditionalGeneration, Pix2StructProcessor, AutoTokenizer, Pix2StructConfig\nfrom transformers import Pix2StructVisionModel, T5ForConditionalGeneration\nfrom torch.nn.utils.rnn import pad_sequence\n\ndef gem(x, p=3, eps=1e-6):\n    return F.avg_pool2d(x.clamp(min=eps).pow(p), (x.size(-2), x.size(-1))).pow(1.0 / p)\n\n\nclass GeM(nn.Module):\n    def __init__(self, p=3, eps=1e-6, p_trainable=False):\n        super(GeM, self).__init__()\n        if p_trainable:\n            self.p = Parameter(torch.ones(1) * p)\n        else:\n            self.p = p\n        self.eps = eps\n\n    def forward(self, x):\n        ret = gem(x, p=self.p, eps=self.eps)\n        return ret\n\n    def __repr__(self):\n        return (self.__class__.__name__  + f\"(p={self.p.data.tolist()[0]:.4f},eps={self.eps})\")\n\n\n'''\nself = Net(cfg)\n'''\n\nclass Net(nn.Module):\n\n    def __init__(self, cfg: Any):\n        super(Net, self).__init__()\n\n        self.cfg = cfg\n        \n        config = Pix2StructConfig()\n        config.vision_config.use_bfloat16 = cfg.use_bfloat16\n        config.text_config.use_bfloat16 = cfg.use_bfloat16\n        self.backbone = Pix2StructForConditionalGeneration.from_pretrained(cfg.backbone, config = config)\n        \n        self.processor = Pix2StructProcessor.from_pretrained(cfg.backbone, is_vqa = False)\n        sep_pos = self.processor.tokenizer.encode('\\;', add_special_tokens = False)\n        # wt1 = self.backbone.decoder.embed_tokens.weight[sep_pos]\n        wt0 = self.backbone.decoder.embed_tokens.weight#[:-2]\n        emb_wt = torch.cat((wt0, wt0[sep_pos]))\n        self.backbone.resize_token_embeddings(2+self.backbone.config.text_config.vocab_size)\n        self.loss_weights = torch.ones(self.backbone.config.text_config.vocab_size)\n        self.loss_weights[-2:] *= self.cfg.break_wt\n        self.backbone.decoder.embed_tokens.load_state_dict({'weight': emb_wt})\n        \n        # self.processor = Pix2StructProcessor.from_pretrained(cfg.backbone)\n        self.in_features = self.backbone.config.vision_config.hidden_size\n        self.chart_classifier = torch.nn.Linear(in_features=self.in_features, out_features=len(self.cfg.chart_map ), bias=True)\n        # self.dtype_classifier = torch.nn.Linear(in_features=self.in_features, out_features=len(self.cfg.dtype_map ), bias=True)\n        self.criterion = nn.CrossEntropyLoss(ignore_index=-100)\n        calc_grad = False\n        for nm, param in self.backbone.named_parameters():\n            if cfg.freeze_from in nm:\n                calc_grad = True\n            param.requires_grad = calc_grad\n        # for nm, param in self.backbone.named_parameters():\n        #     print(param.requires_grad, nm)\n        self.loss_weights = torch.nn.Parameter(self.loss_weights, requires_grad=False)\n        # self.cfg.break_wt = 2.\n        \n        self.criterion_table = nn.CrossEntropyLoss(weight = self.loss_weights , ignore_index=-100, reduction=\"mean\")\n\n    def forward(self, batch):\n        \n        labels = batch['series_label_1'].permute(1,0)\n        encoding = {k:v[:,0] for k,v in batch.items() if k in ['flattened_patches', 'attention_mask']}\n        predictions = self.backbone.generate(**encoding, \n                                                max_new_tokens=self.cfg.max_label_length, \n                                                early_stopping=True,\n                                                pad_token_id=self.processor.tokenizer.pad_token_id,\n                                                eos_token_id=self.processor.tokenizer.eos_token_id,\n                                                use_cache=True,\n                                                num_beams=self.cfg.num_beams,\n                                                temperature=self.cfg.temperature,\n                                                top_k=self.cfg.top_k,\n                                                return_dict_in_generate=True,\n                                                output_hidden_states = True)\n        logits_chart = self.chart_classifier(predictions.encoder_hidden_states[-1][:,0])\n        logits_table = predictions.sequences #[:,1:]\n        # print(logits_table)\n        loss = self.criterion(logits_chart, batch['chart_label'])\n\n        outputs = {}\n        outputs[\"loss\"] = loss\n        if not self.training:\n            # Calculate the required padding\n            padding = (0, self.cfg.max_label_length - logits_table.size(1))\n            # Pad the array along the 3rd dimension\n            logits_table  = F.pad(logits_table, padding, mode=\"constant\", value=0)\n            outputs[\"logits_table\"] = logits_table\n            outputs[\"logits_chart\"] = logits_chart\n \n        return outputs\n","metadata":{"papermill":{"duration":0.073865,"end_time":"2023-06-19T12:22:51.162975","exception":false,"start_time":"2023-06-19T12:22:51.089110","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:37:39.839793Z","iopub.execute_input":"2023-06-21T14:37:39.840418Z","iopub.status.idle":"2023-06-21T14:37:47.453831Z","shell.execute_reply.started":"2023-06-21T14:37:39.840388Z","shell.execute_reply":"2023-06-21T14:37:47.452793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_state_dict(sd_fp):\n    sd = torch.load(sd_fp, map_location=\"cpu\")\n    if \"model\" in sd.keys():\n        sd = sd[\"model\"]\n    sd = {k.replace(\"module.\", \"\"):v for k,v in sd.items()}\n    return sd\n\ndef get_nets(cfg,state_dicts):\n    model = importlib.import_module(cfg.model)\n    importlib.reload(model)\n    Net = model.Net\n\n    nets = []\n\n    for i,state_dict in enumerate(state_dicts):\n        net = Net(cfg).eval().to(DEVICE)\n        print(\"loading dict\")\n        sd = get_state_dict(state_dict)\n        net.load_state_dict(sd, strict=cfg.pretrained_weights_strict)\n        #nets += [net.half()]\n        nets += [net]\n        del sd\n        gc.collect()\n    return nets","metadata":{"papermill":{"duration":0.03174,"end_time":"2023-06-19T12:22:51.216401","exception":false,"start_time":"2023-06-19T12:22:51.184661","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:37:47.455240Z","iopub.execute_input":"2023-06-21T14:37:47.455568Z","iopub.status.idle":"2023-06-21T14:37:47.463021Z","shell.execute_reply.started":"2023-06-21T14:37:47.455537Z","shell.execute_reply":"2023-06-21T14:37:47.461719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nimport torch.nn.functional as F\nfrom torch import nn\nfrom torch.nn.parameter import Parameter\nimport torch\nfrom transformers import LogitsProcessorList\nfrom transformers.generation.utils import GreedySearchOutput, GreedySearchEncoderDecoderOutput, GreedySearchDecoderOnlyOutput\nfrom typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Union\nimport warnings\nfrom transformers import Pix2StructForConditionalGeneration, Pix2StructProcessor, AutoTokenizer\nfrom transformers import StoppingCriteriaList,  MaxLengthCriteria\n\n\n        \n'''\nReference code:\nhttps://github.com/huggingface/transformers/blob/118e9810687dd713b6be07af79e80eeb1d916908/src/transformers/generation/utils.py#L2164\n'''\n       \n\n\nclass Pix2StructGreedySearch(Pix2StructForConditionalGeneration):\n    def __init__(self, \n                 models, \n                 max_length = 512):\n        super().__init__(models[0].config)\n        \n        del self.encoder \n        del self.decoder \n        self.models = models\n        self.is_vqa  = False\n        self.logits_processor = LogitsProcessorList([])\n        self.stopping_criteria = StoppingCriteriaList([MaxLengthCriteria(max_length=max_length)])\n        \n        '''\n        Reference code:\n        https://github.com/huggingface/transformers/blob/118e9810687dd713b6be07af79e80eeb1d916908/src/transformers/generation/utils.py#L2164\n        '''\n        \n    def forward(\n        self,\n        flattened_patches: Optional[torch.Tensor] = None,\n        attention_mask: Optional[torch.Tensor] = None,\n        use_cache = True,\n        return_dict_in_generate = False,\n        output_hidden_states = False,\n        \n        ):\n\n        if self.models[0].device != flattened_patches.device:\n            self.models = [m.to(flattened_patches.device) for m in self.models]\n        #print(self.models[0].device)\n        #print(flattened_patches.device)\n\n        encoder_outputs_list  = [m.encoder(flattened_patches = flattened_patches, \n                                           attention_mask = attention_mask) for m in self.models]\n        input_ids = torch.tensor([[self.models[0].config.pad_token_id]] * len(flattened_patches), \n                                 device = flattened_patches.device) # '<pad>' token to begin\n        # attention_mask = attention_mask\n        # print(flattened_patches.shape)\n        # print(input_ids.shape)\n        \n        output = self.greedy_search(encoder_outputs_list, \n                                               attention_mask, \n                                               input_ids, \n                                               output_attentions = False,\n                                               output_hidden_states = output_hidden_states,\n                                               output_scores = False,\n                                               return_dict_in_generate =return_dict_in_generate\n                                    \n                                                \n                                   \n                                   )\n                \n        return output\n\n    def greedy_search(\n        self,\n        encoder_outputs_list,\n        attention_mask,\n        input_ids: torch.LongTensor,\n        stopping_criteria: Optional[StoppingCriteriaList] = None,\n        # max_length: Optional[int] = None,\n        pad_token_id: Optional[int] = None,\n        eos_token_id: Optional[Union[int, List[int]]] = None,\n        output_attentions: Optional[bool] = None,\n        output_hidden_states: Optional[bool] = None,\n        output_scores: Optional[bool] = None,\n        return_dict_in_generate: Optional[bool] = None,\n        synced_gpus: bool = False,\n        streamer: Optional[\"BaseStreamer\"] = None,\n        **model_kwargs,\n    ) -> Union[GreedySearchOutput, torch.LongTensor]:\n        # init values\n        logits_processor = LogitsProcessorList()\n        stopping_criteria = self.stopping_criteria\n        pad_token_id = self.generation_config.pad_token_id\n        eos_token_id = self.generation_config.eos_token_id\n        if isinstance(eos_token_id, int):\n            eos_token_id = [eos_token_id]\n        eos_token_id_tensor = torch.tensor(eos_token_id).to(input_ids.device) if eos_token_id is not None else None\n        output_scores = output_scores if output_scores is not None else self.generation_config.output_scores\n        output_attentions = (\n            output_attentions if output_attentions is not None else self.generation_config.output_attentions\n        )\n        output_hidden_states = (\n            output_hidden_states if output_hidden_states is not None else self.generation_config.output_hidden_states\n        )\n        return_dict_in_generate = (\n            return_dict_in_generate\n            if return_dict_in_generate is not None\n            else self.generation_config.return_dict_in_generate\n        )\n    \n        # init attention / hidden states / scores tuples\n        scores = () if (return_dict_in_generate and output_scores) else None\n    \n        # keep track of which sequences are already finished\n        unfinished_sequences = torch.ones(input_ids.shape[0], dtype=torch.long, device=input_ids.device)\n        \n        this_peer_finished = False  # used by synced_gpus only\n        \n        model_kwargs_list = [{'use_cache': True, \n                              'attention_mask': attention_mask, \n                              'encoder_outputs':encoder_outputs} for encoder_outputs in encoder_outputs_list]\n        \n        decoder_hidden_states_list = [() for _ in range(len(self.models))]\n        \n        while True:\n            # prepare model inputs\n            # model_inputs = self.prepare_inputs_for_generation(input_ids, **model_kwargs)\n            model_inputs_list = [self.prepare_inputs_for_generation(input_ids, **model_kwargs) for model_kwargs in model_kwargs_list]\n            \n            outputs_list = []\n            for m, model_inputs in zip(self.models, model_inputs_list):\n                outputs_list.append(m(\n                    **model_inputs,\n                    return_dict=True,\n                    output_attentions=output_attentions,\n                    output_hidden_states=output_hidden_states,\n                ))\n            \n            # next_token_logits = outputs.logits[:, -1, :]\n            next_token_logits = torch.stack([o.logits[:, -1, :] for o in outputs_list]).mean(0)\n    \n            # pre-process distribution\n            next_tokens_scores = logits_processor(input_ids, next_token_logits)\n            \n            # Store scores, attentions and hidden_states when required\n            if return_dict_in_generate:\n                if output_scores:\n                    scores += (next_tokens_scores,)\n                \n                if output_hidden_states:\n                    for ii in range(len(model_kwargs_list)):\n                        decoder_hidden_states_list[ii] += (\n                            (outputs_list[ii].decoder_hidden_states,)\n                            if self.config.is_encoder_decoder\n                            else (outputs_list[ii].hidden_states,)\n                        )\n        \n            # argmax\n            next_tokens = torch.argmax(next_tokens_scores, dim=-1)\n            \n            # finished sentences should have their next token be a padding token\n            if eos_token_id is not None:\n                if pad_token_id is None:\n                    raise ValueError(\"If `eos_token_id` is defined, make sure that `pad_token_id` is defined.\")\n                next_tokens = next_tokens * unfinished_sequences + pad_token_id * (1 - unfinished_sequences)\n            \n            # update generated ids, model inputs, and length for next step\n            input_ids = torch.cat([input_ids, next_tokens[:, None]], dim=-1)\n\n            for ii in range(len(model_kwargs_list)):\n                model_kwargs_list[ii] = self.models[ii]._update_model_kwargs_for_generation(\n                                            outputs_list[ii], model_kwargs_list[ii], is_encoder_decoder=self.config.is_encoder_decoder\n                                        )\n            \n            # if eos_token was found in one sentence, set sentence to finished\n            if eos_token_id_tensor is not None:\n                unfinished_sequences = unfinished_sequences.mul(\n                    next_tokens.tile(eos_token_id_tensor.shape[0], 1).ne(eos_token_id_tensor.unsqueeze(1)).prod(dim=0)\n                )\n    \n                # stop when each sentence is finished\n                if unfinished_sequences.max() == 0:\n                    this_peer_finished = True\n    \n            # stop if we exceed the maximum length\n            if stopping_criteria(input_ids, scores):\n                this_peer_finished = True\n    \n            if this_peer_finished:\n                break\n            \n        return GreedySearchEncoderDecoderOutput(\n            sequences=input_ids,\n            scores=scores,\n            #attentions=decoder_attentions,\n            decoder_hidden_states=decoder_hidden_states_list,  # not sure if decoder hidden states if stored correctly, reference original code\n            encoder_hidden_states=encoder_outputs_list, \n        )\n\n\n\n\nclass EnsembleNet(nn.Module):\n\n    def __init__(self, models, cfg):\n        super(EnsembleNet, self).__init__()\n\n        self.cfg = cfg\n        \n#         for t, wtsnm in enumerate(cfg.pretrained_weights_blend):\n#             print(f'Loading {wtsnm}')\n#             wts = torch.load(wtsnm, map_location=torch.device('cpu'))\n#             if 'model' in wts:\n#                 wts = wts['model']\n#             models[t].load_state_dict(wts, strict = False)\n            \n        backbones = [m.backbone for m in models]\n        self.chart_classifiers = torch.nn.ModuleList([m.chart_classifier for m in models])\n        self.criterion = models[0].criterion\n        self.backbones = Pix2StructGreedySearch(backbones, max_length=cfg.max_label_length)\n        \n    def forward(self, batch):\n        \n        encoding = {k:v[:,0] for k,v in batch.items() if k in ['flattened_patches', 'attention_mask']}\n        \n        predictions = self.backbones(**encoding)\n        \n#         logits_table = predictions.sequences #[:,1:]\n        # tokenizer.batch_decode(logits_table)\n        \n        logits_chart = torch.stack([m(enc.last_hidden_state[:, 0]) for m, enc in zip(self.chart_classifiers, predictions.encoder_hidden_states)]).mean(0)\n        \n        return predictions, logits_chart\n","metadata":{"papermill":{"duration":0.058975,"end_time":"2023-06-19T12:22:51.296438","exception":false,"start_time":"2023-06-19T12:22:51.237463","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:37:47.464478Z","iopub.execute_input":"2023-06-21T14:37:47.465041Z","iopub.status.idle":"2023-06-21T14:37:47.501913Z","shell.execute_reply.started":"2023-06-21T14:37:47.465010Z","shell.execute_reply":"2023-06-21T14:37:47.501021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Scatter ","metadata":{"papermill":{"duration":0.021606,"end_time":"2023-06-19T12:22:51.339756","exception":false,"start_time":"2023-06-19T12:22:51.318150","status":"completed"},"tags":[]}},{"cell_type":"code","source":"if 'scatter' in predicted_chart_types:\n\n    test_df_scatter = test_df[test_df['chart_type_pred'] == 'scatter'].copy()\n    name = 'cfg_ch_7_2048'\n\n    cfg = get_cfg(name)\n    cfg.backbone = '/kaggle/input/benetech-deplot/google/deplot/'\n    cfg.data_folder = DATA_FOLDER\n    cfg.batch_size = 4\n    cfg.model = \"mdl_dh_08I_val\"\n    cfg.post_process_pipeline =  \"pp_dh_05B\"\n    cfg.pretrained_weights_strict = False\n    cfg.num_beams=1\n    cfg.temperature=1\n    cfg.top_k=1\n    cfg.max_label_length = 512\n#     cfg.post_process_pipeline = 'pp_dh_01J'\n    test_dl, batch_to_device = get_dl(test_df_scatter, cfg)\n    test_dl.dataset.processor.image_processor.is_vqa = False\n\n    state_dict_fps = sorted(glob.glob('/kaggle/input/benetech-cfg-ch-18-ff/*/check*'))[:2]\n    state_dict_fps += sorted(glob.glob('/kaggle/input/benetech-cfg-ch-18b-ff/*/check*'))[:1]\n    state_dict_fps += sorted(glob.glob('/kaggle/input/benetech-cfg-ch-18c-ff/*/check*'))[:1]\n    \n    print('\\n'.join(state_dict_fps))\n    ens_net = EnsembleNet(get_nets(cfg,state_dict_fps), cfg)\n\n    pp = importlib.import_module(cfg.post_process_pipeline)\n    \n    print('running inference')\n    # https://huggingface.co/docs/transformers/main_classes/text_generation\n    logits_charts = []\n    logits_tables = []\n    with torch.inference_mode():\n        for tt, batch in tqdm(enumerate(test_dl), total = len(test_dl)):\n            batch = batch_to_device(batch,DEVICE)\n            #encoding = {k:v[:,0].half() for k,v in batch.items() if k in ['flattened_patches', 'attention_mask']}\n#             encoding = {k:v[:,0] for k,v in batch.items() if k in ['flattened_patches', 'attention_mask']}\n#             predictions = nets[0].backbone.generate(**encoding, \n#                                                     max_new_tokens=cfg.max_label_length, \n#                                                     early_stopping=True,\n#                                                     pad_token_id=test_dl.dataset.processor.tokenizer.pad_token_id,\n#                                                     eos_token_id=test_dl.dataset.processor.tokenizer.eos_token_id,\n#                                                     use_cache=True,\n#                                                     num_beams=cfg.num_beams,\n#                                                     temperature=cfg.temperature,\n#                                                     top_k=cfg.top_k,\n#                                                     return_dict_in_generate=True,\n#                                                     output_hidden_states = True)\n            predictions, logits_chart = ens_net(batch)\n            logits_table = predictions.sequences\n#             logits_chart = nets[0].chart_classifier(predictions.encoder_hidden_states[-1][:,0])\n#             logits_table = predictions.sequences\n            padding = (0, cfg.max_label_length - predictions.sequences.size(1))\n            logits_table  = F.pad(logits_table, padding, mode=\"constant\", value=0)\n            logits_charts.append(logits_chart)\n            logits_tables.append(logits_table)\n    val_data = {}\n    val_data['logits_chart'] = torch.cat(logits_charts).cpu()\n    val_data['logits_table'] = torch.cat(logits_tables).cpu()\n    \n    sub_df_scatter = pp.post_process_pipeline(cfg, val_data, test_df_scatter)\n#     sub_df += [sub_df_scatter]\n    \n    del ens_net, val_data, test_dl, logits_chart, logits_table\n    gc.collect()\n    torch.cuda.empty_cache()","metadata":{"papermill":{"duration":805.870185,"end_time":"2023-06-19T12:36:17.231327","exception":false,"start_time":"2023-06-19T12:22:51.361142","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:37:47.503445Z","iopub.execute_input":"2023-06-21T14:37:47.503826Z","iopub.status.idle":"2023-06-21T14:40:01.679558Z","shell.execute_reply.started":"2023-06-21T14:37:47.503795Z","shell.execute_reply":"2023-06-21T14:40:01.678467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import albumentations as A","metadata":{"papermill":{"duration":0.031736,"end_time":"2023-06-19T12:36:17.289043","exception":false,"start_time":"2023-06-19T12:36:17.257307","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:40:01.681591Z","iopub.execute_input":"2023-06-21T14:40:01.682233Z","iopub.status.idle":"2023-06-21T14:40:01.687426Z","shell.execute_reply.started":"2023-06-21T14:40:01.682194Z","shell.execute_reply":"2023-06-21T14:40:01.686159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"CFG = 'cfg_ch_sunet_1d2_b7_ext_v2_aug0f2_ddp2'\nstate_dicts = sorted(glob.glob('/kaggle/input/benetech-cfg-ch-sunet-13a-ff/*/*.pth'))\nprint(state_dicts)\n\ncfg = get_cfg(CFG)\ncfg.test_data_folder = cfg.test_data_folder + 'images/'\ncfg.val_aug = A.Compose([\n    A.Resize(768,768)\n#     A.PadIfNeeded (min_height=256, min_width=940),\n#     A.LongestMaxSize(cfg.image_width_orig,p=1),\n#     A.PadIfNeeded(cfg.image_width_orig, cfg.image_height_orig, border_mode=cv2.BORDER_CONSTANT,p=1),\n#     A.CenterCrop(always_apply=False, p=1.0, height=cfg.image_height, width=cfg.image_width), \n#     A.Resize(cfg.img_size[0],cfg.img_size[1])\n])\ncfg.model = 'mdl_ch_sunet_2_inf'\ncfg.return_logits = True\n# cfg.batch_size = 2\ntest_dl, batch_to_device = get_dl(test_df_scatter, cfg)\nnets = get_nets(cfg,state_dicts)","metadata":{"papermill":{"duration":13.67507,"end_time":"2023-06-19T12:36:30.987505","exception":false,"start_time":"2023-06-19T12:36:17.312435","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:40:23.659925Z","iopub.execute_input":"2023-06-21T14:40:23.660872Z","iopub.status.idle":"2023-06-21T14:40:36.080247Z","shell.execute_reply.started":"2023-06-21T14:40:23.660822Z","shell.execute_reply":"2023-06-21T14:40:36.079256Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with torch.inference_mode():\n\n    n_preds = []\n    for batch in tqdm(test_dl):\n        batch = batch_to_device(batch, 'cuda')\n        batch_preds = []\n        for i, net in enumerate(nets):\n            x_pred = net(batch)['pred_mask'].float()\n            batch_preds += [x_pred]\n        batch_preds = torch.stack(batch_preds).mean(0)\n        x_pooled = F.max_pool2d(batch_preds, kernel_size=cfg.nms_kernel_size, stride=1, padding=cfg.nms_padding)\n        batch_preds[batch_preds != x_pooled] = 0\n        n_pred = (batch_preds[:,0] > cfg.n_threshold).sum((1,2)).cpu().numpy()\n        n_preds += [n_pred]\n    n_preds = np.concatenate(n_preds)\n\n    \ndel nets, test_dl\ngc.collect()\ntorch.cuda.empty_cache()","metadata":{"papermill":{"duration":63.228926,"end_time":"2023-06-19T12:37:34.240407","exception":false,"start_time":"2023-06-19T12:36:31.011481","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:40:36.082643Z","iopub.execute_input":"2023-06-21T14:40:36.082997Z","iopub.status.idle":"2023-06-21T14:40:47.732958Z","shell.execute_reply.started":"2023-06-21T14:40:36.082966Z","shell.execute_reply":"2023-06-21T14:40:47.731747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"papermill":{"duration":0.047032,"end_time":"2023-06-19T12:37:34.369932","exception":false,"start_time":"2023-06-19T12:37:34.322900","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_mean(x):\n    vals = []\n    for item in x.split(';'):\n        try:\n            vals += [float(item)]\n        except:\n            pass\n    if len(vals) > 0:\n        m = np.mean(vals)\n    else:\n        m = 0\n    return m","metadata":{"papermill":{"duration":0.044155,"end_time":"2023-06-19T12:37:34.451380","exception":false,"start_time":"2023-06-19T12:37:34.407225","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:40:53.136617Z","iopub.execute_input":"2023-06-21T14:40:53.136994Z","iopub.status.idle":"2023-06-21T14:40:53.143450Z","shell.execute_reply.started":"2023-06-21T14:40:53.136965Z","shell.execute_reply":"2023-06-21T14:40:53.142396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#load unet count preds\noof_df = test_df_scatter[['id']].copy()\noof_df['n_pred'] = n_preds\noof_df_x = oof_df.copy()\noof_df_x['id'] = oof_df_x['id'] + '_x'\noof_df_y = oof_df.copy()\noof_df_y['id'] = oof_df_y['id'] + '_y'\noof_df_xy = pd.concat([oof_df_x,oof_df_y])\noof_df_xy = oof_df_xy.set_index('id')","metadata":{"papermill":{"duration":0.036726,"end_time":"2023-06-19T12:37:34.511299","exception":false,"start_time":"2023-06-19T12:37:34.474573","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:40:53.562996Z","iopub.execute_input":"2023-06-21T14:40:53.563693Z","iopub.status.idle":"2023-06-21T14:40:53.577313Z","shell.execute_reply.started":"2023-06-21T14:40:53.563660Z","shell.execute_reply":"2023-06-21T14:40:53.576351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"oof_df_xy.shape, sub_df_scatter.shape","metadata":{"papermill":{"duration":0.03142,"end_time":"2023-06-19T12:37:34.565415","exception":false,"start_time":"2023-06-19T12:37:34.533995","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:40:54.812994Z","iopub.execute_input":"2023-06-21T14:40:54.813698Z","iopub.status.idle":"2023-06-21T14:40:54.820278Z","shell.execute_reply.started":"2023-06-21T14:40:54.813665Z","shell.execute_reply":"2023-06-21T14:40:54.819244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pp_out_scatter = sub_df_scatter.copy()\n\n#merge into one df\npp_out_scatter['n_current'] = pp_out_scatter['data_series'].apply(lambda x: len(x.split(';')))\npp_out_scatter = pp_out_scatter.merge(oof_df_xy[['n_pred']],how='left',left_index=True,right_index=True)\n\n## count pp1: cut at n_pred if n_current > n_pred\n\nmask = pp_out_scatter['n_current']>pp_out_scatter['n_pred'] #False for nans\nif mask.sum()> 0:\n    pp_out_scatter.loc[mask,'data_series'] = pp_out_scatter[mask].apply(lambda x: ';'.join((x['data_series'].split(';')[:int(x['n_pred'])])), axis=1)\n\n## count pp2: fill with mean if n_current < n_pred\nmask2 = pp_out_scatter['n_current']<pp_out_scatter['n_pred'] #False for nans\nif mask2.sum()> 0:\n    pp_out_scatter_to_fix = pp_out_scatter.loc[mask2].copy()\n    pp_out_scatter_to_fix['mean_data_series'] = pp_out_scatter_to_fix['data_series'].apply(lambda x: get_mean(x))\n    pp_out_scatter_to_fix['data_series'] = pp_out_scatter_to_fix.apply(lambda x: ';'.join(x['data_series'].split(';') + [str(x['mean_data_series'])] * (int(x['n_pred']) - x['n_current'])), axis=1)\n    pp_out_scatter.loc[mask2, 'data_series'] = pp_out_scatter_to_fix['data_series'].values\n\nsub_df_scatter['data_series'] = pp_out_scatter['data_series'].values","metadata":{"papermill":{"duration":0.045601,"end_time":"2023-06-19T12:37:34.633990","exception":false,"start_time":"2023-06-19T12:37:34.588389","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:40:55.583161Z","iopub.execute_input":"2023-06-21T14:40:55.583530Z","iopub.status.idle":"2023-06-21T14:40:55.601241Z","shell.execute_reply.started":"2023-06-21T14:40:55.583501Z","shell.execute_reply":"2023-06-21T14:40:55.600307Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df += [sub_df_scatter]","metadata":{"papermill":{"duration":0.030479,"end_time":"2023-06-19T12:37:34.687075","exception":false,"start_time":"2023-06-19T12:37:34.656596","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:40:57.017469Z","iopub.execute_input":"2023-06-21T14:40:57.018555Z","iopub.status.idle":"2023-06-21T14:40:57.023612Z","shell.execute_reply.started":"2023-06-21T14:40:57.018506Z","shell.execute_reply":"2023-06-21T14:40:57.022520Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Vertical Bar","metadata":{"papermill":{"duration":0.022554,"end_time":"2023-06-19T12:37:34.732093","exception":false,"start_time":"2023-06-19T12:37:34.709539","status":"completed"},"tags":[]}},{"cell_type":"code","source":"#do vbar\nif 'vertical_bar' in predicted_chart_types:\n    \n    print('running vertical_bar')\n    print('setting up dataloader and model')\n    test_df_vb = test_df[test_df['chart_type_pred'] == 'vertical_bar'].copy()\n    \n    name = 'cfg_ch_7_2048'\n\n    cfg = get_cfg(name)\n    cfg.backbone = '/kaggle/input/benetech-deplot/google/deplot/'\n    cfg.data_folder = DATA_FOLDER\n    cfg.batch_size = 4\n    cfg.model = \"mdl_dh_08I_val\"\n    cfg.post_process_pipeline =  \"pp_dh_05B_hist\"\n    cfg.pretrained_weights_strict = False\n    cfg.num_beams=1\n    cfg.temperature=1\n    cfg.top_k=1\n    cfg.max_label_length = 512\n#     cfg.post_process_pipeline = 'pp_dh_01J'\n    test_dl, batch_to_device = get_dl(test_df_vb, cfg)\n#     test_dl.dataset.processor.image_processor.is_vqa = False\n\n    state_dict_fps = sorted(glob.glob('/kaggle/input/benetech-cfg-ch-19-ff/*/check*'))[:2]\n    state_dict_fps += sorted(glob.glob('/kaggle/input/benetech-cfg-ch-19b-ff/*/check*'))[:2]\n    print('\\n'.join(state_dict_fps))\n\n    ens_net = EnsembleNet(get_nets(cfg,state_dict_fps), cfg)\n\n    pp = importlib.import_module(cfg.post_process_pipeline)\n    \n    print('running inference')\n    # https://huggingface.co/docs/transformers/main_classes/text_generation\n    logits_charts = []\n    logits_tables = []\n    with torch.inference_mode():\n        for tt, batch in tqdm(enumerate(test_dl), total = len(test_dl)):\n            batch = batch_to_device(batch,DEVICE)\n            #encoding = {k:v[:,0].half() for k,v in batch.items() if k in ['flattened_patches', 'attention_mask']}\n#             encoding = {k:v[:,0] for k,v in batch.items() if k in ['flattened_patches', 'attention_mask']}\n#             predictions = nets[0].backbone.generate(**encoding, \n#                                                     max_new_tokens=cfg.max_label_length, \n#                                                     early_stopping=True,\n#                                                     pad_token_id=test_dl.dataset.processor.tokenizer.pad_token_id,\n#                                                     eos_token_id=test_dl.dataset.processor.tokenizer.eos_token_id,\n#                                                     use_cache=True,\n#                                                     num_beams=cfg.num_beams,\n#                                                     temperature=cfg.temperature,\n#                                                     top_k=cfg.top_k,\n#                                                     return_dict_in_generate=True,\n#                                                     output_hidden_states = True)\n            predictions, logits_chart = ens_net(batch)\n            logits_table = predictions.sequences\n#             logits_chart = nets[0].chart_classifier(predictions.encoder_hidden_states[-1][:,0])\n#             logits_table = predictions.sequences\n            padding = (0, cfg.max_label_length - predictions.sequences.size(1))\n            logits_table  = F.pad(logits_table, padding, mode=\"constant\", value=0)\n            logits_charts.append(logits_chart)\n            logits_tables.append(logits_table)\n    val_data = {}\n    val_data['logits_chart'] = torch.cat(logits_charts).cpu()\n    val_data['logits_table'] = torch.cat(logits_tables).cpu()\n    \n    \n    sub_df_vb = pp.post_process_pipeline(cfg, val_data, test_df_vb)\n    sub_df += [sub_df_vb]\n    \n    \n    del ens_net, val_data, test_dl, logits_charts, logits_tables\n    gc.collect()\n    torch.cuda.empty_cache()","metadata":{"papermill":{"duration":752.625493,"end_time":"2023-06-19T12:50:07.380336","exception":false,"start_time":"2023-06-19T12:37:34.754843","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:41:46.929733Z","iopub.execute_input":"2023-06-21T14:41:46.930692Z","iopub.status.idle":"2023-06-21T14:43:40.055332Z","shell.execute_reply.started":"2023-06-21T14:41:46.930657Z","shell.execute_reply":"2023-06-21T14:43:40.054249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Horizontal Bar","metadata":{"execution":{"iopub.execute_input":"2023-06-09T20:13:07.263146Z","iopub.status.busy":"2023-06-09T20:13:07.262787Z","iopub.status.idle":"2023-06-09T20:13:07.269Z","shell.execute_reply":"2023-06-09T20:13:07.266427Z","shell.execute_reply.started":"2023-06-09T20:13:07.263118Z"},"papermill":{"duration":0.022851,"end_time":"2023-06-19T12:50:07.427106","exception":false,"start_time":"2023-06-19T12:50:07.404255","status":"completed"},"tags":[]}},{"cell_type":"code","source":"if 'horizontal_bar' in predicted_chart_types:\n    \n    print('running vertical_bar')\n    print('setting up dataloader and model')\n    test_df_hb = test_df[test_df['chart_type_pred'] == 'horizontal_bar'].copy()\n    \n    name = 'cfg_ch_7_2048'\n\n    cfg = get_cfg(name)\n    cfg.backbone = '/kaggle/input/benetech-deplot/google/deplot/'\n    cfg.data_folder = DATA_FOLDER\n    cfg.batch_size = 4\n    cfg.model = \"mdl_dh_08I_val\"\n    cfg.post_process_pipeline =  \"pp_dh_05B\"\n    cfg.pretrained_weights_strict = False\n    cfg.num_beams=1\n    cfg.temperature=1\n    cfg.top_k=1\n    cfg.max_label_length = 512\n#     cfg.post_process_pipeline = 'pp_dh_01J'\n    test_dl, batch_to_device = get_dl(test_df_hb, cfg)\n    test_dl.dataset.processor.image_processor.is_vqa = False\n\n    state_dict_fps = sorted(glob.glob('/kaggle/input/benetech-cfg-ch-18-ff/*/check*'))[:2]\n    state_dict_fps += sorted(glob.glob('/kaggle/input/benetech-cfg-ch-18b-ff/*/check*'))[:1]\n    state_dict_fps += sorted(glob.glob('/kaggle/input/benetech-cfg-ch-18c-ff/*/check*'))[:1]\n    \n    print('\\n'.join(state_dict_fps))\n    ens_net = EnsembleNet(get_nets(cfg,state_dict_fps), cfg)\n\n    pp = importlib.import_module(cfg.post_process_pipeline)\n    \n    print('running inference')\n    # https://huggingface.co/docs/transformers/main_classes/text_generation\n    logits_charts = []\n    logits_tables = []\n    with torch.inference_mode():\n        for tt, batch in tqdm(enumerate(test_dl), total = len(test_dl)):\n            batch = batch_to_device(batch,DEVICE)\n            #encoding = {k:v[:,0].half() for k,v in batch.items() if k in ['flattened_patches', 'attention_mask']}\n#             encoding = {k:v[:,0] for k,v in batch.items() if k in ['flattened_patches', 'attention_mask']}\n#             predictions = nets[0].backbone.generate(**encoding, \n#                                                     max_new_tokens=cfg.max_label_length, \n#                                                     early_stopping=True,\n#                                                     pad_token_id=test_dl.dataset.processor.tokenizer.pad_token_id,\n#                                                     eos_token_id=test_dl.dataset.processor.tokenizer.eos_token_id,\n#                                                     use_cache=True,\n#                                                     num_beams=cfg.num_beams,\n#                                                     temperature=cfg.temperature,\n#                                                     top_k=cfg.top_k,\n#                                                     return_dict_in_generate=True,\n#                                                     output_hidden_states = True)\n            predictions, logits_chart = ens_net(batch)\n            logits_table = predictions.sequences\n#             logits_chart = nets[0].chart_classifier(predictions.encoder_hidden_states[-1][:,0])\n#             logits_table = predictions.sequences\n            padding = (0, cfg.max_label_length - predictions.sequences.size(1))\n            logits_table  = F.pad(logits_table, padding, mode=\"constant\", value=0)\n            logits_charts.append(logits_chart)\n            logits_tables.append(logits_table)\n    val_data = {}\n    val_data['logits_chart'] = torch.cat(logits_charts).cpu()\n    val_data['logits_table'] = torch.cat(logits_tables).cpu()\n    \n    sub_df_hb = pp.post_process_pipeline(cfg, val_data, test_df_hb)\n    sub_df += [sub_df_hb]\n    \n    del ens_net, val_data, test_dl, logits_charts, logits_tables\n    gc.collect()\n    torch.cuda.empty_cache()","metadata":{"papermill":{"duration":136.710204,"end_time":"2023-06-19T12:52:24.160069","exception":false,"start_time":"2023-06-19T12:50:07.449865","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:43:40.058548Z","iopub.execute_input":"2023-06-21T14:43:40.058946Z","iopub.status.idle":"2023-06-21T14:43:40.073625Z","shell.execute_reply.started":"2023-06-21T14:43:40.058911Z","shell.execute_reply":"2023-06-21T14:43:40.072375Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Line","metadata":{"papermill":{"duration":0.028118,"end_time":"2023-06-19T12:52:24.212586","exception":false,"start_time":"2023-06-19T12:52:24.184468","status":"completed"},"tags":[]}},{"cell_type":"code","source":"if 'line' in predicted_chart_types:\n\n    test_df_line = test_df[test_df['chart_type_pred'] == 'line'].copy()\n\n    \n    name = 'cfg_ch_7_2048'\n\n    cfg = get_cfg(name)\n    cfg.backbone = '/kaggle/input/benetech-deplot/google/deplot/'\n    cfg.data_folder = DATA_FOLDER\n    cfg.batch_size = 4\n    cfg.model = \"mdl_dh_08I_val\"\n    cfg.post_process_pipeline =  \"pp_dh_05B\"\n    cfg.pretrained_weights_strict = False\n    cfg.num_beams=1\n    cfg.temperature=1\n    cfg.top_k=1\n    cfg.max_label_length = 512\n#     cfg.post_process_pipeline = 'pp_dh_01J'\n    test_dl, batch_to_device = get_dl(test_df_line, cfg)\n    test_dl.dataset.processor.image_processor.is_vqa = False\n\n    state_dict_fps = sorted(glob.glob('/kaggle/input/benetech-cfg-ch-18-ff/*/check*'))[:2]\n    state_dict_fps += sorted(glob.glob('/kaggle/input/benetech-cfg-ch-18b-ff/*/check*'))[:1]\n    state_dict_fps += sorted(glob.glob('/kaggle/input/benetech-cfg-ch-18c-ff/*/check*'))[:1]\n    \n    print('\\n'.join(state_dict_fps))\n    ens_net = EnsembleNet(get_nets(cfg,state_dict_fps), cfg)\n\n    pp = importlib.import_module(cfg.post_process_pipeline)\n    \n    print('running inference')\n    # https://huggingface.co/docs/transformers/main_classes/text_generation\n    logits_charts = []\n    logits_tables = []\n    with torch.inference_mode():\n        for tt, batch in tqdm(enumerate(test_dl), total = len(test_dl)):\n            batch = batch_to_device(batch,DEVICE)\n            #encoding = {k:v[:,0].half() for k,v in batch.items() if k in ['flattened_patches', 'attention_mask']}\n#             encoding = {k:v[:,0] for k,v in batch.items() if k in ['flattened_patches', 'attention_mask']}\n#             predictions = nets[0].backbone.generate(**encoding, \n#                                                     max_new_tokens=cfg.max_label_length, \n#                                                     early_stopping=True,\n#                                                     pad_token_id=test_dl.dataset.processor.tokenizer.pad_token_id,\n#                                                     eos_token_id=test_dl.dataset.processor.tokenizer.eos_token_id,\n#                                                     use_cache=True,\n#                                                     num_beams=cfg.num_beams,\n#                                                     temperature=cfg.temperature,\n#                                                     top_k=cfg.top_k,\n#                                                     return_dict_in_generate=True,\n#                                                     output_hidden_states = True)\n            predictions, logits_chart = ens_net(batch)\n            logits_table = predictions.sequences\n#             logits_chart = nets[0].chart_classifier(predictions.encoder_hidden_states[-1][:,0])\n#             logits_table = predictions.sequences\n            padding = (0, cfg.max_label_length - predictions.sequences.size(1))\n            logits_table  = F.pad(logits_table, padding, mode=\"constant\", value=0)\n            logits_charts.append(logits_chart)\n            logits_tables.append(logits_table)\n    val_data = {}\n    val_data['logits_chart'] = torch.cat(logits_charts).cpu()\n    val_data['logits_table'] = torch.cat(logits_tables).cpu()\n    \n    sub_df_line = pp.post_process_pipeline(cfg, val_data, test_df_line)\n    sub_df += [sub_df_line]\n    \n    del ens_net, val_data, test_dl, logits_charts, logits_tables\n    gc.collect()\n    torch.cuda.empty_cache()","metadata":{"papermill":{"duration":989.811484,"end_time":"2023-06-19T13:08:54.051056","exception":false,"start_time":"2023-06-19T12:52:24.239572","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:43:40.075362Z","iopub.execute_input":"2023-06-21T14:43:40.076468Z","iopub.status.idle":"2023-06-21T14:45:26.208525Z","shell.execute_reply.started":"2023-06-21T14:43:40.076433Z","shell.execute_reply":"2023-06-21T14:45:26.207215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Dot","metadata":{"execution":{"iopub.status.busy":"2023-06-09T20:30:08.556428Z","iopub.status.idle":"2023-06-09T20:30:08.557194Z","shell.execute_reply":"2023-06-09T20:30:08.556952Z","shell.execute_reply.started":"2023-06-09T20:30:08.556929Z"},"papermill":{"duration":0.036422,"end_time":"2023-06-19T13:08:54.122191","exception":false,"start_time":"2023-06-19T13:08:54.085769","status":"completed"},"tags":[]}},{"cell_type":"code","source":"if 'dot' in predicted_chart_types:\n    \n    test_df_dot = test_df[test_df['chart_type_pred'] == 'dot'].copy()\n    \n    name = 'cfg_ch_7_2048'\n\n    cfg = get_cfg(name)\n    cfg.backbone = '/kaggle/input/benetech-deplot/google/deplot/'\n    cfg.data_folder = DATA_FOLDER\n    cfg.batch_size = 4\n    cfg.model = \"mdl_dh_08I_val\"\n    cfg.post_process_pipeline =  \"pp_dh_05B\"\n    cfg.pretrained_weights_strict = False\n    cfg.num_beams=1\n    cfg.temperature=1\n    cfg.top_k=1\n    cfg.max_label_length = 512\n#     cfg.post_process_pipeline = 'pp_dh_01J'\n    test_dl, batch_to_device = get_dl(test_df_dot, cfg)\n    test_dl.dataset.processor.image_processor.is_vqa = False\n\n    state_dict_fps = sorted(glob.glob('/kaggle/input/benetech-cfg-ch-18-ff/*/check*'))[:2]\n    state_dict_fps += sorted(glob.glob('/kaggle/input/benetech-cfg-ch-18b-ff/*/check*'))[:1]\n    state_dict_fps += sorted(glob.glob('/kaggle/input/benetech-cfg-ch-18c-ff/*/check*'))[:1]\n    \n    print('\\n'.join(state_dict_fps))\n    ens_net = EnsembleNet(get_nets(cfg,state_dict_fps), cfg)\n\n    pp = importlib.import_module(cfg.post_process_pipeline)\n    \n    print('running inference')\n    # https://huggingface.co/docs/transformers/main_classes/text_generation\n    logits_charts = []\n    logits_tables = []\n    with torch.inference_mode():\n        for tt, batch in tqdm(enumerate(test_dl), total = len(test_dl)):\n            batch = batch_to_device(batch,DEVICE)\n            #encoding = {k:v[:,0].half() for k,v in batch.items() if k in ['flattened_patches', 'attention_mask']}\n#             encoding = {k:v[:,0] for k,v in batch.items() if k in ['flattened_patches', 'attention_mask']}\n#             predictions = nets[0].backbone.generate(**encoding, \n#                                                     max_new_tokens=cfg.max_label_length, \n#                                                     early_stopping=True,\n#                                                     pad_token_id=test_dl.dataset.processor.tokenizer.pad_token_id,\n#                                                     eos_token_id=test_dl.dataset.processor.tokenizer.eos_token_id,\n#                                                     use_cache=True,\n#                                                     num_beams=cfg.num_beams,\n#                                                     temperature=cfg.temperature,\n#                                                     top_k=cfg.top_k,\n#                                                     return_dict_in_generate=True,\n#                                                     output_hidden_states = True)\n            predictions, logits_chart = ens_net(batch)\n            logits_table = predictions.sequences\n#             logits_chart = nets[0].chart_classifier(predictions.encoder_hidden_states[-1][:,0])\n#             logits_table = predictions.sequences\n            padding = (0, cfg.max_label_length - predictions.sequences.size(1))\n            logits_table  = F.pad(logits_table, padding, mode=\"constant\", value=0)\n            logits_charts.append(logits_chart)\n            logits_tables.append(logits_table)\n    val_data = {}\n    val_data['logits_chart'] = torch.cat(logits_charts).cpu()\n    val_data['logits_table'] = torch.cat(logits_tables).cpu()\n    \n    sub_df_dot = pp.post_process_pipeline(cfg, val_data, test_df_dot)\n    sub_df += [sub_df_dot]\n    \n    del ens_net, val_data, test_dl, logits_charts, logits_tables\n    gc.collect()\n    torch.cuda.empty_cache()","metadata":{"papermill":{"duration":145.802744,"end_time":"2023-06-19T13:11:19.957535","exception":false,"start_time":"2023-06-19T13:08:54.154791","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:45:26.212399Z","iopub.execute_input":"2023-06-21T14:45:26.213017Z","iopub.status.idle":"2023-06-21T14:45:26.233143Z","shell.execute_reply.started":"2023-06-21T14:45:26.212983Z","shell.execute_reply":"2023-06-21T14:45:26.232166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df = pd.concat(sub_df)","metadata":{"papermill":{"duration":0.036153,"end_time":"2023-06-19T13:11:20.019822","exception":false,"start_time":"2023-06-19T13:11:19.983669","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:45:26.234550Z","iopub.execute_input":"2023-06-21T14:45:26.235188Z","iopub.status.idle":"2023-06-21T14:45:26.253597Z","shell.execute_reply.started":"2023-06-21T14:45:26.235155Z","shell.execute_reply":"2023-06-21T14:45:26.252842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df.to_csv(\"submission.csv\")\npd.set_option('display.width', None)\nsub_df.head(10)","metadata":{"papermill":{"duration":0.073723,"end_time":"2023-06-19T13:11:20.118578","exception":false,"start_time":"2023-06-19T13:11:20.044855","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:45:26.255060Z","iopub.execute_input":"2023-06-21T14:45:26.255732Z","iopub.status.idle":"2023-06-21T14:45:26.275509Z","shell.execute_reply.started":"2023-06-21T14:45:26.255699Z","shell.execute_reply":"2023-06-21T14:45:26.274650Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!head submission.csv","metadata":{"papermill":{"duration":1.16768,"end_time":"2023-06-19T13:11:21.342228","exception":false,"start_time":"2023-06-19T13:11:20.174548","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-21T14:45:26.278383Z","iopub.execute_input":"2023-06-21T14:45:26.278659Z","iopub.status.idle":"2023-06-21T14:45:27.419211Z","shell.execute_reply.started":"2023-06-21T14:45:26.278636Z","shell.execute_reply":"2023-06-21T14:45:27.417994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os","metadata":{"execution":{"iopub.execute_input":"2023-06-19T13:11:22.575323Z","iopub.status.busy":"2023-06-19T13:11:22.574997Z","iopub.status.idle":"2023-06-19T13:11:22.579414Z","shell.execute_reply":"2023-06-19T13:11:22.578336Z"},"papermill":{"duration":0.034132,"end_time":"2023-06-19T13:11:22.581573","exception":false,"start_time":"2023-06-19T13:11:22.547441","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.listdir('/kaggle/working/')","metadata":{"execution":{"iopub.execute_input":"2023-06-19T13:11:22.638068Z","iopub.status.busy":"2023-06-19T13:11:22.637786Z","iopub.status.idle":"2023-06-19T13:11:22.644473Z","shell.execute_reply":"2023-06-19T13:11:22.643535Z"},"papermill":{"duration":0.037611,"end_time":"2023-06-19T13:11:22.646493","exception":false,"start_time":"2023-06-19T13:11:22.608882","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!rm -rf /kaggle/working/configs/","metadata":{"execution":{"iopub.execute_input":"2023-06-19T13:11:22.700625Z","iopub.status.busy":"2023-06-19T13:11:22.700340Z","iopub.status.idle":"2023-06-19T13:11:23.809146Z","shell.execute_reply":"2023-06-19T13:11:23.807807Z"},"papermill":{"duration":1.139297,"end_time":"2023-06-19T13:11:23.811775","exception":false,"start_time":"2023-06-19T13:11:22.672478","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!rm -rf /kaggle/working/postprocess/","metadata":{"execution":{"iopub.execute_input":"2023-06-19T13:11:23.867529Z","iopub.status.busy":"2023-06-19T13:11:23.866436Z","iopub.status.idle":"2023-06-19T13:11:25.051872Z","shell.execute_reply":"2023-06-19T13:11:25.050447Z"},"papermill":{"duration":1.216543,"end_time":"2023-06-19T13:11:25.054754","exception":false,"start_time":"2023-06-19T13:11:23.838211","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!rm -rf /kaggle/working/data/","metadata":{"execution":{"iopub.execute_input":"2023-06-19T13:11:26.264324Z","iopub.status.busy":"2023-06-19T13:11:26.263465Z","iopub.status.idle":"2023-06-19T13:11:27.351201Z","shell.execute_reply":"2023-06-19T13:11:27.349781Z"},"papermill":{"duration":1.118081,"end_time":"2023-06-19T13:11:27.353974","exception":false,"start_time":"2023-06-19T13:11:26.235893","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!rm -rf /kaggle/working/models/","metadata":{"execution":{"iopub.execute_input":"2023-06-19T13:11:27.409308Z","iopub.status.busy":"2023-06-19T13:11:27.408500Z","iopub.status.idle":"2023-06-19T13:11:28.504619Z","shell.execute_reply":"2023-06-19T13:11:28.503134Z"},"papermill":{"duration":1.126683,"end_time":"2023-06-19T13:11:28.507619","exception":false,"start_time":"2023-06-19T13:11:27.380936","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"papermill":{"duration":0.026225,"end_time":"2023-06-19T13:11:28.560574","exception":false,"start_time":"2023-06-19T13:11:28.534349","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]}]}