如标题中所述,我不知道如何建立犬种识别的最佳模型。
我尝试了各种方法,例如删除图层,更改密实值,增加学习率,增加衰减率,甚至更改优化程序,但无济于事
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense,Dropout,Activation, Flatten, Conv2D, MaxPooling2D
#print(X)
# print(y)
model = Sequential()
# METHOD TWO(Works but not accurate, built by self)
model.add(Conv2D(128,(3,3),input_shape=X.shape[1:]))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Activation("relu"))
model.add(Conv2D(128,(3,3)))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Activation("relu"))
model.add(Flatten())
model.add(Activation("relu"))
model.add(Dense(2048))
model.add(Dropout(0.5))
model.add(Activation("relu"))
model.add(Dense(2048))
model.add(Dropout(0.5))
model.add(Activation("relu"))
model.add(Dense(2048))
model.add(Dropout(0.5))
model.add(Activation("softmax"))
model.add(Dense(120))
opt = tf.keras.optimizers.Adam()
model.compile(optimizer = opt,
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
# from tfkeras.utils import to_categorical
# y_binary = tf.keras.utils.to_categorical(y)
# y_binary = to_categorical(y)
model.fit(X, y,epochs=2)
Epoch 1/2
20580/20580 [==============================] - 311s 15ms/sample - loss: 4.8735 - acc: 0.0084
Epoch 2/2
12448/20580 [=================>............] - ETA: 2:02 - loss: 4.7875 - acc: 0.0071
答案 0 :(得分:4)
这里有些错误的地方:
model.add(Conv2D(128, (3, 3), input_shape=X.shape[1:], activation='relu', padding='same'))
model.add(MaxPooling2D(pool_size=(2,2)))
或
model.add(Conv2D(128,(3,3),input_shape=X.shape[1:]))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Dense(120))
model.add(Activation("softmax"))
model.add(Conv2D(64, (3, 3) , padding='SAME'))
model.add(Activation("relu"))
model.add(Conv2D(64, (3, 3) , padding='SAME'))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
您可以根据需要操纵此类块,尝试使用具有不同数量过滤器的多个块,等等
model.add(Flatten())
model.add(Dense(256))
model.add(Activation('relu')
model.add(Dense(128)(x)
model.add(Activation('relu'))
model.add(Dense(120))
model.add(Activation('softmax'))
在评论中告诉我此更改为您带来的结果!