最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于Python實(shí)現(xiàn)RLE格式分割標(biāo)注文件的格式轉(zhuǎn)換

 更新時(shí)間:2022年08月18日 09:18:57   作者:Livingbody  
本文將以Airbus Ship Detection Challenge為例,為大家詳細(xì)講解Python實(shí)現(xiàn)RLE格式分割標(biāo)注文件格式轉(zhuǎn)換的方法,感興趣的可以了解一下

1.Airbus Ship Detection Challenge

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

2.數(shù)據(jù)展示

2.1 標(biāo)注數(shù)據(jù)

該數(shù)據(jù)以csv格式存儲(chǔ),具體如下:

2.2 圖象文件

3.格式轉(zhuǎn)換

由于圖太多,暫時(shí)轉(zhuǎn)換10個(gè)

#!/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


# 將目標(biāo)路徑下的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/')

其中為了方便查看,原計(jì)劃0為背景,1為mask,為了方便顯示,設(shè)置為255為mask。

4.轉(zhuǎn)換結(jié)果

到此這篇關(guān)于基于Python實(shí)現(xiàn)RLE格式分割標(biāo)注文件的格式轉(zhuǎn)換的文章就介紹到這了,更多相關(guān)Python RLE文件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python中matplotlib實(shí)現(xiàn)最小二乘法擬合的過程詳解

    python中matplotlib實(shí)現(xiàn)最小二乘法擬合的過程詳解

    這篇文章主要給大家介紹了關(guān)于python中matplotlib實(shí)現(xiàn)最小二乘法擬合的相關(guān)資料,文中通過示例代碼詳細(xì)介紹了關(guān)于最小二乘法擬合直線和最小二乘法擬合曲線的實(shí)現(xiàn)過程,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-07-07
  • Python?PyCharm無法打開終端命令行最終解決方案(實(shí)測(cè)成功)

    Python?PyCharm無法打開終端命令行最終解決方案(實(shí)測(cè)成功)

    這篇文章主要介紹了在使用PyCharm?2024版本時(shí)遇到的無法打開終端的問題,文中提供了兩種解決方案,大家可以根據(jù)自己的需求選擇對(duì)應(yīng)的解決方法,需要的朋友可以參考下
    2024-12-12
  • python正則表達(dá)式用法超詳細(xì)講解大全

    python正則表達(dá)式用法超詳細(xì)講解大全

    正則表達(dá)式是一種用來匹配字符串的強(qiáng)有力的武器,利用字符來匹配字符的思想,基于顯示規(guī)則進(jìn)行模式匹配,可以高效組合成不同樣式的字符串,下面這篇文章主要給大家介紹了關(guān)于python正則表達(dá)式用法超詳細(xì)講解的相關(guān)資料,需要的朋友可以參考下
    2022-10-10
  • pytorch實(shí)踐線性模型3d詳解

    pytorch實(shí)踐線性模型3d詳解

    這篇文章主要介紹了pytorch實(shí)踐線性模型3d詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-04-04
  • python+rsync精確同步指定格式文件

    python+rsync精確同步指定格式文件

    這篇文章主要為大家詳細(xì)介紹了python+rsync精確同步指定格式文件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-08-08
  • 使用Python實(shí)現(xiàn)搖號(hào)系統(tǒng)的詳細(xì)步驟

    使用Python實(shí)現(xiàn)搖號(hào)系統(tǒng)的詳細(xì)步驟

    這篇文章主要介紹了如何使用Python構(gòu)建一個(gè)簡(jiǎn)單的搖號(hào)系統(tǒng),包括需求分析、技術(shù)棧、實(shí)現(xiàn)步驟和完整代碼示例,該系統(tǒng)能夠從用戶輸入的參與者名單中隨機(jī)抽取指定數(shù)量的中獎(jiǎng)?wù)?并將結(jié)果展示給用戶以及記錄到日志文件中,需要的朋友可以參考下
    2024-11-11
  • python Opencv將圖片轉(zhuǎn)為字符畫

    python Opencv將圖片轉(zhuǎn)為字符畫

    這篇文章主要為大家詳細(xì)介紹了python Opencv將圖片轉(zhuǎn)為字符畫的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-03-03
  • Python爬蟲技術(shù)

    Python爬蟲技術(shù)

    本文將要介紹的是python爬蟲基礎(chǔ)知識(shí),感興趣的小伙伴一起來學(xué)習(xí)吧
    2021-08-08
  • Python類的繼承用法示例

    Python類的繼承用法示例

    這篇文章主要介紹了Python類的繼承用法,結(jié)合實(shí)例形式分析了Python類的定義、繼承等相關(guān)操作技巧,需要的朋友可以參考下
    2019-01-01
  • python進(jìn)階教程之動(dòng)態(tài)類型詳解

    python進(jìn)階教程之動(dòng)態(tài)類型詳解

    這篇文章主要介紹了python進(jìn)階教程之動(dòng)態(tài)類型詳解,動(dòng)態(tài)類型是動(dòng)態(tài)語言的特性,本文對(duì)多種動(dòng)態(tài)類型應(yīng)用做了講解,需要的朋友可以參考下
    2014-08-08

最新評(píng)論

贵港市| 武汉市| 沙坪坝区| 陈巴尔虎旗| 福安市| 化德县| 鹤庆县| 丹江口市| 兴隆县| 孟州市| 双江| 湘潭市| 平安县| 临邑县| 高阳县| 天长市| 东阿县| 德庆县| 织金县| 呼图壁县| 莒南县| 陆河县| 芒康县| 沂南县| 中山市| 荣昌县| 黔西县| 兰州市| 金山区| 繁昌县| 达孜县| 犍为县| 尼勒克县| 射阳县| 抚松县| 锦州市| 吉林省| 油尖旺区| 杨浦区| 如皋市| 时尚|