多层感知神经网络具有10%的精度



我正在使用CIFAR-10数据集训练我的神经网络,并且我的分数大约是0.10,这就好像我的神经网络只是猜测(1/10的赔率一个正确的答案),CIFAR-10具有32x32图像的10种类型的事物(汽车,飞机,猫,狗等)。我怀疑我的代码有问题。

顺便说一句,这不是文件未点缀

的问题

请帮助我!

from sklearn import datasets
from sklearn.neural_network import MLPClassifier
import numpy as np
import time
labels = ["airplane", "automobile", "bird", "cat", "deer", "dog", "frog", "horse", "ship", "truck"]
def unpickle(f):
    import cPickle
    fo = open(f, "rb")
    dict = cPickle.load(fo)
    fo.close()
    return dict
def setup_mlp(unpickled_data):
    new_mlp = MLPClassifier(hidden_layer_sizes=3072, solver='sgd', batch_size=1000, max_iter=500, random_state=1, learning_rate_init=0.01)
    return new_mlp
#hidden_layer_sizes is the number of neurons in a layer. In this case I have one hidden layer & 3072 neurons in that layer
if __name__ == "__main__":
    unpickled_batch = unpickle("./data_batch_1")
    print int(unpickled_batch["data"].shape[0])
    #time.sleep(1000)
    X_train = unpickled_batch["data"][:1000]
    Y_train = unpickled_batch["labels"][:1000]
    print "Decoded batch, now trainingn"
    mlp = setup_mlp(unpickled_batch)
    mlp.fit(X_train, Y_train)
    print "Score=" + str(mlp.score(X_train, Y_train))

我昨天有类似的问题,所以也许这可以帮助您。

MLPClassifier在CIFAR-10上工作正常,如果您标准化数据集,即添加

from sklearn import preprocessing X_train = preprocessing.scale(X_train)

加载数据后。

但这还不够

要解决此问题,您可以从CIFAR-10文件加载'test_batch'或拆分unpicklet_batch [" data"]和unpicklet_batch [" labels"]来训练我测试数据集。

之后,根据测试集的大小,您应该得到大约0.3的得分。

最新更新