Tensorflow 实战 Google 深度学习框架(第2版)---- 10.3.1节 P278 代码

【信息科学与工程学】计算机科学与自动化—第十五篇 云计算 11 算法篇02 但若第一个应用需求40GB/s,第二个10GB/s,总需求50GB/s>40GB/s,第一个得32GB/s,第二个得8GB/s,不公平。但若分区负载不均(分区1-2各有100任务/s,分区3-4各有50任务/s),A负责1-2(200/s),B负责3-4(100/s),仍均衡。任务 τi​ 的计算需求 Wi​(CPU周期),在频率 f 下执行时间 Ti​=Wi​/f,能耗 Ei​=Pdyn​⋅Ti​=Ceff​⋅V2⋅f⋅(Wi​/f)=Ceff​⋅V2⋅Wi​。若 Mneed​>Mi​,需使用远程显存。 阅读详情
#-*-coding:utf-8-*-
import numpy as np
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data

tf.logging.set_verbosity(tf.logging.INFO)
mnist = input_data.read_data_sets('./mnist_data',one_hot = False)

feature_columns = [tf.feature_column.numeric_column('image',shape=[784])]

estimator = tf.estimator.DNNClassifier(
    feature_columns = feature_columns,
    hidden_units=[500],
    n_classes=10,
    optimizer=tf.train.AdamOptimizer(),
    model_dir = './mnist_data')

train_input_fn = tf.estimator.inputs.numpy_input_fn(
    x={'image':mnist.train.images},
    y=mnist.train.labels.astype(np.int32),
    num_epochs=None,
    batch_size=128,
    shuffle=True
)

estimator.train(input_fn=train_input_fn,steps=10000)

test_input_fn = tf.estimator.inputs.numpy_input_fn(
    x={'image':mnist.test.images},
    y=mnist.test.labels.astype(np.int32),
    num_epochs = 1,
    batch_size=128,
    shuffle=False)

accuracy_score = estimator.evaluate(input_fn=test_input_fn)['accuracy']
print('\nTest accuracy:%g %%'%(accuracy_score*100))

 

【信息科学与工程学】【数据科学】数据科学领域 第六篇 算法设计 07 堆、栈、表、矩阵、集合、队列、数组、字符串、树、图、动态规划、结构体、元组的算法01 当前段必须包含所有字符的最后出现位置。1. 字符串分割成最多片段2. 基因序列功能域划分3. 文本段落划分4. 音频声道分离5. 图像色彩分区6. 社交网络社群划分7. 蛋白质结构域8. 音乐乐章分段9. 代码模块划分10. 章节划分特征:一次扫描,贪心确定边界。 阅读详情

相关推荐

【信息科学与工程学】【运营科学】第二篇 C4信息与通信网络运营 (C4) ——数据中心网络运营06

13 | 司法诉讼 | 原告律师 | 争取和解优势 | 证据披露的序贯博弈 | 策略性证据释放 | 持有证据集E = {强证据e_s, 中证据e_m, 弱证据e_w}。设公众原有认知人格向量为 Pold​​=(p1​,p2​,...,pk​), 其中p_i为负面特质(如“不敬业”)。危机后, 通过行为序列 {At​}和宣传, 将公众认知向新向量 Pnew​​引导, 使得在关键维度上, Pnew​​与 Pold​​的余弦相似度降低, 并与一个正面的、可接受的“原型”(如“浪子回头”、“慈父”)对齐。

weixin_49199313的博客 1481

《Tensorflow 实战google深度学习框架》第二版 的 程序源代码存放地址

<<Tensorflow 实战google深度学习框架--第二版>> 源代码链接:书中代码存放地址:Github 代码要用到的数据链接:每章所需的数据集下载地址 

一滴水,一缕光 8129

从零开始玩转机械臂:用Matlab+Robotics Toolbox实现四自由度机械臂运动仿真

本文详细介绍了如何利用Matlab及其Robotics Toolbox工具箱,从零开始构建并仿真一个四自由度机械臂。通过D-H参数建模、正向运动学验证、交互式操控以及轨迹规划等实践步骤,帮助初学者在虚拟环境中直观理解机器人运动学核心概念,为后续硬件实现奠定坚实基础。

weixin_29055699的博客 325

说说TensorFlow实战Google深度学习框架

TensorFlow实战Google深度学习框架第一、二版pdf分享 事情是这样的,博主买了这本书,但是碍于想在电脑上边看边码,想找找PDF版本,然后各种百度,Google,百度网盘,最后找到的都是很多200M的,百度网盘分享的。 好不容易下载下来! 兴致勃勃的打开一看,文档都是加密的,压缩包也是加密的! 里面全是这个sb的: 对没错,为什么要骂人? 我辛辛苦苦下载,最后你告诉我,你收费?你加密...

空空说技术的博客 5055

Pytorch版deeplabv3+环境配置训练自己的数据集

参考:https://blog.csdn.net/qq_36766560/article/details/110009622?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522161594607816780266214828%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=161594607816780266214828

Ring__Rain的博客 1万+

告别乱码!手把手教你用docx4j实现Word转PDF(附完整中文字体配置)

本文详细介绍了如何使用纯Java库docx4j实现Word到PDF的精准转换,并重点解决了中文乱码这一核心痛点。文章提供了从环境搭建、核心代码实现到中文字体配置的完整教程,特别针对Linux服务器部署场景,给出了详细的字体安装与映射方案,确保跨平台转换的稳定性和准确性。

nokia的博客 1153

TensorFlow实战Google深度学习框架(第二版) ---- 学习代码

TensorFlow实战Google深度学习框架(第二版) ---- 学习代码

学无止境 1379

Qcom camera hal简介

Qcom camera hal简介

weixin_42136255的博客 7764

【TensorFlow】TensorFlow实战Google深度学习框架第2版参考代码(05-MNIST数字识别问题)

郑泽宇&梁博文&顾思宇著《TensorFlow实战Google深度学习框架(第2版)》第5章MNIST数字识别问题部分样例代码。

长相忆兮长相忆的专栏 213

MUSIC算法翻车?Toeplitz矩阵重构如何解决DOA估计中的相干信源难题

本文深入探讨了MUSIC算法在相干信源DOA估计中失效的根本原因,并详细介绍了基于Toeplitz矩阵重构的协方差矩阵修复技术。该方法通过凸优化恢复协方差矩阵的理想结构,有效解决了信号子空间秩亏损问题,从而显著提升了MUSIC算法在相干和多径场景下的分辨精度与稳健性。

a2b3c4d5e的博客 249

面向网络攻击行为可视化分析系统实现【WebSocket + 可视化】

本系统主要应用于网站运维管理,它解决了网站运维人员排查网络攻击行为复杂且繁琐等问题,提高了运维人员网络安全分析的效率和准确性。

oNew_Lifeo的博客 1620

学习《TensorFlow实战Google深度学习框架 (第2版) 》中文PDF和代码

TensorFlow是谷歌2015年开源的主流深度学习框架,目前已得到广泛应用。《TensorFlow:实战Google深度学习框架(第2版)》为TensorFlow入门参考书,帮助快速、有效的方式上手TensorFlow和深度学习。书中省略了烦琐的数学模型推导,从实际应用问题出发,通过具体的TensorFlow示例介绍如何使用深度学习解决实际问题。书中包含深度学习的入门知识和大量实践经验,是走进...

weixin_30814319的博客 1981

C#实现鼠标点击任意绝对位置(附完整源码)

C#实现鼠标点击任意绝对位置(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 476

tensorflow28《TensorFlow实战Google深度学习框架》笔记-10-05 同步更新模式样例程序 code

# 《TensorFlow实战Google深度学习框架》10 TensorBoard计算加速 # win10 Tensorflow1.0.1 python3.5.3 # CUDA v8.0 cudnn-8.0-windows10-x64-v5.1 # filename:ts10.05.py # 同步更新模式样例程序# coding=utf-8 import time import tensorflo

一朵花开的时间 1783

uniapp - 解决报错 canvasToTempFilePath: fail canvas is empty 画布为空错误,生成海报相册、二维码、条码、裁剪/拼合操作图片报错,加了this还是报错

uni-app,h5移动端网页,微信小程序,支付宝小程序,Android安卓,苹果ios,app,nvue,canvasToTempFilePath:失败画布为空,报错,canvasToTempFilePath:failcanvasisempty,不支持2d,还是报错,this,加上this还是报错,vue3没有this怎么办?海报,保存到手机相册,生成二维码,显示条码,图像裁切,图片处理,canvas报错,无法解决,还是fail,依然报错,传了this也不好使,Uniapp小程序,如何解决这个问题

🏆 前端领域优质创作者 4706

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

TensorFlow实战Google深度学习框架第二版学习总结-TensorFlow入门

本文内容主要针对第三章做知识总结 概述:TensorFlow的工作原理分为计算模型,数据模型和运行模型三部分。 1.TensorFlow计算模型-计算图 1.1计算图模型 tensorflow通过计算图的形式来表达计算的编程系统,其中那个tensorflow中的每一个计算都是计算图上的一个节点,而节点之间的边描述了计算之间的依赖关系。下图是典型的计算图模型 1.2计算图使用 ...

wangshuailpp的博客 3016

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

TensorFlow实战Google深度学习框架第二版学习总结-TensorFlow安装

安装方式主要分为两个版本,分别是CPU和GPU版本,CPU版本相对简单,而GPU版本过程较为复杂。如果只是新手使用tensorflow完全没必要装GPU版本,等你需要构建几十层网络的时候在安装GPU版本,同时GPU版本的安装每台电脑的情况不一样。 CPU版本主要参考: https://blog.csdn.net/colourful_sky/article/details/73823939 h...

wangshuailpp的博客 1251

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【TensorFlow】TensorFlow实战Google深度学习框架第2版参考代码(06-图像识别与卷积神经网络)

郑泽宇&梁博文&顾思宇著《TensorFlow实战Google深度学习框架(第2版)》第6章图像识别与卷积神经网络部分样例代码。

长相忆兮长相忆的专栏 462

Tensorflow 实战 Google 深度学习框架(第2版)---- 10.2.2节 P274 代码

#-*-coding:utf-8-*- import keras from tflearn.layers.core import fully_connected from keras.datasets import mnist from keras.layers import Input,Dense from keras.models import Model num_classes = 1...

wzg2016的博客 462

《Tensorflow 实战google深度学习框架》第二版源代码

&lt;&lt;Tensorflow 实战google深度学习框架–第二版&gt;&gt; 完整资料github地址: https://github.com/caicloud/tensorflow-tutorial 源代码链接: https://github.com/caicloud/tensorflow-tutorial/tree/master/Deep_Learning_with_Tensor...

Bowen Wang的博客 1030

tensorflow 中,修改张量tensor特定元素的值

tensorflow中:                    constant tensor不能直接赋值,否则会报错:                TypeError: 'Tensor' object does not support item assignment        Variable tensor不能为某个特定元素赋值,只能为整个变量tensor全部赋值。        ...

wzg2016的博客 2万+

卷积神经网络的卷积核的每个通道是否相同?

假设输入数据的格式是[?,28,28,16],卷积核的尺寸是[3,3,16,32] 输入数据的格式的含义是:                                                   ?:batchsize                                                   28,28:feature map单个通道的尺寸(高,宽) ...

wzg2016的博客 1万+

多层LSTM的坑:如何定义多层LSTM?

多层LSTM定义的两种方式,其中方式2是正确的,方式1挥出现错误: 多层LSTM需要每次都定义一个新的BasicCell, 而不是定义一个BasicCell之后多次调用。 def lstm_model(X,Y,is_training): ###方式1:错误!! #cell_unit = tf.nn.rnn_cell.BasicLSTMCell(HIDDEN_SIZ...

wzg2016的博客 1万+

tensorflow基础:tf.data.Dataset.from_tensor_slices()

tf.data.Dataset.from_tensor_slices() 语义解释:from_tensor_slices,从张量的切片读取数据。 工作原理:将输入的张量的第一个维度看做样本的个数,沿其第一个维度将tensor切片,得到的每个切片是一个样本数据。实现了输入张量的自动切片。 输入数据格式/要求: 1)可以是numpy格式,也可以是tensorflow的tenso...

wzg2016的博客 1万+
上一篇: Tensorflow 实战 Google 深度学习框架(第2版)---- 10.2.2节 P276 代码
下一篇: Tensorflow 实战 Google 深度学习框架(第2版)---- 10.3.2节 P280 代码
wzg2016
博客等级 码龄10年 539粉丝 493原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值