<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
url: https://www.kaggle.com/competitions/airbus-ship-detection
Find ships on satellite images as quickly as possible
Data Description
In this competition, you are required to locate ships in images, and put an aligned bounding box segment around the ships you locate. Many images do not contain ships, and those that do may contain multiple ships. Ships within and across images may differ in size (sometimes significantly) and be located in open sea, at docks, marinas, etc.
For this metric, object segments cannot overlap. There were a small percentage of images in both the Train and Test set that had slight overlap of object segments when ships were directly next to each other. Any segments overlaps were removed by setting them to background (i.e., non-ship) encoding. Therefore, some images have a ground truth may be an aligned bounding box with some pixels removed from an edge of the segment. These small adjustments will have a minimal impact on scoring, since the scoring evaluates over increasing overlap thresholds.
The train_ship_segmentations.csv file provides the ground truth (in run-length encoding format) for the training images. The sample_submission files contains the images in the test images.
Please click on each file / folder in the Data Sources section to get more information about the files.
kaggle competitions download -c airbus-ship-detection
該資料以csv格式儲存,具體如下:
由於圖太多,暫時轉換10個
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import numpy as np # linear algebra import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv) from PIL import Image # ref: https://www.kaggle.com/paulorzp/run-length-encode-and-decode # 將圖片編碼成rle格式 def rle_encode(img, min_max_threshold=1e-3, max_mean_threshold=None): ''' img: numpy array, 1 - mask, 0 - background Returns run length as string formated ''' if np.max(img) < min_max_threshold: return '' ## no need to encode if it's all zeros if max_mean_threshold and np.mean(img) > max_mean_threshold: return '' ## ignore overfilled mask pixels = img.T.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) # 將圖片從rle解碼 def rle_decode(mask_rle, shape=(768, 768)): ''' mask_rle: run-length as string formated (start length) shape: (height,width) of array to return Returns numpy array, 1 - mask, 0 - background ''' 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(shape[0] * shape[1], dtype=np.uint8) for lo, hi in zip(starts, ends): # img[lo:hi] = 1 img[lo:hi] = 255 #方便視覺化 return img.reshape(shape).T # Needed to align to RLE direction def masks_as_image(in_mask_list): # Take the individual ship masks and create a single mask array for all ships all_masks = np.zeros((768, 768), dtype=np.uint8) for mask in in_mask_list: if isinstance(mask, str): all_masks |= rle_decode(mask) return all_masks # 將目標路徑下的rle檔案中所包含的所有rle編碼,儲存到save_img_dir中去 def rle_2_img(train_rle_dir, save_img_dir): masks = pd.read_csv(train_rle_dir) not_empty = pd.notna(masks.EncodedPixels) print(not_empty.sum(), 'masks in', masks[not_empty].ImageId.nunique(), 'images') print((~not_empty).sum(), 'empty images in', masks.ImageId.nunique(), 'total images') all_batchs = list(masks.groupby('ImageId')) train_images = [] train_masks = [] i = 0 for img_id, mask in all_batchs[:10]: c_mask = masks_as_image(mask['EncodedPixels'].values) im = Image.fromarray(c_mask) im.save(save_img_dir + img_id.split('.')[0] + '.png') print(i, img_id.split('.')[0] + '.png') i += 1 return train_images, train_masks if __name__ == '__main__': rle_2_img('train_ship_segmentations_v2.csv', 'mask/')
其中為了方便檢視,原計劃0為背景,1為mask,為了方便顯示,設定為255為mask。
到此這篇關於基於Python實現RLE格式分割標註檔案的格式轉換的文章就介紹到這了,更多相關Python RLE檔案內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45