tensorflow的helloworld

安装

easy_install pip

virtualenv tensorenv
source bin/activate
#pip install tensorflow
#pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl
#easy_install --upgrade six
#pip install --upgrade pip
#pip install six
#pip install matplotlib


pip install --upgrade tensorflow



helloworld

(tensorflow)$ cd tensorflow/models/image/mnist
(tensorflow)$ python convolutional.py

>>> import tensorflow as tf
>>> hello = tf.constant('hello TensorFlow!')
>>> sess = tf.Session()
>>> print sess.run(hello)
hello TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print sess.run(a+b)
42



cd tensorenv/lib/python2.7/site-packages/tensorflow/models/image/mnist

python convolutional.py


基本概念
[url]https://blog.youkuaiyun.com/ls617386/article/details/60572770[/url]

基本用法
[url]http://wiki.jikexueyuan.com/project/tensorflow-zh/get_started/basic_usage.html[/url]


deepspeaker
gmm
Kaldi
Caffe

测试集的使用

下载MNIST训练集
[url]http://wiki.jikexueyuan.com/project/tensorflow-zh/tutorials/mnist_beginners.html[/url]


gzip -d * 解压四个文件
安装生成图片的必要的库


yum install libpng-devel freetype-devel -y
pip install matplotlib


xxd t10k-images-idx3-ubyte |less

hexdump t10k-images-idx3-ubyte |less

yum install libjpeg
yum install libjpeg-devel -y


pip install pillow

把数据生成图片
参考
[url]https://blog.youkuaiyun.com/u010194274/article/details/50817999[/url]
# 
encoding: utf-8
import struct
import numpy as np
import matplotlib.pyplot as plt
#import Image
from PIL import Image
#二进制的形式读入
filename='./MNIST_data_back/train-images-idx3-ubyte'
binfile=open(filename,'rb')
buf=binfile.read()
#大端法读入4个unsigned int32
#struct用法参见网站 http://www.cnblogs.com/gala/archive/2011/09/22/2184801.html

index=0
magic,numImages,numRows,numColumns=struct.unpack_from('>IIII',buf,index)
index+=struct.calcsize('>IIII')
#将每张图片按照格式存储到对应位置
for image in range(0,numImages):
im=struct.unpack_from('>784B',buf,index)
index+=struct.calcsize('>784B')
#这里注意 Image对象的dtype是uint8,需要转换
im=np.array(im,dtype='uint8')
im=im.reshape(28,28)
# fig=plt.figure()
# plotwindow=fig.add_subplot(111)
# plt.imshow(im,cmap='gray')
# plt.show()
im=Image.fromarray(im)
im.save('train/train_%s.bmp'%image,'bmp')



[img]http://dl2.iteye.com/upload/attachment/0129/9628/bda61707-49ed-3146-bfee-ccd8d0849a95.png[/img]


如果是解析
参考[url]https://www.jianshu.com/p/84f72791806f[/url]

# encoding: utf-8
"""
@author: monitor1379
@contact: yy4f5da2@hotmail.com
@site: www.monitor1379.com

@version: 1.0
@license: Apache Licence
@file: mnist_decoder.py
@time: 2016/8/16 20:03

对MNIST手写数字数据文件转换为bmp图片文件格式。
数据集下载地址为http://yann.lecun.com/exdb/mnist。
相关格式转换见官网以及代码注释。

========================
关于IDX文件格式的解析规则:
========================
THE IDX FILE FORMAT

the IDX file format is a simple format for vectors and multidimensional matrices of various numerical types.
The basic format is

magic number
size in dimension 0
size in dimension 1
size in dimension 2
.....
size in dimension N
data

The magic number is an integer (MSB first). The first 2 bytes are always 0.

The third byte codes the type of the data:
0x08: unsigned byte
0x09: signed byte
0x0B: short (2 bytes)
0x0C: int (4 bytes)
0x0D: float (4 bytes)
0x0E: double (8 bytes)

The 4-th byte codes the number of dimensions of the vector/matrix: 1 for vectors, 2 for matrices....

The sizes in each dimension are 4-byte integers (MSB first, high endian, like in most non-Intel processors).

The data is stored like in a C array, i.e. the index in the last dimension changes the fastest.
"""

import numpy as np
import struct
import matplotlib.pyplot as plt

# 训练集文件
train_images_idx3_ubyte_file = './MNIST_data_back/train-images-idx3-ubyte'
# 训练集标签文件
train_labels_idx1_ubyte_file = './MNIST_data_back/train-labels-idx1-ubyte'

# 测试集文件
test_images_idx3_ubyte_file = './MNIST_data_back/t10k-images-idx3-ubyte'
# 测试集标签文件
test_labels_idx1_ubyte_file = './MNIST_data_back/t10k-labels-idx1-ubyte'


def decode_idx3_ubyte(idx3_ubyte_file):
"""
解析idx3文件的通用函数
:param idx3_ubyte_file: idx3文件路径
:return: 数据集
"""
# 读取二进制数据
bin_data = open(idx3_ubyte_file, 'rb').read()

# 解析文件头信息,依次为魔数、图片数量、每张图片高、每张图片宽
offset = 0
fmt_header = '>iiii'
magic_number, num_images, num_rows, num_cols = struct.unpack_from(fmt_header, bin_data, offset)
print '魔数:%d, 图片数量: %d张, 图片大小: %d*%d' % (magic_number, num_images, num_rows, num_cols)

# 解析数据集
image_size = num_rows * num_cols
offset += struct.calcsize(fmt_header)
fmt_image = '>' + str(image_size) + 'B'
images = np.empty((num_images, num_rows, num_cols))
for i in range(num_images):
if (i + 1) % 10000 == 0:
print '已解析 %d' % (i + 1) + '张'
images[i] = np.array(struct.unpack_from(fmt_image, bin_data, offset)).reshape((num_rows, num_cols))
offset += struct.calcsize(fmt_image)
return images


def decode_idx1_ubyte(idx1_ubyte_file):
"""
解析idx1文件的通用函数
:param idx1_ubyte_file: idx1文件路径
:return: 数据集
"""
# 读取二进制数据
bin_data = open(idx1_ubyte_file, 'rb').read()

# 解析文件头信息,依次为魔数和标签数
offset = 0
fmt_header = '>ii'
magic_number, num_images = struct.unpack_from(fmt_header, bin_data, offset)
print '魔数:%d, 图片数量: %d张' % (magic_number, num_images)

# 解析数据集
offset += struct.calcsize(fmt_header)
fmt_image = '>B'
labels = np.empty(num_images)
for i in range(num_images):
if (i + 1) % 10000 == 0:
print '已解析 %d' % (i + 1) + '张'
labels[i] = struct.unpack_from(fmt_image, bin_data, offset)[0]
offset += struct.calcsize(fmt_image)
return labels


def load_train_images(idx_ubyte_file=train_images_idx3_ubyte_file):
"""
TRAINING SET IMAGE FILE (train-images-idx3-ubyte):
[offset] [type] [value] [description]
0000 32 bit integer 0x00000803(2051) magic number
0004 32 bit integer 60000 number of images
0008 32 bit integer 28 number of rows
0012 32 bit integer 28 number of columns
0016 unsigned byte ?? pixel
0017 unsigned byte ?? pixel
........
xxxx unsigned byte ?? pixel
Pixels are organized row-wise. Pixel values are 0 to 255. 0 means background (white), 255 means foreground (black).

:param idx_ubyte_file: idx文件路径
:return: n*row*col维np.array对象,n为图片数量
"""
return decode_idx3_ubyte(idx_ubyte_file)


def load_train_labels(idx_ubyte_file=train_labels_idx1_ubyte_file):
"""
TRAINING SET LABEL FILE (train-labels-idx1-ubyte):
[offset] [type] [value] [description]
0000 32 bit integer 0x00000801(2049) magic number (MSB first)
0004 32 bit integer 60000 number of items
0008 unsigned byte ?? label
0009 unsigned byte ?? label
........
xxxx unsigned byte ?? label
The labels values are 0 to 9.

:param idx_ubyte_file: idx文件路径
:return: n*1维np.array对象,n为图片数量
"""
return decode_idx1_ubyte(idx_ubyte_file)


def load_test_images(idx_ubyte_file=test_images_idx3_ubyte_file):
"""
TEST SET IMAGE FILE (t10k-images-idx3-ubyte):
[offset] [type] [value] [description]
0000 32 bit integer 0x00000803(2051) magic number
0004 32 bit integer 10000 number of images
0008 32 bit integer 28 number of rows
0012 32 bit integer 28 number of columns
0016 unsigned byte ?? pixel
0017 unsigned byte ?? pixel
........
xxxx unsigned byte ?? pixel
Pixels are organized row-wise. Pixel values are 0 to 255. 0 means background (white), 255 means foreground (black).

:param idx_ubyte_file: idx文件路径
:return: n*row*col维np.array对象,n为图片数量
"""
return decode_idx3_ubyte(idx_ubyte_file)


def load_test_labels(idx_ubyte_file=test_labels_idx1_ubyte_file):
"""
TEST SET LABEL FILE (t10k-labels-idx1-ubyte):
[offset] [type] [value] [description]
0000 32 bit integer 0x00000801(2049) magic number (MSB first)
0004 32 bit integer 10000 number of items
0008 unsigned byte ?? label
0009 unsigned byte ?? label
........
xxxx unsigned byte ?? label
The labels values are 0 to 9.

:param idx_ubyte_file: idx文件路径
:return: n*1维np.array对象,n为图片数量
"""
return decode_idx1_ubyte(idx_ubyte_file)


def run():
train_images = load_train_images()
train_labels = load_train_labels()
# test_images = load_test_images()
# test_labels = load_test_labels()

# 查看前十个数据及其标签以读取是否正确
for i in range(10):
print train_labels[i]
plt.imshow(train_images[i], cmap='gray')
plt.show()
print 'done'

if __name__ == '__main__':
run()
小白上手tensorflow helloworld 全宇宙最白的小白 上手tensorflow 刚刚从菜鸟上看了python语法,用import < 包名模块名 >来导入模块,*就是包的模块全导入。 tensorflow是啥 是个python包。 嗯,没毛病…… 导入…… 然后就不会了 #!/usr/bin/env python # -*- coding: utf-8 -*- import tensorflow as tf 不会没关系,代码打一半就会出现提示。 不光有提示,还有示例。 上手深度学习很多不免一篇茫然,tensorflow 阅读详情

相关推荐

Live2D虚拟主播整活:用VTS挂件轻松实现捂脸大哭

在虚拟主播(VUP)直播中,Live2D技术是驱动角色生动表现的核心引擎。通过Cubism制作的角色模型,配合VTube Studio(VTS)的面部捕捉与挂件机制,主播可以灵活地在模型之上叠加独立动画层,实现快速出现、消失的“整活”效果。挂件不仅独立于模型文件,还能与表情参数绑定,实现联动反馈。这种技术方案成本低、改动小,非常适合在直播中制造戏剧化名场面。从静态透明PNG到序列帧,从热键触发到OBS画面合成,挂件玩法可以覆盖捂脸大哭、流泪特效、头顶字幕等丰富场景。本文以“捂脸大哭”为主线,梳理从模型准备、

weixin_33922670的博客 365

ESP32 & Tensorflow Lite (二)TensorFlow Lite Hello World

这篇文章将介绍使用 TensorFlow Lite for Microcontrollers 的基础知识。它包括训练模型,将其转换为 TensorFlow Lite 版本使用以及在微控制器上运行的完整的端到端工作流程。

InfiniteYuan 5428

tensorflow_helloworld_demo.py例子

官方例子,深度学习专用,机器学习专用,代码简单,一看就会(tensorflow helloworld demo)

TensorFlow :HelloWorld

1、TensorFlow简介    &gt;使用计算图 (graph) 来表示计算任务.    &gt;在被称之为会话 (Session) 的上下文 (context) 中执行图.    &gt;使用 tensor 表示数据.    &gt;通过变量 (Variable) 维护状态.    &gt;使用feed和fetch可以为任意的操作(arbitrary operation) 赋值或者从其中获...

蓬莱道人的博客 1524

Unity 升级 xLua 版本,编译不同平台链接库

Unity 升级 xLua 详解

LymanCao的专栏 1801

【Creo】关于Creo一换网络就报错许可证丢失问题解决方案

依照我的个人理解,Creo只要一更换网络,则其许可证里面的网卡参数和现在的网络就对不上了,所以就会出现报错,并且有可能是报错代码(-9),提示许可证激活有问题。

weixin_52002180的博客 6036

Tensorflow入门之 Hello World

Tensorflow入门之 Hello World

R先生专栏 2万+

【读代码】深入解析Ragas:RAG应用效果评估最好的工具

Ragas是由Exploding Gradients团队开发的专业LLM应用评估框架,通过自动化测试和量化指标帮助开发者构建可靠的AI系统。# 典型架构模块 ├── metrics # 50+评估指标实现 ├── testset # 测试集生成系统 ├── embeddings # 多模态嵌入支持 ├── integrations # 主流框架集成 ├── optimizers # 遗传算法优化器 └── experimental # 前沿功能实验区。

kakaZhui的博客 850

tensorflow入门案例手写数字识别人工智能界的helloworld项目落地1

数据集市28*28单通道灰度图像])

AnalogElectronic的博客 1037

Android PMS——概述(一)

PMS(Package Manager Service)是 Android 操作系统的一个重要组件,它负责管理应用程序的包信息以及与应用程序的安装、卸载、权限控制等相关功能,确保应用程序的安全性和稳定性。 Android PMS 负责维护一个应用程序包的清单信息,该清单是一个 XML 文件,包含应用程序的各种元数据,例如应用程序的包名、版本号、权限要求、组件信息等。PMS通过访问该清单文件来获取应用程序的信息。 此外,Android PMS 还负责应用程序的安装和卸载。在安装应用

小旭的专栏 1667

一分钟了解 “提示词工程”、“上下文工程”、“驾驭工程”

在大模型刚刚进入大众视野的初期,开发者面临的最大挑战是如何让模型听懂人类的指令。这一阶段被称为提示词工程时代。其核心思想非常直观:通过精心设计输入的文本提示,引导模型输出符合预期的结果。这一时期的开发者更像是“提示词巫师”,他们热衷于寻找所谓的“魔法咒语”。典型的技巧包括角色设定、思维链、少样本学习以及输出格式约束。例如,仅仅在问题前加上一句“请一步步思考”,模型的推理能力往往就能得到显著提升。然而,随着应用场景的复杂化,提示词工程的局限性逐渐暴露。

h a 6 6 6 c k 为 你解决复杂难题! 568

使用TensorFlow完成HelloWorld

使用TensorFlow完成HelloWorld1.安装python和TensorFlow 2.完成helloworld案例 首先,安装python环境也是很简单的,直接上网址,选择合适的版本,我这里选择的是3.5.2版本,安装直接选择exe文件安装,Windows x86-64 executable installer我是Windows环境,如果是其他os可以选择对应的版本,安装的时候注意在界面选

叶初阳 3077

视觉Transformer实战 | Token-to-Token Vision Transformer(T2T-ViT)详解与实现

Vision Transformer (ViT) 在计算机视觉领域取得了巨大成功,但标准的 ViT 存在一些局限性,如需要大规模预训练数据、对局部结构建模不足等。Token-to-Token ViT (T2T-ViT) 通过引入渐进式分词过程改进了原始 ViT,使其能够在中小型数据集上取得更好的性能。本节将详细介绍 T2T-ViT 的技术原理,并使用 PyTorch 从零开始实现 T2T-ViT。

盼小辉丶的博客 4万+

TensorFlow-Examples - helloworld.py

TensorFlow-Examples - helloworld.py 1. helloworld.py #!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import absolute_import from __future__ import division from __future__ import print_function ''' HelloWorld example using TensorFlow librar

程永强 602

MFC Windows 程序设计[122]之树形下拉列表框(附源码)

MFC是微软公司提供的一个类库(class libraries),用以减少应用程序开发人员的工作量。其中包含大量Windows句柄封装类和很多Windows的内建控件和组件的封装类。有很多初学MFC的小伙伴们都觉得MFC比较难学,看书吧,看了就忘了,网上的一些教程又是写的含糊不清,故而学习起来很吃力...... 故此,本专栏亲自研究,实践,由易到难,层层深入,将调试过程中所遭所遇进行详细讲解,注意事项进行一一列举,希望能够帮助到各位初学MFC的小伙伴,避免走弯路,费时费力。.........

hnjzfwy的博客 458

深度学习论文: Cultivated Land Extraction from High-Resolution Remote Sensing Image

深度学习论文: Cultivated Land Extraction from High-Resolution Remote Sensing Image The Winning Solution to the iFLYTEK Challenge 2021 Cultivated Land Extraction from High-Resolution Remote Sensing Image PDF: https://arxiv.org/pdf/2202.10974.pdf PyTorch代码: https:

mingo_敏 3480

tensorflow之helloworld

学习tfmnist手写字体识别tensorflow实现softmax regression识别手写数字 mnist手写字体识别 注:官方源代码在www.broadview.com.cn,我现阶段的学习方式是复现效果,过程中解决问题加深理解,经典代码段进行反复直到熟记。 tensorflow实现softmax regression识别手写数字 一边看tf实战书,一边跑3_2_helloworld代码...

for happy の road 522

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

win10 安装 tensorflow 并运行helloworld

win10 安装 tensorflow 并运行helloworld   折腾了一下,在win10上成功安装tensorflow. 1 下载安装python,注意一定要是64位(比如python-3.5.1-amd64)的,建议直接下载.exe版本的,在安装的时候选择添加环境变量; 2 下载最新的 tensorflow-1.1.0rc0-cp35-cp35m-win_amd64.whl 包;...

weixin_33860553的博客 139

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

tensorFlow Helloworld

import tensorflow as tf matrix1 = tf.constant([[3., 3.]]) matrix2 = tf.constant([[2.], [2.]]) product = tf.matmul(matrix1, matrix2) sess = tf.Session() result = sess.run(product) print (result) ses

huaweitman的专栏 5258

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

TensorFlow 实现Helloworld

import tensorflow as tf hello = tf.constant('hello, tensorflow!') with tf.Session() as sess: print(sess.run(hello)) 张量、变量、会话 什么是计算图,tensorboard查看计算图 计算图采用nodes和edges的有向图来描述数据流和计算,node代表...

538

TensorFlow下的HelloWorld(一)

这一节我们使用TensorFlow来实战,使用它进行简单的线性模型的预测。 线性模型预测 假如现在有一组数据,反应的是一个人在某个时刻,走的总路程的关系。数据放在excel表里,数据如下: 现在要求我们用一个函数表达式来拟合这个人在任一时刻,他走的路程和时间的关系。按照传统的方法,我们会去画出这个人的时间和路程图像,图像如下: 从图里,我们可以很明显的看出,这个函数是个线性函数,符合y=kx+b的线性函数。因此代入2个点,就可以求解出k和b两个值,得到y=2x+30 ,整个过程,我们是通过人类归纳的数学

laigengsong的博客 409

tensorflow 的HelloWorld模型

第一步,训练并保存模型:saver_hello.py内容如下import tensorflow as tfdef helloFunc():    print("hellFunc")if __name__ == '__main__':    hello = tf.Variable(tf.constant('Hello World', name = "hello"))    #init = tf.in...

zmlovelx(帅得不敢出门 程序员群31843264) 591

TensorFlow 从零到helloWorld

TensorFlow 从零到helloWorld 目录 1.git安装与使用 1.1 git安装 1.2 修改git bash默认路径 1.3 git常用操作 2.环境搭建   2.1 tensorflow安装   2.2 CUDA安装   2.3 CuDNN安装 3.测试 3.1 helloword测...

u013165852的博客 156
上一篇: nginx push_upstream模块的websocket
下一篇: tensorflow模拟仿真
linux内核控
博客等级 码龄19年 41粉丝 638原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值