简体   繁体   English

在Theano中使用GPU进行数据增强

[英]Data Augmentation using GPU in Theano

I am new in Theano and Deep Learning, I am running my experiments in Theano but I would like to reduce the time I spend per epoch by doing data augmentation directly using the GPU. 我是Theano和Deep Learning的新手,我正在Theano中运行实验,但我想通过直接使用GPU进行数据增强来减少每个纪元花费的时间。

Unfortunately I can not use PyCuda, so I would like to know if is possible to do basic Data Augmentation using Theano. 不幸的是我不能使用PyCuda,所以我想知道是否可以使用Theano进行基本的数据增强。 For example Translation or Rotation in images, meanwhile I am using scipy functions in CPU using Numpy but it is quite slow. 例如,图像中的平移或旋转,与此同时,我正在使用Numpy在CPU中使用scipy函数,但速度相当慢。

If the data augmentation is part of your computation graph, and can be executed on GPU, it will naturally be executed on the GPU. 如果数据扩充是计算图的一部分,并且可以在GPU上执行,则自然会在GPU上执行。 So the question narrows down to "is it possible to do common data augmentation tasks using Theano tensor operations on the GPU". 因此,问题缩小为“是否有可能使用GPU上的Theano张量运算来执行常见的数据增强任务”。

If the transformations you want to apply are just translations, you can just use theano.tensor.roll followed by some masking. 如果要应用的转换只是翻译,则可以仅使用theano.tensor.roll然后进行一些遮罩。 If you want the rotations as well, take a look at this implementation of spatial transformer network . 如果还需要旋转,请看一下空间变压器网络的这种实现 In particular take a look at the _transform function, it takes as an input a matrix theta that has a 2x3 transformation (left 2x2 is rotation, and right 1x2 is translation) one per sample and the actual samples, and applies the rotation and translation to those samples. 特别要看一下_transform函数,它以一个矩阵theta为输入,该矩阵对每个样本和实际样本进行2x3变换(左2x2是旋转,右1x2是平移),并将旋转和平移应用于这些样品。 I didn't confirm that what it does is optimized for the GPU (ie it could be that the bottleneck of that function is executed on the CPU, which will make it not appropriate for your use case), but it's a good starting point. 我没有确认它针对GPU进行了优化(例如,该功能的瓶颈可能在CPU上执行,这将使其不适用于您的用例),但这是一个很好的起点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM