cnn从图像中提取特征,python

时间:2017-10-27 08:05:23

标签: python image-processing neural-network deep-learning image-segmentation

我需要提取广告页面的组件;首先,我需要检测并标记网页广告页面上的按钮(页面下方的小矩形以及#39;点击')(我将这些页面用作我的数据的图像。)和我#39;已经训练了数据以便通过CNN检测按钮,并且它完全知道图像是否是按钮。但是,在我训练了数据之后,CNN对这些检测到的按钮进行标记时遇到了一些麻烦。任何建议我都会很高兴。这是代码;

from keras.models import Sequential
from keras.layers import Convolution2D
from keras.layers import MaxPooling2D
from keras.layers import Flatten 
from keras.layers import Dense
#Initialising the CNN
classifier = Sequential()
#Step 1: Convolution
classifier.add(Convolution2D(32, 3, 3, input_shape = (64, 64, 3), activation 
= 'relu')) 

#Step 2: Pooling
classifier.add(MaxPooling2D(pool_size= (2,2)))

#Step 3:Flatten
classifier.add(Flatten())

#Step 4: Full connection
classifier.add(Dense(output_dim = 128, activation = 'relu'))
classifier.add(Dense(output_dim = 1, activation = 'sigmoid'))

#Compiling the CNN
classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics 
= ['accuracy'])

#Fitting the CNN to the Images from keras.preprocessing.image import ImageDataGenerator

train_datagen = ImageDataGenerator(rescale=1./255, shear_range=0.2, zoom_range=0.2, horizontal_flip=True)

test_datagen = ImageDataGenerator(rescale=1./255)

training_set = train_datagen.flow_from_directory('train_set1',
                                                 target_size=(64, 64),
                                                 batch_size=32,
                                                 class_mode='binary')

test_set = test_datagen.flow_from_directory('test_set1', target_size(64,64), 
batch_size=32,class_mode='binary')

classifier.fit_generator(training_set, steps_per_epoch=2754, epochs=25, 
validation_data=test_set, nb_val_samples=460)

0 个答案:

没有答案