简体   繁体   English

python中CNN多类图像分类的边界框预测

[英]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.

相关问题 CNN 图像分类:它总是给我相同的预测 - CNN Image Classification: It gives me always the same prediction CNN-具有多分类的错误预测 - CNN - Wrong prediction with multiclass classification 使用 CNN 进行多类图像分类的错误 - Errors in Multi class image classification using CNN 使用 CNN 的多 class 图像分类 - Multi class image classification using CNN python 中的图像分类得到不准确的预测 - Image classification in python getting not accurate prediction 加载CNN模型以进行文本分类预测时出错 - Error in loading CNN model for text classification prediction 使用CNN对图片进行两类分类,但始终可以将所有内容预测为一类 - Image two-classification with CNN, but it always predicts everything into one class 多次运行,对CNN上图像分类的准确性有影响吗? - Running multiple times, is there any impact to accuracy of Image classification on CNN? 当我测试为多个类别数据集训练的图像分类模型时,为什么会得到相同的类别预测? - Why am I getting same class prediction when I test image classification model trained for multiple class datasets? CNN 图像分类,一条记录有多个输入图像 - CNN Image Classification with multiple input images for one record
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM