[英]Bounding box prediction on CNN multiple class image classification in python
I have the training set and test of 4 types of specific objects. 我对4种类型的特定对象进行了训练和测试。 I also have the bound box conditions / Area of interest coordinates (x,y,w,h) in csv format. 我也有csv格式的装订框条件/关注区域坐标(x,y,w,h)。 Main aim of the project is to predict the class of test image along with bounding box around the area of interest along with printing the name of the class on the image. 该项目的主要目的是预测测试图像的类别以及感兴趣区域周围的边框,并在图像上打印类别名称。
I have applied CNN model based on keras library. 我已经基于keras库应用了CNN模型。 which classifies the given images of test set. 它对测试集的给定图像进行分类。 what should i change in order to predict the bounding box coordinates of the given test image ? 为了预测给定测试图像的边界框坐标,我应该改变什么?
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
#CNN initializing
classifier= Sequential()
#convolutional layer
classifier.add(Convolution2D(filters = 32, kernel_size=(3,3), data_format= "channels_last", input_shape=(64, 64, 3), activation="relu"))
#Pooling
classifier.add(MaxPooling2D(pool_size=(2,2)))
#addition of second convolutional layer
classifier.add(Convolution2D(filters = 32, kernel_size=(3,3), data_format= "channels_last", activation="relu"))
classifier.add(MaxPooling2D(pool_size=(2,2)))
#step 3 - FLatttening
classifier.add(Flatten())
#step 4 - Full connection layer
classifier.add(Dense(128, input_dim = 11, activation = 'relu'))
#output layer
classifier.add(Dense(units = 4, activation = 'sigmoid'))
#compiling the CNN
classifier.compile(optimizer='adam',loss="categorical_crossentropy",metrics =["accuracy"])
#part 2 -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('dataset/Train',
target_size = (64, 64),
batch_size = 32,
class_mode = 'categorical')
test_set = test_datagen.flow_from_directory('dataset/Test',
target_size = (64, 64),
batch_size = 32,
class_mode = 'categorical')
classifier.fit_generator(training_set,
steps_per_epoch =4286/32,
epochs = 25,
validation_data = test_set,
validation_steps = 44/32)
The task you described is object detection, which usually requires a more complicated CNN model. 您描述的任务是对象检测,通常需要更复杂的CNN模型。 Check https://github.com/fizyr/keras-retinanet for one of the famous neural network architectures. 检查https://github.com/fizyr/keras-retinanet以了解著名的神经网络架构之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.