我没有得到关于狗与猫分类问题的输出。我已经使用了从kaggle到classifiy dog和cat的数据集,我使用了学习率为1e-3的Adam优化器,它没有给出所需的精度。该模型基于使用tflearn的卷积神经网络。但是它提供了50%的准确度,我尝试过使用不同类型的卷积层,我也尝试调整超参数,但它的准确率仍然高达50%。
import tflearn
import numpy as np
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.core import input_data, dropout, fully_connected
from tflearn.layers.estimator import regression
IMG_SIZE = 64
learningRate = 1e-3
MODEL_NAME = 'dogsvscats.model'
train_data = np.load('dog_vs_cat/train_data.npy')
trainData = train_data[:-int(0.33*train_data.shape[0])]
validationData = train_data[-int(0.33*train_data.shape[0]):]
x_train = np.array([i[0] for i in trainData]).reshape(-1,IMG_SIZE,IMG_SIZE,1)
y_train = np.array([i[1] for i in trainData])
x_validation = np.array([i[0] for i in validationData]).reshape(-1,IMG_SIZE,IMG_SIZE,1)
y_validation = np.array([i[1] for i in validationData])
convnet = input_data(shape=[None, IMG_SIZE, IMG_SIZE, 1], name='input')
convnet = input_data(shape=[None, IMG_SIZE, IMG_SIZE, 1], name='input')
convnet = conv_2d(convnet, 32, 5, activation='relu')
convnet = max_pool_2d(convnet, 5)
convnet = conv_2d(convnet, 64, 5, activation='relu')
convnet = conv_2d(convnet, 64, 5, activation='relu')
convnet = max_pool_2d(convnet, 5)
convnet = fully_connected(convnet, 1024, activation='relu')
convnet = dropout(convnet, 0.7)
convnet = fully_connected(convnet, 2, activation='softmax')
convnet = regression(convnet, optimizer='adam', learning_rate=learningRate, loss='categorical_crossentropy', name='targets')
model = tflearn.DNN(convnet, tensorboard_dir='log')
model.fit({'input': x_train}, {'targets': y_train}, n_epoch=10, validation_set=({'input': x_validation}, {'targets': y_validation}), snapshot_step=500, show_metric=True, run_id=MODEL_NAME)
model.save(MODEL_NAME)
模型的输出是:
Training Step: 5239 | total loss: 11.20254 | time: 3.820s
| Adam | epoch: 020 | loss: 11.20254 - acc: 0.5135 -- iter: 16704/16750
Training Step: 5240 | total loss: 11.19760 | time: 4.985s
| Adam | epoch: 020 | loss: 11.19760 - acc: 0.5137 | val_loss: 11.57712 - val_acc: 0.4972 -- iter: 16750/16750
答案 0 :(得分:0)
如果你试试,
convnet = fully_connected(convnet, 1, activation='sigmoid')
convnet = regression(convnet, optimizer='adam', learning_rate=learningRate, loss='binary_crossentropy', name='targets')
[请检查tf的参数名称,我只使用Keras]
你应该获得更好的准确性。但主要问题是你为什么需要使用
convnet = dropout(convnet, 0.7)
首先尝试辍学0.2左右?