zoukankan      html  css  js  c++  java
  • keras加载mnist数据集

    from keras.datasets import mnist
    (train_images,train_labels),(test_images,test_labels)=mnist.load_data()

    此处会报 SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed 错误

    通过下面命令解决

    > cd "/Applications/Python 3.7/"
    > sudo "./Install Certificates.command"

     载入并训练数据集

    from keras.datasets import mnist
    
    (train_images,train_labels),(test_images,test_labels)=mnist.load_data()
    
    from keras import models
    from keras import layers
    network = models.Sequential()
    
    #准备网络
    network.add(layers.Dense(512,activation='relu',input_shape=(28*28,)))
    network.add(layers.Dense(10,activation='softmax'))
    network.compile(optimizer='rmsprop',loss='categorical_crossentropy',metrics=['accuracy'])
    
    #准备图像数据
    train_images = train_images.reshape((60000,28*28))
    train_images = train_images.astype('float32') /255
    
    test_images = test_images.reshape((10000,28*28))
    test_images = test_images.astype('float32') /255
    
    #准备标签
    from keras.utils import to_categorical
    train_labels = to_categorical(train_labels)
    test_labels = to_categorical(test_labels)
    
    #训练数据
    network.fit(train_images,train_labels,epochs=5,batch_size=128)
    
    # 测试性能
    test_loss,test_acc = network.evaluate(test_images,test_labels)
    print('test_acc:',test_acc)
  • 相关阅读:
    linux 学习(二)防火墙
    linux学习(一)开始
    ajax和sap以及网络安全
    仿苹果导航菜单js问题
    基本类型和引用类型调用是的区别(Object.create)
    箴言
    思维的宽度
    笔记
    循环传值_闭包
    一个问题的解法(兔子三个月之后每月都生兔子的问题)
  • 原文地址:https://www.cnblogs.com/Erick-L/p/12686645.html
Copyright © 2011-2022 走看看