tensorflow
苏学算法
这个作者很懒,什么都没留下…
展开
-
tensorflow 对 label 做 mask
有时,需要对某些 label 做 mask#!/usr/bin/env python# coding=utf-8"""tf version: 1.15.0"""import tensorflow as tf# 维度 [batch_size, 1]label1 = tf.constant([[0.0], [1.0], [1.0]])label2 = tf.constant([[1.0],原创 2022-05-01 20:39:56 · 503 阅读 · 0 评论 -
tf.squeeze 和 tf.reduce_sum 区别
tf.squeeze 和 tf.reduce_sum 是可以起到一样的作用的直接上代码#!/usr/bin/env python# coding=utf-8"""tf version: 1.15.0"""import tensorflow as tf# 维度 [batch_size, 1]a = tf.constant([[1], [6], [11]])b1 = tf.squeeze(a, axis=1)b2原创 2022-05-01 19:42:05 · 230 阅读 · 0 评论 -
tensorflow或运算 tf.logical_or & tf.math.logical_or
模块tensorflow.math为许多基本的数学运算提供支持。功能 tf.logical_or [别名 tf.math.logical_or ]为Tensorflow中的逻辑OR功能提供支持。期望输入布尔类型。输入类型为张量,如果张量包含多个元素,则将按元素进行逻辑或运算, xORyx OR yxORy 。用法:tf.logical_or(x, y, name=None) ortf.math.logical_or(x, y, name=None)参数:x:布尔类型的张量。y:布尔类型的张原创 2022-01-11 10:29:20 · 1256 阅读 · 0 评论 -
tf.ones_like & tf.zeros_like 用法
tf.ones_like(tensor,dype=None,name=None)tf.zeros_like(tensor,dype=None,name=None)新建一个与给定的tensor类型大小一致的tensor,其所有元素为1 或 0tensor=[[1, 2, 3], [4, 5, 6]] x = tf.ones_like(tensor) print(sess.run(x))输出:[[1 1 1],[1 1 1]]...原创 2022-01-10 19:24:19 · 520 阅读 · 0 评论 -
tf.add_n函数的用法
tf.add_n([p1, p2, p3…])函数是实现一个列表的元素的相加。就是输入的对象是一个列表,列表里的元素可以是向量,矩阵,等例如:import tensorflow as tf;import numpy as np; input1 = tf.constant([1.0, 2.0, 3.0])input2 = tf.Variable(tf.random_uniform([3]))output = tf.add_n([input1, input2]) with tf.Session原创 2022-01-06 11:31:25 · 467 阅读 · 0 评论 -
tf.stack详解
直接上代码,更直观# coding=utf-8# tf 2.0import tensorflow as tfa = tf.constant([[1,2,3], [3,4,5]]) # shape (2,3)b = tf.constant([[7,8,9], [10,11,12]]) # shape (2,3)ab = tf.stack([a,b], axis=0) # shape (2,2,3)print(ab)输出t原创 2021-11-03 16:15:36 · 590 阅读 · 0 评论 -
tf.gather_nd详解
其实就是取出对应位置的元素,直接看代码更直观简单# coding=utf-8# tf 2.0import tensorflow as tfa = tf.constant([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]])index_a1 = tf.constant([[0, 2], [0, 4], [2, 2]]) # 随便选几个index_原创 2021-11-03 15:40:19 · 549 阅读 · 0 评论