Kaggle competition: IEEE-CIS Fraud Detection
<SOS> metric: AUC Kaggle data source: ieee-cis-fraud-detection<define_variables>
LABELS = ["isFraud"]
fig, ax = plt.subplots(3, 3, figsize=(30, 30))
DIR_TEST = '.. /input/global-wheat-detection/test'
for i1 in range(3):
for j1 in range(3):
num = j1*3 + i1
img_pth = os.path.join(DIR_TEST, test_df.image_id[num]+'.jpg')
 image = cv2.imread(img_pth)
 b = [float(i)for i in test_df.PredictionString[num].split(' ')]
boxes = []
i = 0
while i < len(b):
boxes.append([int(b[i+1]),int(b[i+2]),int(b[i+3]),int(b[i+4]),float(b[i])])
 i+=5
boxes = np.array(boxes)
 for box in boxes.astype(float):
cv2.rectangle(image,(int(box[0]), int(box[1])) ,(int(box[0])+int(box[2]), int(box[1])+int(box[3])) ,(0, 32, 255), 3)
 cv2.putText(image, str(box[4]),(int(box[0]), int(box[1])+20), cv2.FONT_HERSHEY_SIMPLEX, 0.9,(36,255,12), 2)
 ax[i1][j1].imshow(image )<install_modules>
%matplotlib inline
all_files = glob.glob(".. /input/lgmodels/*.csv")
 all_files
!pip install --no-deps '.. /input/pycocotools/pycocotools-2.0-cp37-cp37m-linux_x86_64.whl' > /dev/null
!pip install --no-deps '.. /input/effdet012/effdet-0.1.2-py3-none-any.whl' > /dev/null
!pip install --no-deps '.. /input/timm-lab/timm-0.1.30-py3-none-any.whl' > /dev/null<define_variables>
predict_list = []
predict_list.append(pd.read_csv('.. /input/lgmodels/Submission-.9433.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/lgmodels/submission-.9451.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/lgmodels/submission-.9459.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/lgmodels/submission-.9463.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/lgmodels/submission-0.9467.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/lgmodels/Submission-.9440.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/lgmodels/submission-.9454.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/lgmodels/submission-0.9466.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/lgmodels/submission-0.9475.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/lgmodels/submission-0.9433.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/lgmodels/submission-0.9468.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/lgmodels/submission-.9452.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/lgmodels/Submission-.9429.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/lgmodels/submission-.9449.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/lgmodels/submission-.9457.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/lgmodels/Submission-.9438.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/lgmodels/Submission-.9442.csv')[LABELS].values)
 predict_list.append(pd.read_csv('.. /input/lgmodels/submission-.9469.csv')[LABELS].values)
IMG_SIZE = 512<import_modules>
warnings.filterwarnings("ignore")
 print("Rank averaging on ", len(predict_list), " files")
 predictions = np.zeros_like(predict_list[0])
 for predict in predict_list:
for i in range(1):
predictions[:, i] = np.add(predictions[:, i], rankdata(predict[:, i])/predictions.shape[0])
 predictions /= len(predict_list)
 submission = pd.read_csv('.. /input/ieee-fraud-detection/sample_submission.csv')
 submission[LABELS] = predictions
submission.to_csv('AggStacker.csv', index=False )
from ensemble_boxes import *
import torch
import numpy as np
import pandas as pd
from glob import glob
from torch.utils.data import Dataset,DataLoader
import albumentations as A
from albumentations.pytorch.transforms import ToTensorV2
import cv2
import gc
from matplotlib import pyplot as plt
from effdet import get_efficientdet_config, EfficientDet, DetBenchPredict
from effdet.efficientdet import HeadNet<set_options>
sub_path = ".. /input/lgmodels/"
all_files = os.listdir(sub_path)
 all_files
device=torch.device('cuda' if torch.cuda.is_available() else 'cpu' )<choose_model_class>
rank = np.tril(concat_sub.iloc[:,1:].corr().values,-1)
 m =(rank>0 ).sum()
m_gmean, s = 0, 0
for n in range(min(rank.shape[0],m)) :
mx = np.unravel_index(rank.argmin() , rank.shape)
 w =(m-n)/(m+n)
 print(w)
 m_gmean += w*(np.log(concat_sub.iloc[:,mx[0]+1])+np.log(concat_sub.iloc[:,mx[1]+1])) /2
s += w
rank[mx] = 1
m_gmean = np.exp(m_gmean/s )
def load_net(checkpoint_path):
config = get_efficientdet_config('tf_efficientdet_d7')
 net = EfficientDet(config, pretrained_backbone=False)
 config.num_classes = 1
config.image_size = 512
net.class_net = HeadNet(config, num_outputs=config.num_classes, norm_kwargs=dict(eps=.001, momentum=.01),act_layer=timm.models.layers.activations.Mish)
 checkpoint = torch.load(checkpoint_path)
 net.load_state_dict(checkpoint['model_state_dict'])
 del checkpoint
gc.collect()
net = DetBenchPredict(net, config)
 net.eval() ;
return net.cuda()
models = [load_net('.. /input/weight2/fold0-best2.bin'),
load_net('.. /input/weight2/fold1-best2.bin'),
load_net('.. /input/weight2/fold2-best2.bin'),
load_net('.. /input/weight2/fold3-best2.bin'),
load_net('.. /input/weight2/fold4-best2.bin')]<choose_model_class>
concat_sub['isFraud'] = m_gmean
concat_sub[['TransactionID','isFraud']].to_csv('stack_gmean.csv',
index=False, float_format='%.4g' )
<choose_model_class><EOS> 
concat_sub['m_median'] = concat_sub.iloc[:, 1:ncol].median(axis=1)
 concat_sub['isFraud'] = concat_sub['m_median']
concat_sub[['TransactionID','isFraud']].to_csv('stack_median.csv',
index=False, float_format='%.6f' )