首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Keras CNN中级没有任何功能更改

Keras CNN中级没有任何功能更改
EN

Stack Overflow用户
提问于 2019-02-28 18:34:46
回答 1查看 107关注 0票数 2

我发现我的数据集的中间层完全没有任何特征变化,如下所示:

其中,Google ML Crash Course中的例子(猫和狗)显示了更丰富的不同特征,如下所示:

我相信正是因为这个原因,CNN在我的数据集上的准确率低得离谱,只有6%左右……

我想知道有没有人知道为什么?

我不认为这是我的数据集的问题(14个类,每个类的amount_of_images = 100-450,训练集中总共有~2500张图像),所以我将跳过这篇文章中关于数据集的细节。我认为这更多的是一个与CNN有关的问题...?

我将我的CNN架构设计如下:

代码语言:javascript
复制
# Our input feature map is 150x150x3: 150x150 for the image pixels, and 3 for
# the three color channels: R, G, and B
img_input = layers.Input(shape=(150, 150, 3))
print(img_input)

# First convolution extracts 16 filters that are 3x3
# Convolution is followed by max-pooling layer with a 2x2 window
x = layers.Conv2D(16, 3, activation='relu', strides=(1,1), padding='same')(img_input)
# x = layers.MaxPooling2D(2)(x)
print(x)

# Second convolution extracts 32 filters that are 3x3
# Convolution is followed by max-pooling layer with a 2x2 window
x = layers.Conv2D(32, 3, activation='relu',strides=(2,2), padding='same')(x)
# x = layers.MaxPooling2D(2)(x)
print(x)

# Third convolution extracts 64 filters that are 3x3
# Convolution is followed by max-pooling layer with a 2x2 window
x = layers.Conv2D(64, 3, activation='relu', strides=(2,2), padding='same')(x)
# x = layers.MaxPooling2D(2)(x)
print(x)

# forth convolution extracts 128 filters that are 3x3
# Convolution is followed by max-pooling layer with a 2x2 window
x = layers.Conv2D(128, 3, activation='relu', strides=(2,2), padding='same')(x)
# x = layers.MaxPooling2D(2)(x)
print(x)

#fifth convolution extracts 256 filters that are 3x3
#Convolution is followed by max-pooling layer with a 2x2 window
x = layers.Conv2D(256, 3, activation='relu', strides=(2,2), padding='same')(x)
# x = layers.MaxPooling2D(2)(x)
print(x)

它可以被看作是以下内容:

代码语言:javascript
复制
Tensor("input_1:0", shape=(?, 150, 150, 3), dtype=float32)
Tensor("conv2d/Relu:0", shape=(?, 150, 150, 16), dtype=float32)
Tensor("conv2d_1/Relu:0", shape=(?, 75, 75, 32), dtype=float32)
Tensor("conv2d_2/Relu:0", shape=(?, 38, 38, 64), dtype=float32)
Tensor("conv2d_3/Relu:0", shape=(?, 19, 19, 128), dtype=float32)
Tensor("conv2d_4/Relu:0", shape=(?, 10, 10, 256), dtype=float32)

然后

代码语言:javascript
复制
# Flatten feature map to a 1-dim tensor so we can add fully connected layers
x = layers.Flatten()(x)

# Create a fully connected layer with ReLU activation and 512 hidden units
x = layers.Dense(512, activation='relu')(x)

# Create output layer with a single node and sigmoid activation
output = layers.Dense(1, activation='sigmoid')(x)

# Create model:
# input = input feature map
# output = input feature map + stacked convolution/maxpooling layers + fully 
# connected layer + sigmoid output layer
model = Model(img_input, output)

以下是每个时期的结果:

代码语言:javascript
复制
Epoch 1/15
126/126 - 92s - loss: -4.6284e+13 - acc: 0.0647 - val_loss: -3.0235e+14 - val_acc: 0.0615
Epoch 2/15
126/126 - 50s - loss: -3.6250e+15 - acc: 0.0639 - val_loss: -1.2503e+16 - val_acc: 0.0615
Epoch 3/15
126/126 - 50s - loss: -4.7133e+16 - acc: 0.0639 - val_loss: -1.2015e+17 - val_acc: 0.0615
Epoch 4/15
126/126 - 50s - loss: -3.0991e+17 - acc: 0.0639 - val_loss: -6.4998e+17 - val_acc: 0.0615
Epoch 5/15
126/126 - 51s - loss: -1.3102e+18 - acc: 0.0639 - val_loss: -2.4530e+18 - val_acc: 0.0615
Epoch 6/15
126/126 - 50s - loss: -4.2291e+18 - acc: 0.0639 - val_loss: -7.3530e+18 - val_acc: 0.0615
Epoch 7/15
126/126 - 50s - loss: -1.1655e+19 - acc: 0.0639 - val_loss: -1.8978e+19 - val_acc: 0.0615
Epoch 8/15
126/126 - 50s - loss: -2.8185e+19 - acc: 0.0639 - val_loss: -4.3459e+19 - val_acc: 0.0615
Epoch 9/15
126/126 - 50s - loss: -6.0396e+19 - acc: 0.0639 - val_loss: -9.0798e+19 - val_acc: 0.0615
Epoch 10/15
126/126 - 51s - loss: -1.2250e+20 - acc: 0.0639 - val_loss: -1.7633e+20 - val_acc: 0.0615
Epoch 11/15
126/126 - 49s - loss: -2.2829e+20 - acc: 0.0639 - val_loss: -3.2223e+20 - val_acc: 0.0615
Epoch 12/15
126/126 - 50s - loss: -4.0790e+20 - acc: 0.0639 - val_loss: -5.5966e+20 - val_acc: 0.0615
Epoch 13/15
126/126 - 51s - loss: -6.9094e+20 - acc: 0.0639 - val_loss: -9.3551e+20 - val_acc: 0.0615
Epoch 14/15
126/126 - 50s - loss: -1.1305e+21 - acc: 0.0639 - val_loss: -1.5039e+21 - val_acc: 0.0615
Epoch 15/15
126/126 - 50s - loss: -1.7871e+21 - acc: 0.0639 - val_loss: -2.3466e+21 - val_acc: 0.0615

为了损失和准确性,我还在这里附上了两个图表:

它基本上是一个Google ML Crash Course的模型,我只是在这里和那里更改了参数,并应用我自己的数据来看看会发生什么。

我的理论是,由于未知的原因,CNN没有从我的数据集中提取任何特征,因此网络在两个时期内就找到了局部最小值。

当我对这个问题摸不着头脑时,任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-01 15:09:33

如果你有14个类,这是没有意义的:

代码语言:javascript
复制
# Create output layer with a single node and sigmoid activation
output = layers.Dense(1, activation='sigmoid')(x)

你应该对14个神经元使用softmax激活:

代码语言:javascript
复制
output = layers.Dense(14, activation='softmax')(x)

然后,您应该确保使用正确的损失(分类或稀疏交叉熵),并在损失需要时对标签进行一次热编码。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54923573

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档