技术标签: Udacity 神经网络 TensorFlow
#NN with SGD, L2
batch_size = 128
layer_cnt = 6#层数
graph = tf.Graph()
with graph.as_default():
# Input data. For the training data, we use a placeholder that will be fed
# at run time with a training minibatch.
tf_train_dataset = tf.placeholder(tf.float32,
shape=(batch_size, image_size * image_size))
tf_train_labels = tf.placeholder(tf.float32, shape=(batch_size, num_labels))
tf_valid_dataset = tf.constant(valid_dataset)
tf_test_dataset = tf.constant(test_dataset)
# Variables.
weights = []
biases = []
hidden_cur_cnt = 784
for i in range(layer_cnt - 2):
if hidden_cur_cnt > 2:
hidden_next_cnt = int(hidden_cur_cnt / 2)
else:
hidden_next_cnt = 2
hidden_stddev = np.sqrt(2.0 / hidden_cur_cnt)
weights.append(tf.Variable(tf.truncated_normal([hidden_cur_cnt, hidden_next_cnt], stddev=hidden_stddev)))
biases.append(tf.Variable(tf.zeros([hidden_next_cnt])))
hidden_cur_cnt = hidden_next_cnt
weights.append(tf.Variable(tf.truncated_normal([hidden_cur_cnt, num_labels], stddev=hidden_stddev)))
biases.append(tf.Variable(tf.zeros([num_labels])))
# Training computation.
hidden_drop = tf_train_dataset
keep_prob = 0.5
for i in range(layer_cnt - 2):
y1 = tf.matmul(hidden_drop, weights[i]) + biases[i]
hidden_drop = tf.nn.relu(y1)
keep_prob += 0.5 * i / (layer_cnt + 1)
hidden_drop = tf.nn.dropout(hidden_drop, keep_prob)
z3 = tf.matmul(hidden_drop, weights[-1]) + biases[-1]
l2_loss = tf.Variable(0.0)
for wi in weights:
l2_loss += tf.nn.l2_loss(wi)
loss = tf.reduce_mean(
tf.add(
tf.nn.softmax_cross_entropy_with_logits(labels=tf_train_labels, logits=z3),0.001 * l2_loss) )
# Optimizer.
global_step = tf.Variable(0) # count the number of steps taken.
learning_rate = tf.train.exponential_decay(0.5, global_step, 1000, 0.9)
optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(loss, global_step=global_step)
# Predictions for the training, validation, and test data.
train_prediction = tf.nn.softmax(z3)
def predict(dataset):
hidden_drop = dataset
for i in range(layer_cnt - 2):
y1 = tf.matmul(hidden_drop, weights[i]) + biases[i]
hidden_drop = tf.nn.relu(y1)
result = tf.matmul(hidden_drop, weights[-1]) + biases[-1]
return result
valid_prediction = tf.nn.softmax(predict(tf_valid_dataset))
test_prediction = tf.nn.softmax(predict(tf_test_dataset))
num_steps = 20001
with tf.Session(graph=graph) as session:
tf.global_variables_initializer().run()
print("Initialized")
for step in range(num_steps):
# Pick an offset within the training data, which has been randomized.
# Note: we could use better randomization across epochs.
offset = (step * batch_size) % (train_labels.shape[0] - batch_size)
# Generate a minibatch.
batch_data = train_dataset[offset:(offset + batch_size), :]
batch_labels = train_labels[offset:(offset + batch_size), :]
# Prepare a dictionary telling the session where to feed the minibatch.
# The key of the dictionary is the placeholder node of the graph to be fed,
# and the value is the numpy array to feed to it.
feed_dict = {tf_train_dataset : batch_data, tf_train_labels : batch_labels}
_, l, predictions = session.run(
[optimizer, loss, train_prediction], feed_dict=feed_dict)
if (step % 500 == 0):
print("Minibatch loss at step %d: %f" % (step, l))
print("Minibatch accuracy: %.1f%%" % accuracy(predictions, batch_labels))
print("Validation accuracy: %.1f%%" % accuracy(
valid_prediction.eval(), valid_labels))
print("Test accuracy: %.1f%%" % accuracy(test_prediction.eval(), test_labels))
文章浏览阅读661次。在这里插入代码片```#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<string.h>#define Elemtype char#define Elemtype1 doubletypedef struct Node { Elemtype data; struct Node* pNext;}Node,*pNode;typedef struct S_c语言识别并计算四则混合运算,包括整数和小数
文章浏览阅读11次。点击下方卡片,关注「3D视觉工坊」公众号选择星标,干货第一时间送达来源:科研大匠添加小助理:dddvision,备注:方向+学校/公司+昵称,拉你入群。文末附行业细分群扫描下方二维码,加入3D视觉知识星球,星球内凝聚了众多3D视觉实战问题,以及各个模块的学习资料:近20门视频课程(星球成员免费学习)、最新顶会论文、计算机视觉书籍、优质3D视觉算法源码等。想要入门3D视觉、做项目、搞科研,欢迎扫码加...
文章浏览阅读1k次,点赞14次,收藏10次。“古剑山”第一届全国大学生网络攻防大赛初赛————(签到题)Misc | i have the flag_古剑山网络攻防大赛
文章浏览阅读562次,点赞25次,收藏10次。ubuntu安装mysql8.0
文章浏览阅读6.1k次,点赞2次,收藏31次。最近在做一个和手势识别相关的东西,了解到google的MediaPipe效果不错而且开源,想着学习一下,于是有了下文的安装, MediaPipe官网提供多种操作系统的安装方法,这里我选择ubuntu系统Ubuntu安装MediaPipegithub下载Meidapipe代码$ git clone https://github.com/google/mediapipe.git# Cha..._mdeiapipe ubuntu安装
文章浏览阅读2k次。OPPO Reno属于一款可以解锁BL的机型,也就是我们常说的深度测试,深度测试成功后就可以非常简单的去ROOT手机了,不会深度测试的看这里:深度测试教程深度测试名额有限,并且需满足一些条件才可以,我们建议用户申请深度测试有了深度测试后,就可以去刷TWRP_recovery了,ROM乐园教程区提供了丰富的TWRP,不少用户在成功刷入TWRP后,再刷入Magisk授权(也就是ROOT权限),再重启手..._oppo reno magisk
文章浏览阅读2.2k次,点赞72次,收藏24次。Node.js 是一个独立的 JavaScript 运行环境,能独立执行 JS 代码,因为这个特点,它可以用来编写服务器后端的应用程序Node.js 作用除了编写后端应用程序,也可以对前端代码进行压缩,转译,整合等等,提高前端开发和运行效率Node.js 基于Chrome V8 引擎封装,独立执行 JS 代码,但是语法和浏览器环境的 V8 有所不同,没有 document 和 window 但是都支持 ECMAScript 标准的代码语法模块化:Nodejs中,每个文件都是单独的模块。_nodejs和webpack
文章浏览阅读200次。(1)在DNS的管理器中添加主机名为adrms,IP为云5的IP(2)添加主机名为iscsi,IP为云5的IP(3)关闭网络掩码排序功能:DNS管理器-DS-属性-高级-取消“启用网络掩码排序”-确定(4)设置DNS服务正向区域和反向区域与活动目录集成:在云1里面添加反
文章浏览阅读1.1w次,点赞4次,收藏28次。Eclipse里面找不到DatabaseExplorer?解决方案:追根溯源我的不是J2EE版本,根本没有window==>show view==>Other==>Data Management的Data Management.因此需要安装Database的插件,过程为:(1)Help==>Install New Software==>Other==>Data Management==>Dat_eclipse没有database
文章浏览阅读770次。按照官网步骤安装引入使用配置autoplay: true,后发现配置无效,查了无数文档后,终于发现是swiper版本问题swiper版本从7.x降到了5.x:配置写法:[email protected] 无法进行轮播
文章浏览阅读154次。(1)使用异或可简单加密数据,解密时使用加密后的数据与密钥重做一次异或运算即可。(2)由于某些操作系统不能正确处理非打印字符,因此,对于此类字符可采取原有不做加密。#include <stdio.h>#include <ctype.h>#define KEY 'z'int main(void){ char orig_char..._对数据,进行异或加密(应付苹果审核)
文章浏览阅读2.2k次。场景 失焦的时候关闭 选择列表 但是同时 点击列表的时候会触发 bulr 事件 然后 click事件失效解决办法 click 换 mousedown ( tips:事件优先执行顺序 mousedown > bulr > click)如果是移动端 同理 touchstart > bulr > touch..._vant swipe 点击和触摸冲突