一类与喀拉拉邦的分类 [英] one class classification with keras
问题描述
我正在尝试建立一个模型来检测输入图像是否是某些东西(例如,狗或不).我正在用keras编码,但是准确性很差.您有什么想法可以正确调整吗?还是我应该使用除keras之外的其他工具来解决一类分类问题?提前非常感谢您.
I am trying to build a model to detect whether the input image is something or not(For example, dog or not). I'm coding with keras, but the accuracy is terrible. Do you have any idea to tune this correctly? Or should I use other tools other than keras for one class classification problem? Thank you so much in advance.
这是到目前为止我写的代码和输出.
Here's the code and the output I've wrote so far.
train_dir = './path/to/train_dir'
vali_dir = './path/to/validation_dir'
train_datagen = ImageDataGenerator(
rescale=1./255,
rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=False)
test_datagen = ImageDataGenerator(rescale=1./255)
train_generator = train_datagen.flow_from_directory(
train_dir,
target_size=(150, 150),
batch_size=20,
class_mode='binary')
vali_datagen = ImageDataGenerator(rescale=1./255)
vali_generator = vali_datagen.flow_from_directory(
vali_dir,
target_size=(150, 150),
batch_size=20,
class_mode='binary')
model = Sequential()
model.add(Conv2D(16, 3, activation='relu', input_shape=(150, 150, 3)))
model.add(MaxPool2D(pool_size=2))
model.add(Conv2D(32, 3, activation='relu'))
model.add(MaxPool2D(pool_size=2))
model.add(Conv2D(64, 3, activation='relu'))
model.add(Flatten())
model.add(Dense(512, activation='relu'))
model.add(Flatten())
model.add(Dense(1024, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(1, activation='sigmoid'))
model.compile(
loss='binary_crossentropy',
optimizer=RMSprop(lr=0.003),
metrics=['acc']
)
history = model.fit_generator(
train_generator,
steps_per_epoch=100,
epochs=8,
verbose=2,
validation_data=vali_generator,
validation_steps=20
)
输出:
Found 3379 images belonging to 2 classes.
Found 607 images belonging to 2 classes.
Epoch 1/8
- 136s - loss: 7.6617 - acc: 0.5158 - val_loss: 10.5220 - val_acc: 0.3400
Epoch 2/8
- 124s - loss: 7.7837 - acc: 0.5118 - val_loss: 10.5220 - val_acc: 0.3400
.......and this is just terrible.
推荐答案
我尝试更改和调整参数和训练数据,但没有得到理想的结果.我遇到了一个使用Isolation forest
的类分类.这就是所谓的新颖性检测,在我使用它之后,它的表现非常出色.感谢那些在评论中建议我的人,很抱歉我自己回答.
I tried to change and tune the parameter and the training data but I didn't get a desirable result. I came across with one class classification using Isolation forest
. This is known as novelty detection, and after I used it, it performs outstandingly. Thanks for those who advised me in the comments, and I'm sorry to answer on my own.
这篇关于一类与喀拉拉邦的分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!