问题一:对特征归一化

Min-Max Scaling:
X′=a+(X−Xmin)(b−a)/(Xmax−Xmin)
# Problem 1 - Implement Min-Max scaling for grayscale image data
def normalize_grayscale(image_data):
"""
Normalize the image data with Min-Max scaling to a range of [0.1, 0.9]
:param image_data: The image data to be normalized
:return: Normalized image data
"""
# TODO: Implement Min-Max scaling for grayscale image data
a = 0.1
b = 0.9
grayscal_min=0
grayscal_max=255
return a + (((image_data-grayscal_min)*(b-a))/(grayscal_max-grayscal_min))

问题二:用 TensorFlow 创建特征、目标、权重和偏置项 tensor。

# All the pixels in the image (28 * 28 = 784)
features_count = 784
# All the labels
labels_count = 10 # TODO: Set the features and labels tensors
features = tf.placeholder(tf.float32)
labels = tf.placeholder(tf.float32) # TODO: Set the weights and biases tensors
weights = tf.Variable(tf.truncated_normal((features_count,labels_count))) biases = tf.Variable(tf.zeros(labels_count)) ### DON'T MODIFY ANYTHING BELOW ### #Test Cases
from tensorflow.python.ops.variables import Variable assert features._op.name.startswith('Placeholder'), 'features must be a placeholder'
assert labels._op.name.startswith('Placeholder'), 'labels must be a placeholder'
assert isinstance(weights, Variable), 'weights must be a TensorFlow variable'
assert isinstance(biases, Variable), 'biases must be a TensorFlow variable' assert features._shape == None or (\
features._shape.dims[0].value is None and\
features._shape.dims[1].value in [None, 784]), 'The shape of features is incorrect'
assert labels._shape == None or (\
labels._shape.dims[0].value is None and\
labels._shape.dims[1].value in [None, 10]), 'The shape of labels is incorrect'
assert weights._variable._shape == (784, 10), 'The shape of weights is incorrect'
assert biases._variable._shape == (10), 'The shape of biases is incorrect' assert features._dtype == tf.float32, 'features must be type float32'
assert labels._dtype == tf.float32, 'labels must be type float32' # Feed dicts for training, validation, and test session
train_feed_dict = {features: train_features, labels: train_labels}
valid_feed_dict = {features: valid_features, labels: valid_labels}
test_feed_dict = {features: test_features, labels: test_labels} # Linear Function WX + b
logits = tf.matmul(features, weights) + biases prediction = tf.nn.softmax(logits) # Cross entropy
cross_entropy = -tf.reduce_sum(labels * tf.log(prediction), reduction_indices=1) # Training loss
loss = tf.reduce_mean(cross_entropy) # Create an operation that initializes all variables
init = tf.global_variables_initializer() # Test Cases
with tf.Session() as session:
session.run(init)
session.run(loss, feed_dict=train_feed_dict)
session.run(loss, feed_dict=valid_feed_dict)
session.run(loss, feed_dict=test_feed_dict)
biases_data = session.run(biases) assert not np.count_nonzero(biases_data), 'biases must be zeros' print('Tests Passed!')

问题三:调整学习率,epochs 和 batch size 来获取最高准确率

tensorflow-解决3个问题的更多相关文章

  1. 深入浅出TensorFlow(二):TensorFlow解决MNIST问题入门

    2017年2月16日,Google正式对外发布Google TensorFlow 1.0版本,并保证本次的发布版本API接口完全满足生产环境稳定性要求.这是TensorFlow的一个重要里程碑,标志着 ...

  2. anaconda安装tensorflow报错 No module named 'tensorflow'解决方法(windows)

    这个错误的原因可能是,anaconda安装的python版本为3.7,现在tensorflow仅支持python 3.6   改变python版本:首先在命令行创建一个名为python36的环境,指定 ...

  3. 在jupyter notebook导入tensorflow出错:No module named tensorflow 解决办法

    1.背景 首先说一下我的环境: os : windows10 anaconda版本:2.7 官网提供了两种方法来安装TensorFlow:pip和anaconda.我使用的是anaconda方法.按照 ...

  4. 基于TensorFlow解决手写数字识别的Softmax方法、多层卷积网络方法和前馈神经网络方法

    一.基于TensorFlow的softmax回归模型解决手写字母识别问题 详细步骤如下: 1.加载MNIST数据: input_data.read_data_sets('MNIST_data',one ...

  5. 李宏毅 Tensorflow解决Fizz Buzz问题

    提出问题 一个网友的博客,记录他在一次面试时,碰到面试官要求他在白板上用TensorFlow写一个简单的网络实现异或(XOR)功能.这个本身并不难,单层感知器不能解决异或问题是学习神经网络中的一个常识 ...

  6. TensorFlow 解决“ImportError: Could not find 'cudnn64_6.dll'”

    解决“ImportError: Could not find 'cudnn64_6.dll'” 1. 问题描述 运行一个基于Tensorflow的代码时报错,如下所示: ImportError: Co ...

  7. Tensorflow 解决MNIST问题的重构程序

    分为三个文件:mnist_inference.py:定义前向传播的过程以及神经网络中的参数,抽象成为一个独立的库函数:mnist_train.py:定义神经网络的训练过程,在此过程中,每个一段时间保存 ...

  8. windows7 安装TensorFlow

    Win7 TensorFlow安装步骤: 1.安装python,参考http://www.zhimengzhe.com/windows/283058.html#0-tsina-1-12530-3972 ...

  9. TensorFlow.org教程笔记(一)Tensorflow初上手

    本文同时也发布在自建博客地址. 本文翻译自www.tensorflow.org的英文教程. 本文档介绍了TensorFlow编程环境,并向您展示了如何使用Tensorflow解决鸢尾花分类问题. 先决 ...

  10. Tensorflow object detection API ——环境搭建与测试

    1.开发环境搭建 ①.安装Anaconda 建议选择 Anaconda3-5.0.1 版本,已经集成大多数库,并将其作为默认python版本(3.6.3),配置好环境变量(Anaconda安装则已经配 ...

随机推荐

  1. 谈谈我对证券公司一些部门的理解(前、中、后台)[z]

    [z]https://blog.csdn.net/UniRong/article/details/79289947 文中对各大部门的分析都是从作者多年经历总结出来的有感之谈,尤其是前台的6大部门(经纪 ...

  2. linux备忘和卸载

    linux上网 -------------------------------------------------linux卸载------------------------------------ ...

  3. Cloudera Manager产品介绍

    一.Cloudera Manager简介 Cloudera Manager(后面简称CM)是CDH(Cloudera’s Distribution Including Apache Hadoop)市场 ...

  4. iOS创建带删除线和价钱符号的Label

    效果显示如下: 只需要子类化Label,重写DrawRect()方法即可: #import "MyLabel.h" @implementation MyLabel - (insta ...

  5. 抄录的Linux命令

    daemon daemon 有一个很高大上的中文名字,叫 守护进程 . 有句话是这么说的,如果 Unix 中没有了守护进程,那么 Unix 就不会是相同的. 它很有个性,是一个运行在后台且不受终端控制 ...

  6. 算法题--Z字形变换

    题目描述 将一个给定字符串根据给定的行数,以从上往下.从左到右进行 Z 字形排列. 比如输入字符串为 "LEETCODEISHIRING" 行数为 3 时,排列如下: L C I ...

  7. NDK学习笔记-JNI数据类型和属性方法的访问

    JNI实现了C/C++与Java的相互访问,那么这篇文章就从C/C++访问Java开始说起 native函数说明 每个native函数,都至少有两个参数(JNIEnv *和jclass或jobject ...

  8. spark 1.6.0 安装与配置(spark1.6.0、Ubuntu14.04、hadoop2.6.0、scala2.10.6、jdk1.7)

    前几天刚着实研究spark,spark安装与配置是入门的关键,本人也是根据网上各位大神的教程,尝试配置,发现版本对应最为关键.现将自己的安装与配置过程介绍如下,如有兴趣的同学可以尝试安装.所谓工欲善其 ...

  9. POJ1041 John's trip 【字典序输出欧拉回路】

    题目链接:http://poj.org/problem?id=1041 题目大意:给出一个连通图,判断是否存在欧拉回路,若存在输出一条字典序最小的路径. 我的想法: 1.一开始我是用结构体记录边的起点 ...

  10. 【转帖】知乎关于鸿蒙OS的思考

    作者:bacon xu链接:https://www.zhihu.com/question/339567108/answer/782431141来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非 ...