深度学习中的数据增广
問(wèn)題一:為什么需要大量的數(shù)據(jù)
當(dāng)訓(xùn)練機(jī)器學(xué)習(xí)模型的時(shí)候,實(shí)際上實(shí)在調(diào)整它的參數(shù),使得可以跟一個(gè)特定的輸入符合。優(yōu)化的目標(biāo)是 chase that sweet spot where our model’s loss is low。當(dāng)前最好的神經(jīng)網(wǎng)絡(luò)擁有的參數(shù)量是上百萬(wàn)的量級(jí)。 因此,有這么多的參數(shù),就需要a proportional amount of examples 來(lái)學(xué)習(xí)這些參數(shù)。
此外,通過(guò)數(shù)據(jù)增廣提升數(shù)據(jù)集中的相關(guān)數(shù)據(jù),能防止網(wǎng)絡(luò)學(xué)習(xí)到不相關(guān)的特征,更多的學(xué)到更數(shù)據(jù)有關(guān)的性能,顯著的提升整體的性能。
問(wèn)題二:在什么地方做數(shù)據(jù)增廣?
- offline augmentation: 適合相對(duì)小一些的數(shù)據(jù)集;原始數(shù)據(jù)集的數(shù)量跟采用的增廣方法成正比。
- online augmentation: 適合大一些的數(shù)據(jù)集;承擔(dān)不起向前者那樣的成倍增廣,更適合on the mini-batches做增廣。 一些機(jī)器學(xué)習(xí)框架也支持被GPU加速過(guò)的在線增廣。
Popular augmentation techniques
1. Flip
水平或者垂直翻轉(zhuǎn)圖像。
# NumPy.'img' = A single image. flip_1 = np.fliplr(img) # 水平翻轉(zhuǎn)# TensorFlow. 'x' = A placeholder for an image. shape = [height, width, channels] x = tf.placeholder(dtype = tf.float32, shape = shape) flip_2 = tf.image.flip_up_down(x) flip_3 = tf.image.flip_left_right(x) flip_4 = tf.image.random_flip_up_down(x) flip_5 = tf.image.random_flip_left_right(x)2. Rotation
對(duì)這個(gè)操作需要特別注意的是:圖像的維數(shù)不會(huì)被保留。
3. Scale
圖像可以被向內(nèi)或向外縮放,當(dāng)向外縮放的時(shí)候,最終的圖像大小比原始圖像大,很多框架從中crop跟原圖一樣大的部分。
# Scikit Image. 'img' = Input Image, 'scale' = Scale factor # For details about 'mode', checkout the interpolation section below. scale_out = skimage.transform.rescale(img, scale=2.0, mode='constant') scale_in = skimage.transform.rescale(img, scale=0.5, mode='constant') # Don't forget to crop the images back to the original size (for # scale_out)4. Crop
不像縮放,裁剪僅僅從原始圖像隨機(jī)采樣,然后resize到跟原來(lái)一樣大。
# TensorFlow. 'x' = A placeholder for an image. original_size = [height, width, channels] x = tf.placeholder(dtype = tf.float32, shape = original_size) # Use the following commands to perform random crops crop_size = [new_height, new_width, channels] seed = np.random.randint(1234) x = tf.random_crop(x, size = crop_size, seed = seed) output = tf.images.resize_images(x, size = original_size)5. Translation
平移僅僅包括將圖像沿著X或者Y方向移動(dòng)。
6. Gaussian Noise
當(dāng)網(wǎng)絡(luò)嘗試去學(xué)習(xí)高頻特征的時(shí)候很容易過(guò)擬合。零均值高斯噪聲能有效的distorting高斯噪聲,這也意味著低頻部分(通常是想要的部分)也會(huì)損毀,但是你的網(wǎng)絡(luò)能從中學(xué)到目標(biāo)信息。Adding just the right amount of noise can enhance the learning capability.
還可以加椒鹽噪聲,視覺(jué)效果類似于高斯噪聲,但是信息損失的更少。
#TensorFlow. 'x' = A placeholder for an image. shape = [height, width, channels] x = tf.placeholder(dtype = tf.float32, shape = shape) # Adding Gaussian noise noise = tf.random_normal(shape=tf.shape(x), mean=0.0, stddev=1.0, dtype=tf.float32) output = tf.add(x, noise)牢記腦中:當(dāng)做數(shù)據(jù)增廣的時(shí)候,要確保不要增加不相關(guān)的數(shù)據(jù)。
相關(guān)資源
- github數(shù)組增廣包
imgaug學(xué)習(xí)筆記
作者:EdwardMa
鏈接:https://www.jianshu.com/p/ffab1d022d2c
來(lái)源:簡(jiǎn)書(shū)
簡(jiǎn)書(shū)著作權(quán)歸作者所有,任何形式的轉(zhuǎn)載都請(qǐng)聯(lián)系作者獲得授權(quán)并注明出處。
總結(jié)
以上是生活随笔為你收集整理的深度学习中的数据增广的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 目标检测带标签样本增广工具
- 下一篇: 深度学习训练中关于数据处理方式--原始样