MNIST数据分类不适用于Google Colab [英] MNIST data classification not working on Google Colab

查看:115
本文介绍了MNIST数据分类不适用于Google Colab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Google Colab上的深层MLP训练MNIST数字数据集.我已经重塑了输入并进行了数据预处理.模型代码如下:

I am trying to train the MNIST digit dataset using deep MLP on Google colab. I have reshaped the input and performed data preprocessing.The model code is as below:

    #define the model layers
    model = Sequential()
    model.add(Dense(512, input_shape = input_shape, activation = "relu"))
    model.add(Dense(256, activation = "relu"))
    model.add(Dropout(0.1))
    model.add(Dense(128,activation = "relu"))
    model.add(Dense(64,activation = "relu"))
    model.add(Dropout(0.1))
    model.add(Flatten())
    model.add(Dense(tar_class,activation = "sigmoid"))

    model.compile(optimizer = "adam",
          loss = "categorical_crossentropy",
          metrics = ["accuracy"])

    model.summary()

    history = model.fit(X_train,y_train,
                epochs = 10,
                validation_split = 0.1,
                batch_size = 64,
                verbose = True)

当我运行model.fit代码时,训练仅针对数据集中的844个样本进行,而不针对60000个样本进行.但是,此代码在我的本地jupyter笔记本中运行良好.我想在Colab上工作,以便可以使用GPU训练模型,与本地计算机相比,该模型要快.

When I run the model.fit code, the training happens only for 844 samples in the dataset and not for 60000 samples. However, this code works well in my local jupyter notebook. I want to work on Colab so that I can use GPU to train the model, which is quick compared to my local machine.

有人可以在这里帮助我吗?

Can anyone please help me out here?

推荐答案

844并不代表正在训练的样本数量,而是代表每个时期的步数.

The 844 does not represent the number of samples it is getting trained on, but it represents number of steps per epoch.

步骤数是多少?
步骤数等效于通过次数,即在一个时期中发生的(1 pass = 1 Forward Pass + 1 Backward pass).
步骤数计算如下:

What is the number of steps?
The number of steps is equivalent no of passes ie(1 pass = 1 Forward Pass + 1 Backward pass) that occurs in an epoch.
The number of steps is calculated as:

no_of_steps_per_epoch = ceil(Total_no_of_samples / batch_size)

要完成一个纪元,您必须遍历整个数据集. IE.遍历所有批次.

For completion of one epoch, you have to iterate over the entire dataset. ie. iterate over all the batches.

例如: X_train有60000个样本.
您已将validation_split指定为0.1.因此,此X_train的0.1%将用作验证数据. IE.不会用于培训.

For eg: X_train has 60000 samples.
You have specified validation_split as 0.1. Therefore, 0.1 % of this X_train will be used as validation data. ie. It will not be used for training.

因此,用于训练的样本数量将为(60000-6000)= 54000.

Therefore, the number of samples for training will be (60000 - 6000) = 54000.

现在您已将batch_size指定为64.
因此,

Now you have specified batch_size as 64.
Therefore,

no_of_steps_per_epoch = ceil(54000/64) = ceil(843.74) = 844

这就是您获得844的方式.

This is how you get 844.

这并不意味着您正在训练844个样本.

It does not mean you are training on 844 samples.

这篇关于MNIST数据分类不适用于Google Colab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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