# -*- coding: utf-8 -*-
"""
author:菜根言
date:2018-10-08
A deep MNIST classifier using convolutional layers.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
#导入所需要的Python库以及tensorflow
from keras.datasets import mnist
from tensorflow import keras as keras
import tensorflow as tf
import numpy as np
from PIL import Image
# Import data
(train_x, train_y), (label_x,label_y) = mnist.load_data()
train_x = train_x.reshape(-1,784)
label_x = label_x.reshape(-1,784)
# # #标签更改为one_hot形式
# train_y = keras.utils.to_categorical(train_y)
# label_y = keras.utils.to_categorical(label_y)
#设置超参数
keep_rate = 0.5
batch_size = 6
board_location = 'logs/'
SESS_PATH = 'model/deepnn.ckpt'
#定义深度卷积神经网络模型
def deepnn(x):
# Reshape to use within a convolutional neural net.
x_image = tf.reshape(x, [-1, 28, 28, 1])
# First convolutional layer - maps one grayscale image to 32 feature maps.
W_conv1 = weight_variable([5, 5, 1, 32])#5x5,输入1channel,输出32channel
b_conv1 = bias_variable([32])
h_conv1 =