Kaggle competition: Severstal: Steel Defect Detection
<data_type_conversions>
model = torch.jit.load(".. /input/mixmocrjit/_ckpt_epoch_64_jit.pth")
 model.eval() ;
model.cuda() ;
user_sum_dict = user_agg['sum'].astype('int16' ).to_dict(defaultdict(int))
user_count_dict = user_agg['count'].astype('int16' ).to_dict(defaultdict(int))
content_sum_dict = content_agg['sum'].astype('int32' ).to_dict(defaultdict(int))
content_count_dict = content_agg['count'].astype('int32' ).to_dict(defaultdict(int))
del user_agg
del content_agg
gc.collect()
task_container_sum_dict = task_container_agg['sum'].astype('int32' ).to_dict(defaultdict(int))
task_container_count_dict = task_container_agg['count'].astype('int32' ).to_dict(defaultdict(int))
task_container_std_dict = task_container_agg['var'].astype('float16' ).to_dict(defaultdict(int))
explanation_sum_dict = explanation_agg['sum'].astype('int16' ).to_dict(defaultdict(int))
explanation_count_dict = explanation_agg['count'].astype('int16' ).to_dict(defaultdict(int))
del task_container_agg
del explanation_agg
gc.collect()<data_type_conversions>
test_data_folder = ".. /input/severstal-steel-defect-detection/test_images"
dataset = TestSegDataset(
 imgdir=test_data_folder,
color_channel="RGB",
normalize=True,
use_tta=False,
ignore_background=True,
input_size=(256,1600), 
)
 print(len(dataset))
dataloader = DataLoader(
 dataset=dataset,
batch_size=14,
shuffle=False,
num_workers=2,
pin_memory=True,
collate_fn=dataset.collate_fn, 
)
 print(len(dataloader))
user_lecture_sum_dict = user_lecture_agg['sum'].astype('int16' ).to_dict(defaultdict(int))
user_lecture_count_dict = user_lecture_agg['count'].astype('int16' ).to_dict(defaultdict(int))
lagtime_mean_dict = lagtime_agg['mean'].astype('int32' ).to_dict(defaultdict(int))
del user_lecture_agg
del lagtime_agg
gc.collect()<categorify>
def fuse_mask_score(cls_score, obj_score,segm_scores, use_sigmoid=True, cls_thresh_prob=0.45):
masks_scores = segm_scores*obj_score
if not use_sigmoid:
masks_scores[:,0,:,:] +=(1-obj_score[:,0,:,:])
 background_proposal_cls = cls_score.squeeze() < cls_thresh_prob
if use_sigmoid:
masks_scores[background_proposal_cls] = 0.0
else:
masks_scores[background_proposal_cls,0,:,:]=1.0
masks_scores[background_proposal_cls,1:,:,:]=0.0
return masks_scores
attempt_no_agg=attempt_no_agg[attempt_no_agg['sum'] >1]
attempt_no_sum_dict = attempt_no_agg['sum'].to_dict(defaultdict(int))
del attempt_no_agg
gc.collect()<categorify>
predictions = []
with torch.no_grad() :
for batch in tqdm(dataloader, total=len(dataloader)) :
filenames = batch['fnames']
imgs = batch['images']
imgs = imgs.cuda()
cls_score, obj_score, segm_scores = model(imgs)
 mask_score = fuse_mask_score(cls_score, obj_score,segm_scores, use_sigmoid=False, cls_thresh_prob=0.45)
 for dim_tta in [(2,),(3,),(2,3)]:
imgs_tta = imgs.flip(dims=dim_tta)
 cls_score, obj_score, segm_scores = model(imgs_tta)
 mask_score_tta = fuse_mask_score(cls_score, obj_score,segm_scores, use_sigmoid=False, cls_thresh_prob=0.45)
 mask_score_tta = mask_score_tta.flip(dim_tta)
 mask_score +=mask_score_tta
mask_score /=4
N,num_class,H,W = mask_score.shape
masks = torch.argmax(mask_score,dim=1)
 masks = masks.squeeze()
masks_binary = F.one_hot(masks,num_class)
 masks_binary = masks_binary.permute(0,3,1,2)[:,1:,:,:]
masks_binary = masks_binary.cpu().numpy()
for i in range(N):
fname = filenames[i].split('/')[-1]
mask_i = masks_binary[i]
for cls_idx in range(num_class-1):
rle = mask2rle(mask_i[cls_idx].astype('uint8'))
name = f'{fname}_{cls_idx+1}'
predictions.append(( name, rle))
max_timestamp_u_dict=max_timestamp_u.set_index('user_id' ).to_dict()
user_prior_question_elapsed_time_dict=user_prior_question_elapsed_time.set_index('user_id' ).to_dict()
del max_timestamp_u
del user_prior_question_elapsed_time
gc.collect()<feature_engineering>
sample_submission_path = 'submission.csv'
df = pd.DataFrame(predictions, columns=['ImageId_ClassId', 'EncodedPixels'])
 df.to_csv(sample_submission_path, index=False )
<split><EOS> 
df_results = pd.read_csv("submission.csv")
 num_samples = len(df_results)
 num_images = int(num_samples / 4)
 print(df_results.shape)
 print(df_results.head(18))