二进制分类器之后的分类器

时间:2018-10-26 13:46:45

标签: python keras deep-learning

我有一些包含某些结构的图像(例如建筑物)。

我有像素数据和标签数据。

标签数据的格式为:

np.array([[0, nan, nan],
          [1, 2, 1],
          [1, 3, 2]])
  

第一列表示:是否有结构? 1或0

     

第二:结构是什么类型?类型:1,2,3

     

第三个:有多少个结构?

当我们没有结构时,所有其他值都是nan。

因此,对于上面的示例,我们有:

  

第一行:无结构

     

第二行:我们有一个类型2的结构,它是一个

     

第三行:我们有一个类型3的结构,其中有两个

所以,首先我要进行二进制分类,以了解我们是否具有结构。

我正在使用具有预训练权重的vggnet。

imagenet_weights = './vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5'
base_vgg16 = VGG16(include_top=False, weights=imagenet_weights, input_shape=input_shape)
last_layer = base_vgg16.output

x = Flatten()(last_layer)
x = Dense(512, activation='relu')(x)
x = Dropout(0.3)(x)
preds = Dense(1, activation='sigmoid')(x)

base_vgg16.trainable = False
model_vgg16 = Model(base_vgg16.input, preds)

为了进行培训,我正在使用3kfold和数据增强。

这提供了97%的准确性。

现在,我想根据二进制分类结果对分类进行分类。

所以,我有:

pred_val = model.predict(X_val)

现在,我不确定如何继续。

用作分类器输入的内容。

我尝试过:

X_train = X_train[np.where(pred_val >= 0.5), :]

pred_train = model.predict(X_train)
X_train = X_train[np.where(pred_train.squeeze() >= 0.5), :]

(我不确定火车数据是否有预测意义

现在,但是我运行了第二个网络,我总是收到可怕的结果。

Val_loss is almost steady around (10-11)
Train_loss is around 10-12

Val_acc is almost steady around (0.25-0.35)
Train_acc is 0.28-0.38

对于第二个网络:

 inputs = Input(shape=input_shape)
 x = Flatten()(inputs)
 x = Dense(512, activation='relu')(x)
 x = Dense(256, activation='relu')(x)
 preds = Dense(5, activation='softmax')(x)      
 model = Model(inputs, preds)

无论我尝试了多少种组合,都或多或少地尝试了单位(我只尝试了几种类似的方法:x = Dense(8, activation='relu')(x)  或无论批次大小,优化程序和学习率如何,结果都是相同的。

0 个答案:

没有答案