【问题标题】:keras mnist.load_data() is superslow and throw an error after some timeskeras mnist.load_data() 超级慢,并在一段时间后抛出错误
【发布时间】:2018-08-23 06:01:35
【问题描述】:

这是我使用的全部代码

import os
import numpy as np
import matplotlib.pyplot as plt
from tqdm import tqdm


from keras.layers import Input
from keras.models import Model, Sequential
from keras.layers.core import Dense, Dropout
from keras.layers.advanced_activations import LeakyReLU
from keras.datasets import mnist
from keras.optimizers import Adam
from keras import initializers

os.environ["KERAS_BACKEND"] = "tensorflow"

np.random.seed(10)

random_dim = 100

def load_mnist_data():
    # load the data
    (x_train, y_train), (x_test, y_test) = mnist.load_data()
    # normalize our inputs to be in the range[-1, 1]
    x_train = (x_train.astype(np.float32) - 127.5)/127.5
    print(x_train.shape)
    # convert x_train with a shape of (60000, 28, 28) to (60000, 784) so we have
    # 784 columns per row
    x_train = x_train.reshape(60000, 784)
    return (x_train, y_train, x_test, y_test)


load_mnist_data()

下载到一半大约需要 30 分钟,并且在一段时间后(大约 5000000/11490434 和 6000000/11490434)它会崩溃并抛出此错误:

ConnectionResetError: [WinError 10054] Une connexion existsante a dû être fermée par l'hôte distance

(翻译)

现有连接已被远程主机关闭

这是什么原因造成的?用 keras 下载 mnist 数据需要一个小时,而我从 tensorflow 下载它只需要几分钟,这是否正常?

【问题讨论】:

    标签: python keras mnist


    【解决方案1】:

    我在评论中写下了我是如何解决问题的,但我想让它更清楚。

    仅当程序从空闲状态启动并且这是您第一次从 keras 导入 mnist 数据时才会出现问题。

    简单的解决方案是简单地从命令提示符下启动您的程序,似乎 idle 无法处理打印那么多东西,而在 idle 打印一些东西实际上会在短时间内停止您的程序,这可以解释荒谬的数量是时候下载了。

    TLDR:从命令提示符启动您的程序

    【讨论】:

      猜你喜欢
      • 2023-02-07
      • 2019-08-07
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 2018-06-22
      • 1970-01-01
      • 2014-12-05
      • 1970-01-01
      相关资源
      最近更新 更多