tensorflow tf.argmax() 用法 例子
轉自:https://blog.csdn.net/Jiaach/article/details/78874704
argmax()官方文件如下:
tf.argmax(input, dimension, name=None)
Returns the index with the largest value across dimensions of a tensor.
Args:
input: A Tensor. Must be one of the following types: float32, float64, int64, int32, uint8, int16, int8, complex64, qint8, quint8, qint32.
dimension: A Tensor of type int32. int32, 0 <= dimension < rank(input). Describes which dimension of the input Tensor to reduce across. For vectors, use dimension = 0.
name: A name for the operation (optional).
Returns:
A Tensor of type int64.
dimension=0 按列找
dimension=1 按行找
tf.argmax()返回最大數值的下標
通常和tf.equal()一起使用,計算模型準確度
correct_pred = tf.equal(tf.argmax(pred,1), tf.argmax(y,1))
accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32))
栗子
>>> import tensorflow as tf
>>> a = tf.constant([1.,2.,3.,0.,9.,])
>>> b = tf.constant([[1,2,3],[3,2,1],[4,5,6],[6,5,4]])
>>> with tf.Session() as sess:
... sess.run(tf.argmax(a, 0))
Output:
4
>>> with tf.Session() as sess:
... sess.run(tf.argmax(b, 0))
Output:
array([3, 2, 2])
>>> with tf.Session() as sess:
... sess.run(tf.argmax(b, 1))
Output:
array([2, 0, 2, 0])
Ref:
API文件
--------------------- 本文來自 Jaichg 的CSDN 部落格 ,全文地址請點選:https://blog.csdn.net/Jiaach/article/details/78874704?utm_source=copy
相關文章
- While True用法小例子While
- C++【string】用法和例子C++
- C++【vector】用法和例子C++
- PHP中ZendCache用法的小例子PHP
- C++【stack/queue】用法和例子C++
- tensorflow學習筆記--embedding_lookup()用法筆記
- [轉載] Python中協程的詳細用法和例子Python
- 用一個小例子教你入門機器學習框架TensorFlow機器學習框架
- Orale的struct,array,cursor,stored procedure,function,package的用法例子StructFunctionPackage
- 通過一個例子學習Kubernetes裡的PersistentVolumeClaim的用法AI
- Python中threading的join和setDaemon的區別及用法[例子]Pythonthread
- 一個簡單例子教會你C++動態庫的用法單例C++
- pytorch和tensorflow的愛恨情仇之一元線性迴歸例子(keras插足啦)PyTorchKeras
- 【python小例子】小例子拾憶Python
- 4.5.1.1.2 例子
- awk例子
- C++STL之Vector向量詳解,用法和例子 一起學習 一起加油C++
- tensorflow:使用conda安裝tensorflow
- TensorFlow
- popmenu的例子
- java socket例子Java
- tensorflow的各種坑 tensorflow1.x 與 tensorflow2.x
- TensorFlow——tensorflow指定CPU與GPU運算GPU
- TensorFlow Lite
- TensorFlow Serving
- dockerfile測試例子Docker
- Qt表格排序例子QT排序
- CSS 權值例子CSS
- expdp一個例子
- mybatis小例子2MyBatis
- Java String length()例子Java
- sax解析例子演示
- 【TensorFlow】 TensorFlow-Slim影像分類模型庫模型
- 【TensorFlow篇】--Tensorflow框架視覺化之Tensorboard框架視覺化ORB
- TensorFlow模型部署到伺服器---TensorFlow2.0模型伺服器
- DKT模型及其TensorFlow實現(Deep knowledge tracing with Tensorflow)模型
- Tensorflow教程(2)Tensorflow的常用函式介紹函式
- Tensorflow2