Keras神经网络只需要训练几个样本 [英] Keras neural network takes only few samples to train

查看:450
本文介绍了Keras神经网络只需要训练几个样本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

data = np.random.random((10000, 150)) 
labels = np.random.randint(10, size=(10000, 1))
labels = to_categorical(labels, num_classes=10) 

model = Sequential()
model.add(Dense(units=32, activation='relu', input_shape=(150,)))
model.add(Dense(units=10, activation='softmax'))
model.compile(optimizer='rmsprop',
              loss='categorical_crossentropy',
              metrics=['accuracy'])

model.fit(data, labels, epochs=30, validation_split=0.2)

我创建了10000个随机样本来训练我的网络,但只使用其中的几个(250/10000) 第一个纪元的例子:

I created 10000 random samples to train my net, but it use only few of them(250/10000) Exaple of the 1st epoch:

Epoch 1/30

250/250 [==============================-0s 2ms/step-损耗:2.1110 -准确性:0.2389-val_loss:2.2142-val_accuracy:0.1800

推荐答案

您的数据分为训练和验证子集(validation_split = 0.2). 训练子集的大小为8000,验证为2000. 培训分批进行,默认情况下,每批具有32个样本. 因此,一个进度应该进行8000/32 = 250批处理,如进度所示.

Your data is split into training and validation subsets (validation_split=0.2). Training subset has size 8000 and validation 2000. Training goes in batches, each batch has size 32 samples by default. So one epoch should take 8000/32=250 batches, as it shows in the progress.

这篇关于Keras神经网络只需要训练几个样本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆