pytorch系列之實用資料增強

2021-10-09 20:39:39 字數 879 閱讀 2225

pytorch資料增強

from pil import image, imagefilter

from torchvision import datasets,transforms

img = image.open(fn) #fn是路徑 記住pytorch資料增強傳入的格式是pil !!!!

mg = img.filter(imagefilter.gaussianblur(radius=1.1)) #模糊半徑越大,就越模糊 高斯濾波

img = transforms.randomrotation(5)(img)

img = transforms.centercrop(28)(img) #亮度

img = transforms.colorjitter(brightness=0.2)(img) # 隨機從 0 ~ 2 之間亮度變化,1 表示原圖

img = transforms.colorjitter(contrast=0.2)(img) # 隨機從 0 ~ 2 之間對比度變化,1 表示原圖 contrast:對比度 saturation:飽和度

img = transforms.colorjitter(saturation=0.2)(img)

img = transforms.colorjitter(hue=0.3)(img) # 隨機從 -0.5 ~ 0.5 之間對顏色變化 brightness:亮度 色調 0<= hue <= 0.5 or -0.5 <= min <= max <= 0.5.

img = transforms.resize([32,32])(img)

img = transforms.randomcrop([28,28])(img)

img.show() #顯示

python基礎篇之實用庫

python 的實用離不開其強大的庫或框架的支援,像正規表示式,檔案模組,命令列模組,django 框架,sk learning 工具箱等.這些都讓 python 能夠非常方便的處理不同領域的問題。初學 python,對 python 的文書處理能力有很深的印象,除了 str 物件自帶的一些方法外,...

boost之實用工具

1.noncopyable用於禁止複製和拷貝的類繼承。宣告拷貝和賦值函式為私有,將執行時的錯誤轉化為編譯期的錯誤。include include using namespace std using namespace boost class mynoncopy private mynoncopy c...

程式設計樂趣之實用小外掛程式

綜上都是在同一網速下測試,明顯感受到idm的速度對應的外掛程式,收藏貓外掛程式商店中都有對應的詳細資訊,這裡就不做詳細介紹了,utools是乙個極簡 外掛程式化 跨平台的現代桌面軟體。通過自由選配豐富的外掛程式,打造你得心應手的工具集合。當你熟悉它後,能夠為你節約大量時間,讓你可以更加專注地改變世界...