我正在使用CIFAR-10数据集来训练我的神经网络,我得到的分数约为0.10
,就好像我的神经网络只是在猜测(正确答案的1/10几率) ,CIFAR-10有10种类型的东西(汽车,飞机,猫,狗等)的32x32图像。我怀疑我的代码有问题。
顺便说一下,文件unpickling不是问题
请帮助我!!
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 training\n"
mlp = setup_mlp(unpickled_batch)
mlp.fit(X_train, Y_train)
print "Score=" + str(mlp.score(X_train, Y_train))
答案 0 :(得分:0)
昨天我遇到了类似的问题,所以也许这可以帮到你。
如果您将数据集标准化,MLPClassifier在Cifar-10上运行良好,即 添加
from sklearn import preprocessing
X_train = preprocessing.scale(X_train)
。
但这还不够,因为你的测试集与训练集相同,你最终得分= 1.0,没有新图像预测的信息。
要解决此问题,您可以加载' test_batch'来自cifar-10文件或拆分unpickled_batch ["数据"]和unpickled_batch ["标签"]来训练i测试数据集。
之后你应该得到大约0.3分,这取决于测试集的大小。