问题一:对特征归一化

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 来获取最高准确率

最新文章

  1. 【Django】--Models 和ORM以及admin配置
  2. WKWebview 拼接tableview,获取web内容高度
  3. C#中的问号
  4. 13.Xcode开发的快捷键
  5. angularjs 自带的过滤器
  6. overfitting过拟合
  7. yii框架部署
  8. HTML5标签学习之~~~
  9. Hdu 1506 Largest Rectangle in a Histogram 分类: Brush Mode 2014-10-28 19:16 93人阅读 评论(0) 收藏
  10. CF 19D - Points 线段树套平衡树
  11. https证书申请
  12. 基于物联网操作系统HelloX的智慧家庭体系架构
  13. HDU 2266 How Many Equations Can You Find(DFS)
  14. 重载(overload),覆盖/重写(override),隐藏(hide)
  15. (大数据工程师学习路径)第一步 Linux 基础入门----数据流重定向
  16. jquery easyui的datagrid在初始化的时候会请求两次URL?
  17. noip普及组2004 FBI树
  18. 使用Entity Framework Core访问数据库(Oracle篇)
  19. Qt如何去掉按钮等控件的虚线框(焦点框)
  20. POJ 1067 威佐夫博弈

热门文章

  1. 使用LuceneUtil工具类,完成CURD操作
  2. openstack部署nova
  3. delphi循环校验数据集
  4. Java日志体系(二)log4j
  5. android#使用Intent传递对象
  6. server 2008 R2 DHCP服务器部署
  7. php 解决跨域问题
  8. TestNG使用教程详解(接口测试用例编写与断言)
  9. ARST第二周打卡
  10. linux的安装和配置