TensorFlow_MNIST 保存、恢复模型及参数

本文档展示了如何使用TensorFlow训练MNIST数据集,并详细说明了模型及其参数的保存和恢复过程。在Windows环境下,通过Python3.5和TensorFlow 1.2.1实现网络定义,训练后保存模型文件。恢复模型后进行测试,由于训练迭代次数有限,测试准确率较低。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

内容:使用TensorFlow跑MNIST,并保存模型。之后恢复模型并进行测试
配置:win7x64/PyCharm/Python3.5/tensorflow-1.2.1/dataSet-MNIST
原程序:https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/tutorials/mnist
这里写图片描述

1.网络定义

def deepnn(x):
  """deepnn builds the graph for a deep net for classifying digits.

  Args:
    x: an input tensor with the dimensions (N_examples, 784), where 784 is the
    number of pixels in a standard MNIST image.

  Returns:
    A tuple (y, keep_prob). y is a tensor of shape (N_examples, 10), with values
    equal to the logits of classifying the digit into one of 10 classes (the
    digits 0-9). keep_prob is a scalar placeholder for the probability of
    dropout.
  """
  # Reshape to use within a convolutional neural net.
  # Last dimension is for "features" - there is only one here, since images are
  # grayscale -- it would be 3 for an RGB image, 4 for RGBA, etc.
  with tf.name_scope('reshape'):
    x_image = tf.reshape(x, [-1, 28, 28, 1])   # [batch,height,width,channels]

  # First convolutional layer - maps one grayscale image to 32 feature maps.
  with tf.name_scope('conv1'):
    W_conv1 = weight_variable([5, 5, 1, 32])   # shape of weight  [conv_W,conv_H,channal_before_conv,channal_after_conv]
    b_conv1 = bias_variable([32])
    h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)

  # Pooling layer - downsamples by 2X.
  with tf.name_scope('pool1'):
    h_pool1 = max_pool_2x2(h_conv1)

  # Second convolutional layer -- maps 32 feature maps to 64.
  with t
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值