tensorflow的tile使用
当你需要按照矩阵维度复制数据时候,可以使用tensorflow的tile函数
a1 = tf.tile(a, [2, 2]) 表示把a的第一个维度复制两次,第二个维度复制2次。
注意使用tf.nn.softmax(r, axis=0),表示对每一列取softmax,一定要注意维度,axis=0表示对列取softmax,不然数据会出错
def tensoflow_test():
# 一个batch有20个样本,每个样本的长度为5,每一个为200维度
lstm_outpus = tf.truncated_normal(shape=[2, 5, 4], mean=0, stddev=1)
# 变形成二维
lstm_o = tf.reshape(lstm_outpus, shape=[-1, 4])
# 经过非线性
M = tf.tanh(lstm_o)
# 初始化权重信息
w = tf.truncated_normal(shape=[4,1], mean=0, stddev=1)
# 权重tf.matmul(M, w)
r = tf.matmul(M, w)
a = tf.nn.softmax(r, axis=0)
alpha = tf.tile(a, (1, 4))
# attention_res = lstm_o * alpha # M = tf.reshape(t, shape=[-1, 200])
# o = tf.Variable(tf.truncated_normal([1, 200]), name='w', dtype=tf.float32)
# a = tf.Variable(tf.truncated_normal([2,3]), dtype=tf.float32)
# b = tf.Variable(tf.truncated_normal([2,3]), dtype=tf.float32)
# a_b = tf.multiply(a,b)
# # a_b = a * b
# w = tf.transpose(o)
# res = tf.matmul(M, w)
# res2 = tf.reshape(res, shape=[-1, 5])
# copy_res = tf.tile(res2, (3,1))
# init_op = tf.global_variables_initializer() with tf.Session() as sess:
# sess.run(init_op)
# print(sess.run(res))
# print(sess.run(res2))
# print(res2)
# print(sess.run(copy_res))
# print(copy_res)
# print(sess.run(lstm_o))
# print(sess.run(lstm_outpus))
# print(sess.run(w))
print(lstm_outpus)
print(lstm_o)
print(alpha)
# print(sess.run(lstm_outpus))
print(sess.run([a, alpha]))
# print(sess.run(alpha))
# print(sess.run(alpha))
# print(sess.run(attention_res))
tensorflow的tile使用的更多相关文章
- TensorFlow学习笔记(一):数据操作指南
扩充 TensorFlow tf.tile 对数据进行扩充操作 import tensorflow as tf temp = tf.tile([1,2,3],[2]) temp2 = tf.tile( ...
- [阿里DIN] 从模型源码梳理TensorFlow的乘法相关概念
[阿里DIN] 从模型源码梳理TensorFlow的乘法相关概念 目录 [阿里DIN] 从模型源码梳理TensorFlow的乘法相关概念 0x00 摘要 0x01 矩阵乘积 1.1 matmul pr ...
- 【学习笔记】tensorflow基础
目录 认识Tensorflow Tensorflow特点 下载以及安装 Tensorflow初体验 Tensorflow进阶 图 op 会话 Feed操作 张量 变量 可视化学习Tensorboard ...
- tensorflow函数/重要功能实现
一.基础函数 1.1 .tf.reduce_sum(input_tensor, axis) Computes the sum of elements across dimensions of a ...
- Tensorflow --BeamSearch
github:https://github.com/zle1992/Seq2Seq-Chatbot 1. 注意在infer阶段,需要需要reuse, 2.If you are using the Be ...
- 第七节,TensorFlow编程基础案例-TensorBoard以及常用函数、共享变量、图操作(下)
这一节主要来介绍TesorFlow的可视化工具TensorBoard,以及TensorFlow基础类型定义.函数操作,后面又介绍到了共享变量和图操作. 一 TesnorBoard可视化操作 Tenso ...
- tensorflow faster rcnn 代码分析一 demo.py
os.environ["CUDA_VISIBLE_DEVICES"]=2 # 设置使用的GPU tfconfig=tf.ConfigProto(allow_soft_placeme ...
- 深度学习原理与框架-递归神经网络-RNN_exmaple(代码) 1.rnn.BasicLSTMCell(构造基本网络) 2.tf.nn.dynamic_rnn(执行rnn网络) 3.tf.expand_dim(增加输入数据的维度) 4.tf.tile(在某个维度上按照倍数进行平铺迭代) 5.tf.squeeze(去除维度上为1的维度)
1. rnn.BasicLSTMCell(num_hidden) # 构造单层的lstm网络结构 参数说明:num_hidden表示隐藏层的个数 2.tf.nn.dynamic_rnn(cell, ...
- Tensorflow基本概念
[本文摘自网络,仅供学习使用] 官网上对TensorFlow的介绍是,一个使用数据流图(data flow graphs)技术来进行数值计算的开源软件库.数据流图中的节点,代表数值运算:节点节点之间的 ...
随机推荐
- SQL 中的多条件查询
在应用程序开发中,多条件查询是个经常遇到的情况,最简单最麻烦的方法是把所有的可能情况都考虑到,但是无疑是繁琐的,而且很容易漏掉可能的情形,下面是SQL语句实现多条件查询的情况 select * fro ...
- ListView中的Item点击事件和子控件的冲突或者item点击没有反应的解决的方法
fragment中加入了button和checkbox这些控件.此时这些子控件会将焦点获取到.所以经常当点击item时变化的是子控件.item本身的点击没有响应. 这时候就能够使用descendant ...
- openssl - 数字证书的编程解析
原文链接: http://www.cangfengzhe.com/wangluoanquan/37.html 这篇文章主要介绍PKI公钥体系中非常核心元素——数字证书的编程解析.在SSL,SET等安全 ...
- Spark 论文篇-Spark:工作组上的集群计算的框架(中英双语)
论文内容: 待整理 参考文献: Spark: Cluster Computing with Working Sets. Matei Zaharia, Mosharaf Chowdhury, Micha ...
- Spring Boot 2.0 热部署指南
Spring Boot 2.0 支持热部署,实现方法很简单 Spring Boot 2.0 有几种热重载的选项. 推荐的方法是使用spring-boot-devtools 因为它提供了额外的开发时间功 ...
- vertx插件使用vertx-maven-plugin
http://search.maven.org http://search.maven.org/#artifactdetails%7Cio.fabric8%7Cvertx-maven-plugin%7 ...
- iOS 版本更新(强制更新)检测问题
iOS 版本更新(强制更新)检测问题 通常iOS系统中是默认设置再wifi状态,且网络状况良好下自己更新应用的. 但是如果用户设置了不自动更新,但是我们的APP出现重要的版本,一定需要用户更新的情况下 ...
- [转]Unity手游之路<十二>手游资源热更新策略探讨
最近梳理了下游戏流程.恩,本来想写下,但是,还是看前辈的吧 版权声明: https://blog.csdn.net/janeky/article/details/17666409 上一次我们学习了如何 ...
- [Golang] 从零開始写Socket Server(4):将执行參数放入配置文件(XML/YAML)
为了将我们写好的Server公布到server上.就要将我们的代码进行build打包.这样假设以后想要改动一些代码的话.须要又一次给代码进行编译打包并上传到server上. 显然,这么做过于繁 ...
- 【转帖】Mysql多维数据仓库指南 第一篇 第1章
Mysql多维数据仓库指南 第一篇基本原理 章节列表: 第1章:基本组成 第2章:维度历史 第3章:维度可加性 第4章:维度查询 本篇概述 你将运用关系数据库来实施一个维度数据仓库.事实表和维表这两 ...