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

python目標(biāo)檢測(cè)數(shù)據(jù)增強(qiáng)的代碼參數(shù)解讀及應(yīng)用

 更新時(shí)間:2022年05月09日 11:01:26   作者:Bubbliiiing  
這篇文章主要為大家介紹了python目標(biāo)檢測(cè)數(shù)據(jù)增強(qiáng)的代碼參數(shù)解讀及應(yīng)用,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

數(shù)據(jù)增強(qiáng)做了什么

數(shù)據(jù)增強(qiáng)是非常重要的提高目標(biāo)檢測(cè)算法魯棒性的手段,學(xué)習(xí)一下對(duì)身體有好處!

數(shù)據(jù)增強(qiáng)其實(shí)就是讓圖片變得更加多樣。比如說(shuō)原圖是一個(gè)電腦

如果不使用數(shù)據(jù)增強(qiáng)的話這個(gè)電腦就只是一個(gè)電腦,每次訓(xùn)練的電腦都是這樣的樣子的,但是我們實(shí)際生活中電腦是多樣的。

因此我們可以通過(guò)改變亮度,圖像扭曲等方式使得圖像變得更加多種多樣,如下圖所示,盡管亮度,形態(tài)發(fā)生了細(xì)微改變,但本質(zhì)上,這些東西都依然是電腦。

改變后的圖片放入神經(jīng)網(wǎng)絡(luò)進(jìn)行訓(xùn)練可以提高網(wǎng)絡(luò)的魯棒性,降低各方面額外因素對(duì)識(shí)別的影響。

目標(biāo)檢測(cè)中的圖像增強(qiáng)

在目標(biāo)檢測(cè)中如果要增強(qiáng)數(shù)據(jù),并不是直接增強(qiáng)圖片就好了,還要考慮到圖片扭曲后框的位置。

也就是框的位置要跟著圖片的位置進(jìn)行改變。

如果大家對(duì)我的目標(biāo)檢測(cè)代碼有少許研究的話,應(yīng)該都可以看到。我特別喜歡用這個(gè)數(shù)據(jù)增強(qiáng)代碼:

def get_random_data(annotation_line, input_shape, random=True, max_boxes=20, jitter=.5, hue=.1, sat=1.5, val=1.5, proc_img=True):
    '''random preprocessing for real-time data augmentation'''
    line = annotation_line.split()
    image = Image.open(line[0])
    iw, ih = image.size
    h, w = input_shape
    box = np.array([np.array(list(map(int,box.split(',')))) for box in line[1:]])
    # 對(duì)圖像進(jìn)行縮放并且進(jìn)行長(zhǎng)和寬的扭曲
    new_ar = w/h * rand(1-jitter,1+jitter)/rand(1-jitter,1+jitter)
    scale = rand(.25, 2)
    if new_ar < 1:
        nh = int(scale*h)
        nw = int(nh*new_ar)
    else:
        nw = int(scale*w)
        nh = int(nw/new_ar)
    image = image.resize((nw,nh), Image.BICUBIC)
    # 將圖像多余的部分加上灰條
    dx = int(rand(0, w-nw))
    dy = int(rand(0, h-nh))
    new_image = Image.new('RGB', (w,h), (128,128,128))
    new_image.paste(image, (dx, dy))
    image = new_image
    # 翻轉(zhuǎn)圖像
    flip = rand()<.5
    if flip: image = image.transpose(Image.FLIP_LEFT_RIGHT)
    # 色域扭曲
    hue = rand(-hue, hue)
    sat = rand(1, sat) if rand()<.5 else 1/rand(1, sat)
    val = rand(1, val) if rand()<.5 else 1/rand(1, val)
    x = rgb_to_hsv(np.array(image)/255.)
    x[..., 0] += hue
    x[..., 0][x[..., 0]>1] -= 1
    x[..., 0][x[..., 0]<0] += 1
    x[..., 1] *= sat
    x[..., 2] *= val
    x[x>1] = 1
    x[x<0] = 0
    image_data = hsv_to_rgb(x) # numpy array, 0 to 1
    # 將box進(jìn)行調(diào)整
    box_data = np.zeros((max_boxes,5))
    if len(box)>0:
        np.random.shuffle(box)
        box[:, [0,2]] = box[:, [0,2]]*nw/iw + dx
        box[:, [1,3]] = box[:, [1,3]]*nh/ih + dy
        if flip: box[:, [0,2]] = w - box[:, [2,0]]
        box[:, 0:2][box[:, 0:2]<0] = 0
        box[:, 2][box[:, 2]>w] = w
        box[:, 3][box[:, 3]>h] = h
        box_w = box[:, 2] - box[:, 0]
        box_h = box[:, 3] - box[:, 1]
        box = box[np.logical_and(box_w>1, box_h>1)] # discard invalid box
        if len(box)>max_boxes: box = box[:max_boxes]
        box_data[:len(box)] = box
    return image_data, box_data

里面有一些比較重要的參數(shù)如:

scale = rand(.25, 2)jitter=.5;hue=.1;sat=1.5;val=1.5;

其中:

1、scale代表原圖片的縮放比率,rand(.25, 2)表示在0.25到2之間縮放。

2、jitter代表原圖片的寬高的扭曲比率,jitter=.5表示在0.5到1.5之間扭曲。

3、hue=.1,sat=1.5,val=1.5;分別代表hsv色域中三個(gè)通道的扭曲,分別是:色調(diào)(H),飽和度(S),明度(V)。

實(shí)際效果如下:

原圖:

增強(qiáng)后:

全部代碼

全部代碼構(gòu)成如下:

from PIL import Image, ImageDraw
import numpy as np
from matplotlib.colors import rgb_to_hsv, hsv_to_rgb
def rand(a=0, b=1):
    return np.random.rand()*(b-a) + a
def get_random_data(annotation_line, input_shape, random=True, max_boxes=20, jitter=.5, hue=.1, sat=1.5, val=1.5, proc_img=True):
    '''random preprocessing for real-time data augmentation'''
    line = annotation_line.split()
    image = Image.open(line[0])
    iw, ih = image.size
    h, w = input_shape
    box = np.array([np.array(list(map(int,box.split(',')))) for box in line[1:]])
    # 對(duì)圖像進(jìn)行縮放并且進(jìn)行長(zhǎng)和寬的扭曲
    new_ar = w/h * rand(1-jitter,1+jitter)/rand(1-jitter,1+jitter)
    scale = rand(.25,2)
    if new_ar < 1:
        nh = int(scale*h)
        nw = int(nh*new_ar)
    else:
        nw = int(scale*w)
        nh = int(nw/new_ar)
    image = image.resize((nw,nh), Image.BICUBIC)
    # 將圖像多余的部分加上灰條
    dx = int(rand(0, w-nw))
    dy = int(rand(0, h-nh))
    new_image = Image.new('RGB', (w,h), (128,128,128))
    new_image.paste(image, (dx, dy))
    image = new_image
    # 翻轉(zhuǎn)圖像
    flip = rand()<.5
    if flip: image = image.transpose(Image.FLIP_LEFT_RIGHT)
    # 色域扭曲
    hue = rand(-hue, hue)
    sat = rand(1, sat) if rand()<.5 else 1/rand(1, sat)
    val = rand(1, val) if rand()<.5 else 1/rand(1, val)
    x = rgb_to_hsv(np.array(image)/255.)
    x[..., 0] += hue
    x[..., 0][x[..., 0]>1] -= 1
    x[..., 0][x[..., 0]<0] += 1
    x[..., 1] *= sat
    x[..., 2] *= val
    x[x>1] = 1
    x[x<0] = 0
    image_data = hsv_to_rgb(x) # numpy array, 0 to 1
    # 將box進(jìn)行調(diào)整
    box_data = np.zeros((max_boxes,5))
    if len(box)>0:
        np.random.shuffle(box)
        box[:, [0,2]] = box[:, [0,2]]*nw/iw + dx
        box[:, [1,3]] = box[:, [1,3]]*nh/ih + dy
        if flip: box[:, [0,2]] = w - box[:, [2,0]]
        box[:, 0:2][box[:, 0:2]<0] = 0
        box[:, 2][box[:, 2]>w] = w
        box[:, 3][box[:, 3]>h] = h
        box_w = box[:, 2] - box[:, 0]
        box_h = box[:, 3] - box[:, 1]
        box = box[np.logical_and(box_w>1, box_h>1)] # discard invalid box
        if len(box)>max_boxes: box = box[:max_boxes]
        box_data[:len(box)] = box
    return image_data, box_data
def normal_(annotation_line, input_shape):
    '''random preprocessing for real-time data augmentation'''
    line = annotation_line.split()
    image = Image.open(line[0])
    box = np.array([np.array(list(map(int,box.split(',')))) for box in line[1:]])
    return image, box
if __name__ == "__main__":
    with open("2007_train.txt") as f:
        lines = f.readlines()
    a = np.random.randint(0,len(lines))
    line = lines[a]
    image_data, box_data = normal_(line,[416,416])
    img = image_data
    for j in range(len(box_data)):
        thickness = 3
        left, top, right, bottom  = box_data[j][0:4]
        draw = ImageDraw.Draw(img)
        for i in range(thickness):
            draw.rectangle([left + i, top + i, right - i, bottom - i],outline=(255,255,255))
    img.show()
    image_data, box_data = get_random_data(line,[416,416])
    print(box_data)
    img = Image.fromarray((image_data*255).astype(np.uint8))
    for j in range(len(box_data)):
        thickness = 3
        left, top, right, bottom  = box_data[j][0:4]
        draw = ImageDraw.Draw(img)
        for i in range(thickness):
            draw.rectangle([left + i, top + i, right - i, bottom - i],outline=(255,255,255))
    img.show()
    # img = Image.open(r"F:\Collection\yolo_Collection\keras-yolo3-master\Mobile-yolo3-master/VOCdevkit/VOC2007/JPEGImages/00000.jpg")
    # left, top, right, bottom = 527,377,555,404
    # draw = ImageDraw.Draw(img)
    # draw.rectangle([left, top, right, bottom])
    # img.show()

以上就是python目標(biāo)檢測(cè)數(shù)據(jù)增強(qiáng)的代碼參數(shù)解讀及應(yīng)用的詳細(xì)內(nèi)容,更多關(guān)于python數(shù)據(jù)增強(qiáng)參數(shù)解讀的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Django中日期時(shí)間型字段進(jìn)行年月日時(shí)分秒分組統(tǒng)計(jì)

    Django中日期時(shí)間型字段進(jìn)行年月日時(shí)分秒分組統(tǒng)計(jì)

    這篇文章主要介紹了Django中日期時(shí)間型字段進(jìn)行年月日時(shí)分秒分組統(tǒng)計(jì),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • Python游戲推箱子的實(shí)現(xiàn)

    Python游戲推箱子的實(shí)現(xiàn)

    這篇文章主要介紹了Python游戲推箱子的實(shí)現(xiàn),推箱子游戲是一款可玩性極高的策略解謎手游,游戲中玩家將扮演一名可愛(ài)Q萌的角色,下面我們就看看看具體的實(shí)現(xiàn)過(guò)程吧,需要的小伙伴可以參考一下
    2021-12-12
  • python學(xué)習(xí)筆記:字典的使用示例詳解

    python學(xué)習(xí)筆記:字典的使用示例詳解

    python字典的使用: python字典有很多好用的地方。字典每個(gè)元素都有鍵和值。如同現(xiàn)代漢語(yǔ)字典中的拼音和對(duì)應(yīng)的文字。字典中的鍵是唯一的,而值不一定唯一。你看,和現(xiàn)代漢語(yǔ)字典多么的相似。
    2014-06-06
  • python不同系統(tǒng)中打開(kāi)方法

    python不同系統(tǒng)中打開(kāi)方法

    在本篇文章里小編給大家分享的是一篇關(guān)于python在不同系統(tǒng)中打開(kāi)的方法,有興趣的朋友們可以學(xué)習(xí)下。
    2020-06-06
  • Python使用Flask結(jié)合DeepSeek開(kāi)發(fā)(實(shí)現(xiàn)代碼)

    Python使用Flask結(jié)合DeepSeek開(kāi)發(fā)(實(shí)現(xiàn)代碼)

    文章介紹了如何使用ollama部署DeepSeek大模型,并通過(guò)Python Flask和SSE技術(shù)實(shí)現(xiàn)一個(gè)簡(jiǎn)單的對(duì)話應(yīng)用,代碼實(shí)現(xiàn)了模型的調(diào)用和結(jié)果展示,并討論了SSE不支持POST請(qǐng)求的問(wèn)題及解決方案,感興趣的朋友一起看看吧
    2025-02-02
  • python中的錯(cuò)誤處理及異常斷言詳解

    python中的錯(cuò)誤處理及異常斷言詳解

    這篇文章主要為大家介紹了python中的錯(cuò)誤處理及異常斷言示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-06-06
  • python django生成遷移文件的實(shí)例

    python django生成遷移文件的實(shí)例

    今天小編就為大家分享一篇python django生成遷移文件的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-08-08
  • python使用pandas讀取json文件并進(jìn)行刷選導(dǎo)出xlsx文件的方法示例

    python使用pandas讀取json文件并進(jìn)行刷選導(dǎo)出xlsx文件的方法示例

    這篇文章主要介紹了python使用pandas讀取json文件并進(jìn)行刷選導(dǎo)出xlsx文件的方法,結(jié)合實(shí)例形式分析了python調(diào)用pandas模塊針對(duì)json數(shù)據(jù)操作的相關(guān)使用技巧,需要的朋友可以參考下
    2023-06-06
  • 分享20個(gè)Pandas短小精悍的數(shù)據(jù)操作

    分享20個(gè)Pandas短小精悍的數(shù)據(jù)操作

    本文為大家整理了一個(gè)pandas數(shù)據(jù)操作的大集合,共20個(gè)功能,個(gè)個(gè)短小精悍,一次讓你愛(ài)個(gè)夠,感興趣的小伙伴快跟隨小編一起學(xué)習(xí)一下吧
    2022-04-04
  • 詳解Python3.6安裝psutil模塊和功能簡(jiǎn)介

    詳解Python3.6安裝psutil模塊和功能簡(jiǎn)介

    這篇文章主要介紹了詳解Python3.6安裝psutil模塊和功能簡(jiǎn)介,詳細(xì)的介紹了安裝psutil模塊和該模塊的使用,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-05-05

最新評(píng)論

石嘴山市| 霍州市| 永定县| 宁明县| 曲麻莱县| 田阳县| 宁蒗| 曲水县| 宁化县| 包头市| 浦县| 连江县| 甘德县| 铜梁县| 武穴市| 铁岭县| 东海县| 长顺县| 灵丘县| 奉节县| 长沙县| 扶风县| 横山县| 七台河市| 洛宁县| 丰顺县| 太原市| 康保县| 秦皇岛市| 麻栗坡县| 翁源县| 来宾市| 民县| 西贡区| 益阳市| 沂水县| 南木林县| 五家渠市| 麟游县| 巴彦县| 泸定县|