tf.nn.softmax 分类

tf.nn.softmax(logits,axis=None,name=None,dim=None)
参数:
logits:一个非空的Tensor。必须是下列类型之一:half, float32,float64
axis:将在其上执行维度softmax。默认值为-1,表示最后一个维度
name:操作的名称(可选)
dim:axis的已弃用的别名

返回:
一个Tensor,与logits具有相同的类型和shape

sample

import tensorflow as tf

#tf.enable_eager_execution()
tf.compat.v1.enable_eager_execution()

ones = tf.ones(shape=[2,3])
print(ones)

temp1 = tf.nn.softmax(ones,axis=0) # 列
print(temp1)

temp2 = tf.nn.softmax(ones,axis=1) # 行
print(temp2)

output

tf.Tensor(
[[1. 1. 1.]
 [1. 1. 1.]], shape=(2, 3), dtype=float32)
tf.Tensor(
[[0.5 0.5 0.5]
 [0.5 0.5 0.5]], shape=(2, 3), dtype=float32)
tf.Tensor(
[[0.33333334 0.33333334 0.33333334]
 [0.33333334 0.33333334 0.33333334]], shape=(2, 3), dtype=float32)

原文地址:https://www.cnblogs.com/smallredness/p/11199447.html

时间: 2024-08-27 10:10:59

tf.nn.softmax 分类的相关文章

tensorflow-tf.nn.softmax,tf.nn.sparse_softmax_cr

#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Tue Oct 2 08:43:02 2018 @author: myhaspl @email:[email protected] tf.nn.softmax tf.nn.sparse_softmax_cross_entropy_with_logits tf.nn.softmax_cross_entropy_with_logits ""

深度学习原理与框架-CNN在文本分类的应用 1.tf.nn.embedding_lookup(根据索引数据从数据中取出数据) 2.saver.restore(加载sess参数)

1. tf.nn.embedding_lookup(W, X) W的维度为[len(vocabulary_list), 128], X的维度为[?, 8],组合后的维度为[?, 8, 128] 代码说明一下:即根据每一行X中的一个数,从W中取出对应行的128个数据,比如X[1, 3]个数据是3062,即从W中的第3062行取出128个数据 import numpy as np import tensorflow as tf data = np.array([[2, 1], [3, 4], [5,

tensorflow中四种不同交叉熵函数tf.nn.softmax_cross_entropy_with_logits()

Tensorflow中的交叉熵函数tensorflow中自带四种交叉熵函数,可以轻松的实现交叉熵的计算. tf.nn.softmax_cross_entropy_with_logits() tf.nn.sparse_softmax_cross_entropy_with_logits() tf.nn.sigmoid_cross_entropy_with_logits() tf.nn.weighted_cross_entropy_with_logits()注意:tensorflow交叉熵计算函数输入

【TensorFlow】tf.nn.softmax_cross_entropy_with_logits的用法

在计算loss的时候,最常见的一句话就是 tf.nn.softmax_cross_entropy_with_logits ,那么它到底是怎么做的呢? 首先明确一点,loss是代价值,也就是我们要最小化的值 tf.nn.softmax_cross_entropy_with_logits(logits, labels, name=None) 除去name参数用以指定该操作的name,与方法有关的一共两个参数: 第一个参数logits:就是神经网络最后一层的输出,如果有batch的话,它的大小就是[b

tf.nn.softmax_cross_entropy_with_logits的用法

在计算loss的时候,最常见的一句话就是tf.nn.softmax_cross_entropy_with_logits,那么它到底是怎么做的呢? 首先明确一点,loss是代价值,也就是我们要最小化的值 tf.nn.softmax_cross_entropy_with_logits(logits, labels, name=None) 除去name参数用以指定该操作的name,与方法有关的一共两个参数: 第一个参数logits:就是神经网络最后一层的输出,如果有batch的话,它的大小就是[bat

Tensorflow四种交叉熵函数计算公式:tf.nn.cross_entropy

Tensorflow交叉熵函数:cross_entropy 注意:tensorflow交叉熵计算函数输入中的logits都不是softmax或sigmoid的输出,而是softmax或sigmoid函数的输入,因为它在函数内部进行sigmoid或softmax操作   tf.nn.sigmoid_cross_entropy_with_logits(_sentinel=None,labels=None, logits=None, name=None) argument: _sentinel:本质上

tf.nn.embedding_lookup()

一直想解决如果在tensorflow中按照需求组装向量,于是发现了这个函数 tf.nn.embedding_lookup(params, ids, partition_strategy=’mod’, name=None, validate_indices=True, max_norm=None) 除了前两个参数,其他参数暂时还不知道怎么使用.然而这并不影响实现程序. params放全部的向量,也就是在文本学习中的所有字符对应的向量 ids放置索引的数组,也就是要挑选出来的字符的索引号.

TF-卷积函数 tf.nn.conv2d 介绍

转自 http://www.cnblogs.com/welhzh/p/6607581.html 下面是这位博主自己的翻译加上测试心得 tf.nn.conv2d是TensorFlow里面实现卷积的函数,参考文档对它的介绍并不是很详细,实际上这是搭建卷积神经网络比较核心的一个方法,非常重要 tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, name=None) 除去name参数用以指定该操作的name,与方法有关

tf.nn.conv2d

tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, name=None) input: 指需要做卷积的输入图像,它要求是一个Tensor,具有[batch, in_height, in_width, in_channels]这样的shape,具体含义是[训练时一个batch的图片数量, 图片高度, 图片宽度, 图像通道数],注意这是一个4维的Tensor,要求类型为float32和float64其中之一 fil