我想将深度学习应用于我的分类问题,其中我的数据集中的灰度图像的大小是200x200.目前,我正在对我的大型数据集(超过15,000张图像)的一个非常小的子集(152张图像)测试DL; 我正在使用Keras(版本'1.1.2')库与Theano(版本'0.9.0.dev4')后端Python(Python 2.7.12 :: Anaconda 4.2.0(64位)).我的代码在CPU中运行,但速度非常慢.所以,我切换到GPU.但是,我收到以下错误:
Using Theano backend.
Using gpu device 0: GeForce GTS 450 (CNMeM is enabled with initial size: 70.0% of memory, cuDNN not available)
Train on 121 samples, validate on 31 samples
Epoch 1/200
Traceback (most recent call last):
File "<ipython-input-6-247bada3ec1a>", line 2, in <module>
verbose=1, validation_data=(X_test, Y_test))
File "/home/user1/anaconda2/envs/keras_env/lib/python2.7/site-packages/keras/models.py", line 652, in fit
sample_weight=sample_weight)
File "/home/user1/anaconda2/envs/keras_env/lib/python2.7/site-packages/keras/engine/training.py", line 1111, in fit
initial_epoch=initial_epoch)
File "/home/user1/anaconda2/envs/keras_env/lib/python2.7/site-packages/keras/engine/training.py", line 826, in _fit_loop
outs = f(ins_batch)
File "/home/user1/anaconda2/envs/keras_env/lib/python2.7/site-packages/keras/backend/theano_backend.py", line …Run Code Online (Sandbox Code Playgroud) 我在Keras上阅读了一些关于数据增强的资料,但对我来说仍然有些模糊.是否有任何参数可以控制在数据增强步骤中从每个输入图像创建的图像数量?在此示例中,我看不到任何控制从每个图像创建的图像数量的参数.
例如,在下面的代码中,我可以有一个参数(num_imgs),用于控制从每个输入图像创建的图像数量,并存储在名为preview的文件夹中; 但在实时数据增加中,没有任何参数可用于此目的.
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
num_imgs = 20
datagen = ImageDataGenerator(
rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='nearest')
img = load_img('data/train/cats/cat.0.jpg') # this is a PIL image
x = img_to_array(img) # this is a Numpy array with shape (3, 150, 150)
x = x.reshape((1,) + x.shape) # this is a Numpy array with shape (1, 3, 150, 150)
# the .flow() command below generates batches of randomly transformed images
# and …Run Code Online (Sandbox Code Playgroud) 我使用MATLAB的内置"imfreehand"来定义二进制掩码.边界内的每个像素都设置为1,否则设置为零:
h = imfreehand(handles.fig);
wait(h);
mask = h.creatMask();
Run Code Online (Sandbox Code Playgroud)
然后,我想用4个像素扩大掩模,最后添加一段使边缘更平滑的代码,即掩模的边缘平滑地从1到0; 像汉明或汉宁的窗户.我怎样才能做到这一点?