卷积神经网络的Helloworld例子

马克-to-win @ 马克java社区:防盗版实名手机尾号:73203。下面是keras官方的卷积神经网络在github上的例子。和原版的唯一区别是:mnist的数据因为在国外(由于FQ的原因,报错Exception: URL fetch failure on https://s3.amazonaws.com/img-datasets/mnist.npz),可以像我一样,下载数据后,放在本地。

batch_size = 128
num_classes = 10
epochs = 12

# input image dimensions
img_rows, img_cols = 28, 28

# the data, split between train and test sets
#(x_train, y_train), (x_test, y_test) = mnist.load_data()
#把原版的网上的数据下载到本地
path='D://tmp//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()

if K.image_data_format() == 'channels_first':
    x_train = x_train.reshape(x_train.shape[0], 1, img_rows, img_cols)
    x_test = x_test.reshape(x_test.shape[0], 1, img_rows, img_cols)
    input_shape = (1, img_rows, img_cols)
else:
    x_train = x_train.reshape(x_train.shape[0], img_rows, img_cols, 1)
    x_test = x_test.reshape(x_test.shape[0], img_rows, img_cols, 1)

更多内容请见原文,文章转载自:https://blog.csdn.net/qq_43650923/article/details/100739553

posted @ 2021-10-24 09:53  小龙虾1  阅读(62)  评论(0)    收藏  举报