本文介绍了卷积神经网络标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是深度学习的新手,并且有一个项目.我想创建一个简单的CNN,以对(皮肤癌)恶性和良性肿瘤进行二分类.我每个班有两个文件夹.在机器学习分类中,一个经典问题具有特征的X_table和带有标签的Y数组.在我的CNN项目中,我没有每个图像的特征和标签,而我只有两个文件夹,它们具有单独的类.那么我该如何提供我的数据进行训练,显示标签呢?我用Keras编写代码,仅需要这部分的代码.这是尝试:

I am new in Deep Learning and have a project.I want to create a simple CNN for binary classification of malignant and benign tumors (of skin cancer). I have two folders with each class.In a machine learning classification a classical problem has a X_table of features and Y array with labels.In my CNN project i don't have features and labels for each image.I just have two folders with separated classes.So how can i feed my data for training,showing the labels??I code in Keras and need the code for this part only.This is the try:

# Part 1 - Building the CNN

# Importing the Keras libraries and packages
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
from sklearn.model_selection import train_test_split

# Initialising the CNN
classifier = Sequential()

# Step 1 - Convolution
classifier.add(Convolution2D(32, 3, 3, input_shape = (224, 224, 3), activation = 'relu'))

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

# Adding a second convolutional layer
classifier.add(Convolution2D(32, 3, 3, activation = 'relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))

# Step 3 - Flattening
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'])

# Part 2 - Fitting the CNN to the images
Χ=('C:\Users\User\Desktop\MEDICAL IMAGING\skin-cancer-malignant-vs-benign')
X_train, X_test, = train_test_split(Χ, test_size=0.2)

classifier.fit_generator(training_set,
                         samples_per_epoch = 8000,
                         nb_epoch = 25,
                         validation_data = test_set,
                         nb_val_samples = 2000)

推荐答案

基本上,您可以将每个像素视为每个图像的特征.因此,您获得了224、224、3输入,这意味着图像为224 * 224,深度为R,G,B颜色.由于您的输出为二进制,因此输出为1或0.Google只是其中一个很好的例子,其中一个google IO主题演讲( noreferrer> https://youtu.be/VwVg9jCtqaU?list=PLOU2XLYxmsILVTiOlMJdo7RQS55jYhsMi ).卷积层正在生成一些更高级别的特征.但是,如果您具有一些好的特征生成功能,则可以对图像进行一些预处理.

Basically, you can just treat each pixel as a feature for each image. So you got 224, 224, 3 input, which meant a 224*224 image and R,G,B color for depth. As your output is binary, the output is either 1 or 0. Google just had a good example in one of google IO keynote(https://youtu.be/VwVg9jCtqaU?list=PLOU2XLYxmsILVTiOlMJdo7RQS55jYhsMi). The convolution layer is generating some higher level features. But if you have some good feature generate function, you can apply some pre-processing on your image.

这篇关于卷积神经网络标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-12 02:45