因此,我制作了一个CNN,对两种鸟类进行了分类,并且效果很好。之后,我尝试再添加一种类型,但结果却很奇怪。我已经在ai stack exchange上发布了此帖子,但是他们说最好在这里提问,所以我提供了该帖子的链接。
https://ai.stackexchange.com/q/11444/23452
这是型号代码:
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten, Conv2D, MaxPooling2D
from tensorflow.keras.callbacks import TensorBoard
import pickle
import time as time
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction = 0.333)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
pickle_in = open("C:/Users/Recep/Desktop/programlar/python/X.pickle","rb")
X = pickle.load(pickle_in)
pickle_in = open("C:/Users/Recep/Desktop/programlar/python/Y.pickle","rb")
Y = pickle.load(pickle_in)
X = X/255.0
node_size = 64
model_name = "agi_vs_golden-{}".format(time.time())
tensorboard = TensorBoard(log_dir='C:/Users/Recep/Desktop/programlar/python/logs/{}'.format(model_name))
file_writer = tf.summary.FileWriter('C:/Users/Recep/Desktop/programlar/python/logs/{}'.format(model_name, sess.graph))
model = Sequential()
model.add(Conv2D(node_size,(3,3),input_shape = X.shape[1:]))
#idk what that shape does except that and validation i have no problem
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Conv2D(node_size,(3,3)))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Flatten())
model.add(Dense(node_size))
model.add(Activation("relu"))
model.add(Dense(1))
model.add(Activation("sigmoid"))
model.compile(loss="binary_crossentropy",optimizer="adam",metrics=["accuracy"])
model.fit(X,Y,batch_size=25,epochs=8,validation_split=0.1,callbacks=[tensorboard])
# idk what the validation is and how its used but dont think it caused the problem
model.save("agi_vs_gouldian.model")
顺便说一句,正如我在原始帖子的评论中所说,我认为可能缺乏网络培训,或者我没有足够的数据。因此,我尝试增加了纪元的数量。有点问题,但是我好奇的部分是当我经历了较低的时期时发生了什么?
谁能帮我吗?
我在下面给出张量板图。
顺便说一句,我的数据数组是rgb吗?
而如何摆脱%70的局部最大值?
而且由于我是初学者,所以我不知道什么验证真正有效,但是我看到验证图在我遇到问题的第一次培训中保持不变。
答案 0 :(得分:2)
您尝试用S型将三只鸟分类。 Sigmoid非常适合二进制分类。尝试一个softmax激活层,看看它如何进行。我建议更换
model.add(Dense(1))
model.add(Activation("sigmoid"))
与
model.add(Dense(3, activation='softmax'))
其中3是您要分类的鸟类类型的数量。
在这里看看如何将softmax用作多类分类的激活层的很好的教程
https://machinelearningmastery.com/multi-class-classification-tutorial-keras-deep-learning-library/