zoukankan      html  css  js  c++  java
  • 手写数字识别

    from keras.datasets import mnist
    from keras import models
    from keras import layers
    from keras.utils import to_categorical
    
    
    import numpy as np
    def loadData(path="mnist.npz"):
        f = np.load(path)
        x_train, y_train = f['x_train'], f['y_train']
        x_test, y_test = f['x_test'], f['y_test']
        f.close()
        return (x_train, y_train), (x_test, y_test)
    
    
    (train_images, train_lables),(test_images,test_labels) = loadData()
    
    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
    
    train_lables=to_categorical(train_lables)#对标签进行分类编码,one hot编码
    test_labels=to_categorical(test_labels)
    
    
    network.fit(train_images,train_lables, epochs=5,batch_size=128)

    出现了一个问题:https://blog.csdn.net/ouening/article/details/85065709

    后来发现是标签分类编码那里写错了。。

  • 相关阅读:
    2
    网络对抗第四次实验恶意代码
    网络对抗第三次实验
    网络对抗第二次实验
    网络攻防第一次实验
    123
    数据结构
    第五次实验
    第二次实验
    Qt应用笔记
  • 原文地址:https://www.cnblogs.com/h694879357/p/12566932.html
Copyright © 2011-2022 走看看