def submit(self, preds): for i in range(len(self.x)): file = os.path.basename(self.x[i]['image_file']) for j, c in enumerate(preds[i]): encoded_pixels = mask2rle(c) im_cl = f'{file}_{j + 1}' self.submit_res.append({ 'ImageId_ClassId': im_cl, 'EncodedPixels': encoded_pixels })
preds = preds.detach().cpu().numpy() # Batch post processing for p, file in zip(preds, image_file): file = os.path.basename(file) # Image postprocessing for i in range(4): p_channel = p[i] imageid_classid = file + '_' + str(i + 1) p_channel = (p_channel > thresholds[i]).astype(np.uint8) if p_channel.sum() < min_area[i]: p_channel = np.zeros(p_channel.shape, dtype=p_channel.dtype) res.append({ 'ImageId_ClassId': imageid_classid, 'EncodedPixels': mask2rle(p_channel) }) df = pd.DataFrame(res) df.to_csv('submission.csv', index=False) df = pd.DataFrame(res) df = df.fillna('') df.to_csv('submission.csv', index=False) df['Image'] = df['ImageId_ClassId'].map(lambda x: x.split('_')[0]) df['Class'] = df['ImageId_ClassId'].map(lambda x: x.split('_')[1]) df['empty'] = df['EncodedPixels'].map(lambda x: not x) df[df['empty'] == False]['Class'].value_counts() ### matplotlib inline df = pd.read_csv('submission.csv')[:40] df['Image'] = df['ImageId_ClassId'].map(lambda x: x.split('_')[0])
cls_pred=torch.stack(cls_pred) cls_pred = torch.mean(cls_pred, dim=0) cls_pred = (np.copy(cls_pred) > threshold) # Batch post processing for p_cls,p, file in zip(cls_pred,preds, image_file): file = os.path.basename(file) # Image postprocessing for i in range(4): img_rle = "" p_channel = p[i] imageid_classid = file + '_' + str(i + 1) if p_cls[i]: p_channel = (p_channel > thresholds[i]).astype(np.uint8) if p_channel.sum() >= min_area[i]: img_rle = mask2rle(p_channel) count[i]+=1 # p_channel = np.zeros(p_channel.shape, dtype=p_channel.dtype) res[idx_res] = {'ImageId_ClassId': imageid_classid, 'EncodedPixels': img_rle} idx_res = idx_res + 1 #else: # p_channel = np.zeros(p_channel.shape, dtype=np.uint8) # res.append({ # 'ImageId_ClassId': imageid_classid, # 'EncodedPixels': img_rle # }) df = pd.DataFrame(res) columns = ['ImageId_ClassId','EncodedPixels'] df.to_csv('E:/pycharm_project/steel/code/submit/twotta.csv', index=False, columns=columns) print(count[0],count[1],count[2],count[3])
preds = preds.detach().cpu().numpy() # Batch post processing for p, file in zip(preds, image_file): file = os.path.basename(file) # Image postprocessing for i in range(4): p_channel = p[i] imageid_classid = file + "_" + str(i + 1) p_channel = (p_channel > thresholds[i]).astype(np.uint8) if p_channel.sum() < min_area[i]: p_channel = np.zeros(p_channel.shape, dtype=p_channel.dtype) res.append({ "ImageId_ClassId": imageid_classid, "EncodedPixels": mask2rle(p_channel), }) df = pd.DataFrame(res) df.to_csv("submission.csv", index=False) df = pd.DataFrame(res) df = df.fillna("") df.to_csv("submission.csv", index=False) # In[22]: import pdb import os import cv2 import torch