Kaggle competition: Tabular Playground Series - Jan 2021
models = []
for path in MODELS:
state_dict = torch.load(path,map_location=torch.device('cpu'))
model = UneXt50()
model.load_state_dict(state_dict)
 model.float()
model.eval()
model.to(device)
 models.append(model)
 del state_dict<categorify>
from catboost import CatBoostRegressor
names,preds = [],[]
for idx,row in tqdm(df_sample.iterrows() ,total=len(df_sample)) :
idx = row['id']
ds = HuBMAPDataset(idx)
 dl = DataLoader(ds,bs,num_workers=0,shuffle=False,pin_memory=True)
 mp = Model_pred(models,dl)
 mask = torch.zeros(len(ds),ds.sz,ds.sz,dtype=torch.int8)
 for p,i in iter(mp): mask[i.item() ] = p.squeeze(-1)> TH
mask = mask.view(ds.n0max,ds.n1max,ds.sz,ds.sz ).\
permute(0,2,1,3 ).reshape(ds.n0max*ds.sz,ds.n1max*ds.sz)
 mask = mask[ds.pad0//2:-(ds.pad0-ds.pad0//2)if ds.pad0 > 0 else ds.n0max*ds.sz,
ds.pad1//2:-(ds.pad1-ds.pad1//2)if ds.pad1 > 0 else ds.n1max*ds.sz]
rle = rle_encode_less_memory(mask.numpy())
 names.append(idx)
 preds.append(rle)
 del mask, ds, dl
gc.collect()<save_to_csv>
df_train = pd.read_csv('/kaggle/input/tabular-playground-series-jan-2021/train.csv')
 y = df_train['target']
df_train.drop(['id', 'target'], axis = 1, inplace = True)
 df_test = pd.read_csv('/kaggle/input/tabular-playground-series-jan-2021/test.csv')
 sub_id = df_test['id']
df_test.drop('id', axis = 1, inplace = True )
df = pd.DataFrame({'id':names,'predicted':preds})
 df.to_csv('submission.csv',index=False )<install_modules>
cbr = CatBoostRegressor()
cbr.fit(df_train, y )
!pip install.. /input/segmentationmodelspytorch-013/pretrainedmodels-0.7.4-py3-none-any.whl
!pip install.. /input/segmentationmodelspytorch-013/efficientnet_pytorch-0.6.3-py2.py3-none-any.whl
!pip install.. /input/segmentationmodelspytorch-013/timm-0.3.2-py3-none-any.whl
!pip install.. /input/segmentationmodelspytorch-013/segmentation_models_pytorch-0.1.3-py3-none-any.whl
clear_output()<load_from_csv>
submission = pd.DataFrame(sub_id, columns = ['id'])
 submission.head()
sample_submission = pd.read_csv('.. /input/hubmap-kidney-segmentation/sample_submission.csv')
 sample_submission = sample_submission.set_index('id')
 seed = 1015
np.random.seed(seed)
 torch.manual_seed(seed)
 torch.cuda.manual_seed(seed)
 device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
 def rle_encode_less_memory(img):

 pixels = img.T.flatten()
pixels[0] = 0
pixels[-1] = 0
runs = np.where(pixels[1:] != pixels[:-1])[0] + 2
runs[1::2] -= runs[::2]
return ' '.join(str(x)for x in runs)
 test_files = sample_submission.index.tolist()<define_variables>
submission['target'] = cbr.predict(df_test )
PATH = ".. /input/hubmap-models2"
model_list = ['1_unet-se_resnet50_0.9526_epoch_28.pth', '2_unet-se_resnet50_0.9494_epoch_28.pth', '1_unet-timm-effb0_0.9495_epoch_39.pth', '2_unet-timm-effb0_0.9477_epoch_35.pth', '1_unet-timm-resnest26d_0.9522_epoch_28.pth', '1_unet-se_resnet50_pesudo_0.9572_epoch_26.pth', '1_unet-timm-resnest26d-pesudo_0.9563_epoch_39.pth']<define_variables>
submission.to_csv('catboost.csv', index = False )