test_mask_np = ((test_mask+1)*0.5*255).detach().cpu().numpy().transpose(1,2,0) #print( "test_mask_np.shape : ", test_mask_np.shape ) test_mask_pillow = Image.fromarray( np.uint8(test_mask_np[:,:,0]) ) test_mask_pillow.save( "_debug/test_mask.png" ) test_mask_splits, class_ids = split_masks( mask_np = test_mask_np, n_classes = args.n_classes ) for j, label in enumerate(class_ids): test_mask_pillow_label = Image.fromarray( np.uint8(test_mask_splits[j]) ) test_mask_pillow_label.save( "_debug/test_mask_{}.png".format(label) ) """ # 画像ファイル名 image_names.append(name) # RLE の計算 encoded_pixels.append(convert_rle(np.round(y_pred_test_org))) # クラスラベル class_ids.append(0) # dummy df_submission = pd.DataFrame( { 'EncodedPixels': encoded_pixels, 'ClassId': class_ids }, index=image_names) df_submission.index.names = ['ImageId'] df_submission.to_csv( os.path.join(args.results_dir, args.exper_name, args.submit_file)) if (args.submit):
# Kaggle API での submit #================================ # RLE [Run Length Encoding] 形式で提出のため生成画像を元の画像サイズに変換 y_pred_test_org = np.zeros( (len(y_pred_test), args.image_height_org, args.image_width_org), dtype=np.float32) for i in range(len(y_pred_test)): y_pred_test_org[i] = cv2.resize( y_pred_test[i, 0, :, :].squeeze(), (args.image_height_org, args.image_width_org), interpolation=cv2.INTER_NEAREST) #y_pred_test_org[i] = resize( y_pred_test[i,0,:,:].squeeze(), (args.image_height_org, args.image_width_org), mode='constant', preserve_range=True ) # 提出用データに値を設定 y_sub = { name.split(".png")[0]: convert_rle(np.round(y_pred_test_org[i] > 0.0)) for i, name in enumerate(test_image_names) } df_submission = pd.DataFrame.from_dict(y_sub, orient='index') df_submission.index.names = ['id'] df_submission.columns = ['rle_mask'] df_submission.to_csv( os.path.join(args.results_dir, args.exper_name, args.submit_file)) if (args.submit): # Kaggle-API で submit api = KaggleApi() api.authenticate() api.competition_submit( os.path.join(args.results_dir, args.exper_name, args.submit_file), args.exper_name, args.competition_id)
# IoU pass #================================ # 可視化処理 #================================ pass #================================ # Kaggle API での submit #================================ # 提出用データに値を設定 y_sub = [] for i in range(len(y_pred_test)): rle = convert_rle(y_pred_test[i]) print("rle : ", rle) y_sub.append(rle) df_submission['rle_mask'] = y_sub df_submission.to_csv(os.path.join(args.results_dir, args.exper_name, args.submit_file), index=False) if (args.submit): # Kaggle-API で submit api = KaggleApi() api.authenticate() api.competition_submit( os.path.join(args.results_dir, args.exper_name, args.submit_file), args.exper_name, args.competition_id) os.system('kaggle competitions submissions -c {}'.format(
# RLE [Run Length Encoding] 形式で提出のため生成画像を元の画像サイズに変換 y_pred_test_org = np.zeros( (len(y_pred_test), args.image_height_org, args.image_width_org), dtype=np.float32) for i in range(len(y_pred_test)): y_pred_test_org[i] = cv2.resize( y_pred_test[i, 0, :, :].squeeze(), (args.image_height_org, args.image_width_org), interpolation=cv2.INTER_NEAREST) #y_pred_test_org[i] = resize( y_pred_test[i,0,:,:].squeeze(), (args.image_height_org, args.image_width_org), mode='constant', preserve_range=True ) # 提出用データに値を設定 #threshold_best = 0.0 y_sub = { name.split(".png")[0]: convert_rle(np.round(y_pred_test_org[i] > threshold_best)) for i, name in enumerate(test_image_names) } df_submission = pd.DataFrame.from_dict(y_sub, orient='index') df_submission.index.names = ['id'] df_submission.columns = ['rle_mask'] df_submission.to_csv( os.path.join(args.results_dir, args.exper_name, args.submit_file)) if (args.submit): # Kaggle-API で submit api = KaggleApi() api.authenticate() api.competition_submit( os.path.join(args.results_dir, args.exper_name, args.submit_file), args.exper_name, args.competition_id)