TensorFlow 多分类标签转换成One-hot
来源:互联网 发布:人工智能演讲 编辑:程序博客网 时间:2024/06/05 17:17
TensorFlow 多分类标签转换成One-hot
在处理多分类问题时,将多分类标签转成One-hot编码是一种很常见的手段,以下即为Tensorflow将标签转成One-hot的tensor。以Mnist为例,如果标签为“3”,则One-hot编码为[0,0,0,1,0,0,0,0,0,0].
import tensorflow as tf # version : 1.4NUM_CLASSES = 10 # 10分类labels = [0,1,2,3] # sample labelbatch_size = tf.size(labels) # get size of labels : 4labels = tf.expand_dims(labels, 1) # 增加一个维度indices = tf.expand_dims(tf.range(0, batch_size,1), 1) #生成索引concated = tf.concat([indices, labels] , 1) #作为拼接onehot_labels = tf.sparse_to_dense(concated, tf.stack([batch_size, NUM_CLASSES]), 1.0, 0.0) # 生成one-hot编码的标签
sparse_to_dense 函数说明:https://www.tensorflow.org/api_docs/python/tf/sparse_to_dense
将稀疏矩阵转换成密集矩阵,其中索引在concated中,值为1.其他位置的值为默认值0.
阅读全文
0 0
- TensorFlow 多分类标签转换成One-hot
- PyTorch——Tensor_把索引标签转换成one-hot标签表示
- Tensorflow学习: one-hot编码
- tfrecords的分类处理 one hot
- Tensorflow 的tf.one_hot()功能:dense to one hot
- TensorFlow 之基于Inception V3的多标签分类 retrain
- TensorFlow 之基于Inception V3的多标签分类 retrain
- 独热码one-hot code
- One Hot Code---独热码
- one-hot编码
- One hot encoding
- One-Hot Encoding
- one hot coding
- one-hot编码
- 数据处理之one-hot
- One-Hot Encoding
- one-hot编码
- One-Hot Encoding
- 一、MySQL 安装
- Android双击事件(判断时间范围)
- Magic Powder
- matlab文件导入
- ElasticSearch Java Api(四) -删除索引
- TensorFlow 多分类标签转换成One-hot
- PAT---1027打印沙漏
- Thread类创建线程
- 计算学生分数的最大值,最小值和总分
- 爬虫Scrapy-03Shell和Selectors
- hdu 1022 栈
- C++实现顺序表和单链表
- QT基础之编写第一个QT程序
- Symmetric Tree