Kaggle competition: TGS Salt Identification Challenge
<split><EOS> 
def rle_decode(mask_rle):

 s = mask_rle.split()
starts, lengths = [np.asarray(x, dtype=int)for x in(s[0:][::2], s[1:][::2])]
starts -= 1
ends = starts + lengths
img = np.zeros(101*101, dtype=np.uint8)
 for lo, hi in zip(starts, ends):
img[lo:hi] = 1
return img.reshape(101,101)
 def rle_encode(im):

 pixels = im.flatten()
pixels = np.concatenate([[0], pixels, [0]])
 runs = np.where(pixels[1:] != pixels[:-1])[0] + 1
runs[1::2] -= runs[::2]
return ' '.join(str(x)for x in runs)
 def crf(original_image, mask_img):
if(len(mask_img.shape)<3):
mask_img = gray2rgb(mask_img)
 annotated_label = mask_img[:,:,0] +(mask_img[:,:,1]<<8)+(mask_img[:,:,2]<<16)
 colors, labels = np.unique(annotated_label, return_inverse=True)
 n_labels = 2
d = dcrf.DenseCRF2D(original_image.shape[1], original_image.shape[0], n_labels)
 U = unary_from_labels(labels, n_labels, gt_prob=0.7, zero_unsure=False)
 d.setUnaryEnergy(U)
 d.addPairwiseGaussian(sxy=(3, 3), compat=3, kernel=dcrf.DIAG_KERNEL,
normalization=dcrf.NORMALIZE_SYMMETRIC)
 Q = d.inference(10)
 MAP = np.argmax(Q, axis=0)
 return MAP.reshape(( original_image.shape[0],original_image.shape[1]))
df = pd.read_csv('.. /input/candsub/blend_ez.csv')
 i = 0
j = 0
plt.figure(figsize=(30,15))
plt.subplots_adjust(bottom=0.2, top=0.8, hspace=0.2)
 while True:
if str(df.loc[i,'rle_mask'])!=str(np.nan):
decoded_mask = rle_decode(df.loc[i,'rle_mask'])
 plt.subplot(1,6,j+1)
 plt.imshow(decoded_mask)
 plt.title('ID: '+df.loc[i,'id'])
 j = j + 1
if j>5:
break
i = i + 1
for i in tqdm(range(df.shape[0])) :
if str(df.loc[i,'rle_mask'])!=str(np.nan):
decoded_mask = rle_decode(df.loc[i,'rle_mask'])
 orig_img = imread('.. /input/tgs-salt-identification-challenge/test/images/'+df.loc[i,'id']+'.png')
 crf_output = crf(orig_img,decoded_mask)
 df.loc[i,'rle_mask'] = rle_encode(crf_output)
 df.to_csv('crf_correction_unet_bn_diceloss.csv',index=False )