TensorFlow Seq2Seq Model笔记

TensorFlow中seq2seq库函数 1、seq2seq.py的两个重要的库函数1) outputs, states = basic_rnn_seq2seq(encoder_inputs, decoder_inputs, cell)输入参数 :encoder_inputs: 它是一个二维tensor构成的列表对象,其中每一个二维tensor代表某一时刻的输入,其尺寸为[batch_size x input_size],这里的batch_ 阅读详情

0. tf跑起来一直没有用GPU...

尴尬,跑起来发现GPU没用起来,CPU满了。发现装错了,应该装tensorflow-gpu。

代码测试是否用的是GPU:https://stackoverflow.com/questions/38009682/how-to-tell-if-tensorflow-is-using-gpu-acceleration-from-inside-python-shell


1. tf.app.run()的疑惑

    http://stackoverflow.com/questions/33703624/how-does-tf-app-run-work

    tf.app类似python中argparse


2. variable scope 和 name scope

Variable Scope mechanism: https://www.tensorflow.org/programmers_guide/variable_scope

http://stackoverflow.com/questions/35919020/whats-the-difference-of-name-scope-and-a-variable-scope-in-tensorflow


重点:Name scopes can be opened in addition to a variable scope, and then they will only affect the names of the ops, but not of variables. 

with tf.variable_scope("foo"):
    with tf.name_scope("bar"):
        v = tf.get_variable("v", [1])
        x = 1.0 + v
assert v.name == "foo/v:0"
assert x.op.name == "foo/bar/add"


scope.original_name_scope和scope.name的区别

http://stackoverflow.com/questions/41756054/tensorflow-variablescope-original-name-scope-vs-name


3. Python2 Python3区别
在修改data_utils.py(https://github.com/tensorflow/models/blob/master/tutorials/rnn/translate/data_utils.py)文件中:
没注意版本不同的区别,Python3语法中print语句没有了,取而代之的是print()函数。
另外 用python2执行时候:
with gfile.GFile(data_path, mode="rb") as f:
      counter = 0
      for line in f:


这里line里面含有'\n',用split切分后会和最后一个word组合一起读入list。出现list写到文件中和len(list)大小不一致。
比如 li=['a', 'b\n'] 写入文件。'\n'会换行,写的文件成为3行。
下次逐行读入时候会把空符号(‘’)计算为一个新word。


4. TensorFlow Saver类 https://www.tensorflow.org/api_docs/python/tf/train/Saver

http://blog.youkuaiyun.com/u011500062/article/details/51728830


5. Seq2Seq模型保存

其中保存的模型为:

translate.ckpt-16.data-00000-of-00001

translate.ckpt-16.index

translate.ckpt-16.meta

这些东西的解释见:

https://groups.google.com/a/tensorflow.org/forum/#!topic/discuss/Y4mzbDAUSec 

http://stackoverflow.com/questions/36195454/what-is-the-tensorflow-checkpoint-meta-file


6. RNN示例

https://uqer.io/community/share/58a9332bf1973300597ae209

http://r2rt.com/recurrent-neural-networks-in-tensorflow-ii.html


7. List of tensor to tensor

http://stackoverflow.com/questions/35730161/how-to-convert-a-list-of-tensors-of-dim-n-to-a-tensor-of-dim-n1

http://blog.youkuaiyun.com/sherry_up/article/details/52169318


8. batch_matmul问题

想进行的操作: suppose I have a T x n x k and want to multiply it by a k x k2, and then to a max pool overT and then a mean pool over n. To do this now, I think you need to reshape, do the matmul() and then undo the reshape and then do the pooling.

https://github.com/tensorflow/tensorflow/issues/216

https://www.tensorflow.org/versions/r0.10/api_docs/python/math_ops/matrix_math_functions#batch_matmul

使用时候报错:AttributeError: 'module' object has no attribute 'batch_matmul',才发现1.0版本中没有这个。需要用matmul加参数进行使用


9. Cannot feed value of shape (XX) for Tensor u'target/Y:0', which has shape '(YY)'?

第一次遇到这种问题,google后说是input feed的数据shape不一致。但出问题是第五个变量(mask5),导致自己以为不是input feed问题(如果是为什么会是第5个才出问题?)。瞎折腾好久后,发现还是输入数据时候的问题.....


10. 读取现有模型

之前一直可以读取指定目录下现有模型,后来发现读不了,折腾了几个小时才发现以前下面是有一个checkpoint文件,里面会告诉模型两个path:

model_checkpoint_path: "translate.ckpt-101000"
all_model_checkpoint_paths: "translate.ckpt-101000"


11. 读模型内的参数值

https://www.tensorflow.org/programmers_guide/variables#checkpoint_files:

When you create a Saver object, you can optionally choose names for the variables in the checkpoint files. By default, it uses the value of the tf.Variable.name property for each variable. 

To understand what variables are in a checkpoint, you can use the inspect_checkpoint library, and in particular, the print_tensors_in_checkpoint_file function.

*https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/inspect_checkpoint.py

用法:

python inspect_checkpoint.py  --file_name=./alpha_easy_nmt/valid_model/translate.ckpt-625000tensor

显示:

Decoder/trg_lookup_table/embedding (DT_FLOAT) [16000,620]
Decoder/trg_lookup_table/embedding/Adadelta (DT_FLOAT) [16000,620]
Decoder/trg_lookup_table/embedding/Adadelta_1 (DT_FLOAT) [16000,620]


用法:

python inspect_checkpoint.py  --file_name=./alpha_easy_nmt/valid_model/translate.ckpt-625000 --tensor_name=Decoder/W_sf 

显示:

tensor_name:  Decoder/W_sf
[[ -4.55709170e-07  -9.10816539e-07   4.44753543e-02 ...,  -2.58049741e-02
    4.26506670e-03  -3.64431571e-07]
 [  7.86067460e-07   7.86348721e-07   1.29140466e-02 ...,   7.92008177e-06
    5.49392325e-07   6.99410566e-06]
 [ -5.86683996e-07   5.51591484e-08   9.70983803e-02 ...,   2.75615434e-07
   -4.86231060e-04   1.23817983e-07]
 ...,
 [ -1.40239194e-06  -1.00237912e-06  -1.44313052e-01 ...,  -1.33047411e-06
   -1.17946070e-06  -2.41477892e-07]
 [  1.19242941e-06  -9.48488719e-08  -2.48298571e-02 ...,   1.00101170e-03
   -3.03782895e-03   1.45507602e-06]
 [ -1.27071712e-06  -1.27975386e-06  -2.31240150e-02 ...,  -7.33333752e-02
    2.30671745e-03  -5.72958811e-07]]


12. tf.get_variable的default initializer

https://www.tensorflow.org/api_docs/python/tf/get_variable:

If initializer is None (the default), the default initializer passed in the variable scope will be used. If that one is None too, a glorot_uniform_initializer will be used. The initializer can also be a Tensor, in which case the variable is initialized to this value and shape.

奇怪是glorot_uniform_initializer也差不到任何文档提及,github上倒是有人问过这个问题,不过没人回答https://github.com/tensorflow/tensorflow/issues/7791。


13. 系统记录

13.1 之前系统在NIST06上BLEU到20就停住了(theano版本和我师弟的版本都能到34)。beam search输出每一个beam,发现特别多的over translation问题。找了下发现自己系统出了一个小Bug,在beam search中忘记给source annotation加上mask。

Vocab = 16k,Batch = 50,两种优化算法每隔3000batch测一次BLEU。

Adam:

72000   BLEU score = 0.2412     BEST BLEU is 0
75000   BLEU score = 0.2377     BEST BLEU is 0.2412
78000   BLEU score = 0.2380     BEST BLEU is 0.2412
81000   BLEU score = 0.2513     BEST BLEU is 0.2412
84000   BLEU score = 0.2231     BEST BLEU is 0.2513
87000   
seq2seq_model.py AttributeError: 'NoneType' object has no attribute 'update' #### tensorflow/TensorFlow_seq2seq_tutorial-master/translate/translate.py的运行出现一下错误: AttributeError: 'NoneType' object has no attribute 'update' ``` Traceback (most recent call last):   File "/Us 阅读详情

相关推荐

如何搭建pikachu靶场

Pikachu靶场本地搭建指南 下载安装PHPStudy并启动Apache/MySQL服务 获取Pikachu靶场源码并解压到网站根目录 配置数据库连接信息(修改config.inc.php文件) 创建pikachu数据库(用户名/密码设为root) 访问http://localhost/pikachu测试功能 常见问题:数据库连接失败需检查服务状态和配置信息,页面报错需检查PHP版本兼容性。建议使用PHP7.3/7.4版本,在隔离环境中搭建使用。 (150字)

2401_85351702的博客 1276

安川机器人SOCKET 通讯

命令 功能 参数 示例 返回 SelectJob 选择程序 JobName LineNo SelectJob TEST 0 #SelectJob,Ok StartJob 启动程序 JobName StartJob TEST #StartJob,Ok Pause 暂停当前程序 - Pause #Pause,Ok Continue 继续当前程序 - Continue #Continue,Ok ServoOn 伺服上电 - ServoOn #ServoOn,Ok ServoOf...

记录学习内容 8285

别再模拟IIC了!用STM32F103C8T6的硬件IIC驱动AT24C64,CubeMX配置+避坑指南

本文详细介绍了如何使用STM32F103C8T6的硬件IIC驱动AT24C64 EEPROM,通过CubeMX配置和HAL库函数解析,提供从模拟IIC到硬件IIC的完整解决方案。内容包括硬件IIC与模拟IIC的核心差异、CubeMX工程配置详解、HAL库驱动实战以及典型问题诊断与优化,帮助开发者构建更稳定高效的存储系统。

weixin_27038245的博客 188

QMI8658姿态传感器实战:从校准到自检的完整避坑指南

本文详细解析了QMI8658姿态传感器的校准与自检流程,提供了从硬件环境搭建到高级功能开发的完整避坑指南。通过真实案例揭示电源设计、接口优化、温度补偿等关键细节,帮助开发者提升传感器精度和可靠性,适用于工业级应用场景。

weixin_29184075的博客 455

线阵相机标定必看:如何用Halcon实现亚毫米级精度测量(以HC050标定板为例)

本文以HC050标定板为例,详细阐述了如何利用Halcon实现线阵相机的高精度标定,以达到亚毫米级测量。文章深入剖析了线阵相机标定的核心原理、面临的独特挑战,并提供了从硬件搭建、图像采集到Halcon软件实操的完整路径,重点解析了运动参数设置、精度验证及常见问题排错,为精密测量应用提供系统解决方案。

weixin_29213655的博客 311

基于ZYNQ PL的AD7606数据采集与FFT实时频谱分析:从硬件到创新实现

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-kKnmpgJm-1750295287594)(https://example.com/fft_plot.png)]本文涉及代码已在Xilinx ZCU102开发板与AD7606评估板上验证通过,采样率支持200KSPS@8通道,FFT计算延迟<1ms。传统MCU+DSP方案难以兼顾速度与功耗,而ZYNQ的PL+PS架构为这一问题提供了完美解决方案。本文实现的ZYNQ PL方案突破了传统处理器的性能瓶颈,通过。

QQ_778132974的博客 338

手把手教你学simulink(24.4)--Simulink在机器人视觉场景下的应用——基于视觉的物体跟踪与抓取

该系统集成了图像处理、目标检测、运动估计、路径规划、抓取控制和视觉反馈等多个功能模块,能够实现实时处理视觉数据、检测并跟踪移动物体、规划最优路径并控制机械臂进行精确抓取。本项目的目标是使用Simulink和MATLAB设计一个基于视觉的物体跟踪与抓取系统,该系统能够实时处理图像数据,检测并跟踪移动物体,规划最优的抓取路径,并控制机械臂进行精确抓取。为了验证系统的性能,我们在Simulink中搭建了基于视觉的物体跟踪与抓取系统的仿真模型。

MHD0815的博客 256

增距镜或中继镜选型

增距镜光路图

camerall 5244

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

上一篇: TensorFlow1.0 运行报错 AttributeError: type object 'NewBase' has no attribute 'is_abstract'
下一篇: 组内NLP讨论班阶段总结
warrioR_wx
博客等级 码龄16年 388粉丝 113原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值