TensorFlow
文章平均质量分 57
凝眸伏笔
纵然伤心也不要愁眉不展,因为你不知道谁会爱上你的笑容。
展开
-
TensorFlow:Allocation of 256000000 exceeds 10% of system memory对auc的影响
我在原来特征基础上,增加了一列特征,这列特征是一个list,长度不固定[0,5]之间的一个长度,比如 样本 1: ['找工作', '发工资', '领导力']代码中给该列特征先做了一个分桶,根据该列特征中词的个数,来确定桶的大小;我这里大约2k个不同的词,hash_bucket_size=2e3;然后做tf.feature_column.embedding_column(feat, 8);这个8怎么确定?2000开两次根号,等于6.7,向上取整得到 7,因为这样不会造成词重叠,但是会造成一些参数浪费;至于效果原创 2022-06-06 20:42:17 · 1071 阅读 · 2 评论 -
TF模型训练中数据shuffle对模型性能的影响
未经shuffle的loss曲线出现周期性的震荡,测试后模型的泛化效果也很差。什么是Shuffle?shuffle(中文意思:洗牌,混乱)。shuffle在机器学习与深度学习中代表的意思是,将训练模型的数据集进行打乱的操作。原始的数据,在样本均衡的情况下可能是按照某种顺序进行排列,如前半部分为某一类别的数据,后半部分为另一类别的数据。但经过打乱之后数据的排列就会拥有一定的随机性,在顺序读取的时候下一次得到的样本为任何一类型的数据的可能性相同。模型训练过程中需要Shuffle么?Shuffl原创 2021-12-08 22:41:15 · 2252 阅读 · 0 评论 -
TensorFlow Estimator 中的模型保存为Checkpoints格式
1. 保存经过部分训练的模型Estimators 在训练过程中会自动将以下内容保存到磁盘:chenkpoints:训练过程中的模型快照。event files:其中包含 TensorBoard 用于创建可视化图表的信息。原创 2021-12-08 23:45:00 · 1849 阅读 · 0 评论 -
tensorflow:Entity <bound method Dense AssertionError: Bad argument number for Name: 3, expecting 4
tensorflow:Entity <bound method Dense AssertionError: Bad argument number for Name: 3, expecting 4解决原创 2021-12-08 22:00:00 · 1225 阅读 · 0 评论 -
TFrecords 制作数据报错: Number of int64 values != expected. Values size: 1 but output shape: [3]
1.对于定长的label和feature生成tfrecord数据:多标签样本,这里label包含5个import osimport tensorflow as tfimport numpy as npoutput_flie = str(os.path.dirname(os.getcwd()))+"/train.tfrecords"with tf.python_io.TFRecordWriter(output_flie) as writer: labels = np.array(原创 2021-08-15 19:21:32 · 722 阅读 · 0 评论 -
TensorFlow四则运算之除法:tf.divide()
1.作用:两个张量相除。tf.math.divide( x, y, name=None)或者tf.math.div( x, y, name=None)输入:x:张量,分子,y:张量,分母,x和y要类型相同。输出:张量,类型是float,形状同输入,dim也随输入。例子:import tensorflow as tfa = tf.constant(6.0)b = tf.constant(3)c = tf.div(a, tf.cast(b, dty...原创 2020-09-16 23:29:03 · 12521 阅读 · 0 评论 -
TensorFlow四则运算之乘法:tf.multiply()
1.作用:逐元素相乘tf.math.multiply( x, y, name=None)输入:x:一个tensor,类型得是bfloat16, half, float32, float64, uint8, int8, uint16, int16, int32, int64, complex64, complex128.y:跟x同类型。输出:逐个元素相乘后的结果。import tensorflow as tfa = tf.constant([[3, 2], [5, 1..原创 2020-09-16 23:29:15 · 11094 阅读 · 3 评论 -
TensorFlow四则运算之减法:tf.subtract()
1.作用:逐个元素相减。tf.math.subtract( x, y, name=None)输入:x:一个tensory:跟x同类型的tensor例子:import tensorflow as tfa = tf.constant([[3]]) #广播为:[[3, 3], [3, 3]]b = tf.constant([[1, 6], [2, 9]])c = tf.subtract(a, b)sess = tf.Session()print sess.run(c)..原创 2020-09-16 23:29:21 · 2724 阅读 · 1 评论 -
TensorFlow四则运算之加法:tf.add()
tensor广播(boardcast):为了凑够元素个数,便于后续计算,这里将元素进行复制,达到某一个维度,称之为广播.1.作用:两个张量相加tf.math.add( x, y, name=None)输入:x是一个张量,其类型需得是:bfloat16, half, float32, float64, uint8, int8, int16, int32, int64, complex64, complex128, string.y同x一个类型。输出:一个张量。2...原创 2020-09-16 23:29:27 · 7501 阅读 · 0 评论 -
Tensorflow中的tensor的维度(dim=0、dim=1)理解
1.tensor的维度理解通过tf.rank()函数可以查看tensor的维度。先看一个例子:import tensorflow as tfa = tf.constant(6) #常量-dim=0b = tf.constant([3, 3]) #数组-dim=1c = tf.constant([[6, 3]]) #矩阵-dim=2d = tf.constant([[[2, 2]]]) #矩阵-dim=3可以想象为空间坐标系 xyz三个轴sess = tf.Session() #启动图.原创 2020-09-15 23:06:43 · 15895 阅读 · 0 评论 -
TensorFlow中用tf.size()计算张量中元素个数
1.tf.size()的作用返回输入张量的大小,注意不是 shape,而是元素个数,0 维张量,默认为 tf.int32 类型(下面的示例中可看到)tf.size(input, name=None, out_type=tf.int32)参数:input:张量或稀疏张量name:可选参数,操作的名称out_type:可选参数,操作的指定非量化数字输出类型,默认是 tf.int32 类型返回:out_type 数据类型的张量,默认是 tf.int32.例子...原创 2020-09-15 23:06:58 · 2607 阅读 · 0 评论 -
tf.cast()类型转换函数
作用:类型转换函数tf.cast(x, dtype, name=None)参数:x:输入 dtype:转换目标类型 name:名称返回:Tensor,跟输入同shape这里补充下tf的数据类型,作为tf.cast()的参数时,需要写为tf.float32.uint8,uint16,uint32,uint64,int8,int16,int32,int64,float16,float32,float64,complex64,complex128,bfloa...原创 2020-09-10 23:34:13 · 1309 阅读 · 0 评论 -
tensorflow打印tensor详细数值
问题:tensor详细数值不能直接print打印,print输出的是tensor的类型、shape、和数据类型。import tensorflow as tfa = tf.constant(51)print a输出:Tensor("Const:0", shape=(), dtype=int32)原因:print只能打印输出shape的信息,而要打印输出tensor的值,需要借助 tf.Session,tf.InteractiveSession。因为我们在建立graph的时候,只原创 2020-09-10 23:01:29 · 5714 阅读 · 3 评论 -
TensorFlow的tf.reduce_sum()函数及其使用方式
方法:在reduce_sum()中,是从维度上去考虑元素相加。tf.math.reduce_sum( input_tensor, axis=None, keepdims=False, name=None)参数说明:input_tensor:要求和的数据axis:有两个取值分别为0和1,0代表按照列进行求和,1代表按照行进行求和。当该参数省略时,默认对矩阵所有元素进行求和。keepdims:If true, retains reduced dimensions with ...原创 2020-09-10 23:01:45 · 2927 阅读 · 0 评论 -
Invalid argument: Name:<unknown>,Feature:weight(data type: float)is required but could not be found
TensorFlowflow训练模型报错: Invalid argument: Name: <unknown>, Feature: weight (data type: float) is required but could not be found.问题现场:2020-09-09 11:03:49.962924: W tensorflow/core/framework/op_kernel.cc:1502] OP_REQUIRES failed at example_parsing_原创 2020-09-10 23:02:11 · 1149 阅读 · 0 评论 -
loss不收敛可能的原因以及相应的解决方法
问题现场最近使用tensorflow训练模型,通过tensorboard查看train auc、eval auc、 loss曲线走势。loss如下,这个跟曲线走势跟书本上的曲线走势,差异很大,看到这个loss,波动很大(曾经见过的loss值大约在0.0XX的一个数值上),并且没有收敛的趋势,有点慌了,第一次面对这种情况,跟书上的知识还不一致,自己知识拓展也比较贫瘠,不知如何是好...请教了组内的大神,给出了几点建议,我觉得非常有道理:tricks:推荐数据的loss曲线没有太大的参考意义原创 2020-08-20 23:14:57 · 17544 阅读 · 7 评论 -
tf.app.flags()和tf.flags()的用法及区别
tf.app.flags主要用于处理命令行参数的解析工作,其实可以理解为一个封装好了的argparse包(argparse是一种结构化的数据存储格式,类似于Json、XML)。跟它配合使用的还有一个tf.app.run()函数,它的核心意思:执行程序中main函数,并解析命令行参数。问题现场:tf.app.flags()和tf.flags()定义了变量后,输出没啥区别,并且可以在终端运行时,传入参数,也都可以更新默认参数,有什么区别?import tensorflow as tf#第一.原创 2021-03-08 22:20:44 · 1613 阅读 · 8 评论 -
tf.cond()条件控制语句执行出错
tf.cond()用法,以及常见错误:1. raise TypeError("pred must not be a Python bool")TypeError: pred must not be a Python bool2. raise TypeError("true_fn must be callable.")TypeError: true_fn must be callable.原创 2020-08-17 22:44:43 · 1008 阅读 · 2 评论 -
【TensorFlow】通过实例解释tf.slice()用法
1.作用从tensor中获取一个切片。2.例子python中的切片操作:参考1.官方文档:https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/slice原创 2020-08-17 22:36:52 · 465 阅读 · 0 评论 -
【TensorFlow】查看 tensor详细数值
1.问题想查看tensor的值,print后,只能 看到它的类型信息,而我想看的是value。问题现场:# -*- coding: utf-8 -*-import tensorflow as tfa=tf.constant(2)b=tf.constant(3)x=tf.constant(4)y=tf.constant(5)print aprint bprint xprint y输出:Tensor("Const:0", shape=(), dtype=int32)Ten原创 2020-08-13 22:29:13 · 4766 阅读 · 2 评论 -
【TensorFlow】(八)tf.feature_column.indicator_column()函数的作用及用法
1.作用indicator_column可用于包装任何categorical_column_*产生的向量,然后作为NN模型的input_layer的输入。使用方式:tf.feature_column.indicator_column(categorical_column)输入:categorical_column_*的输出。输出:可用于NN模型的input_layer的输入。2.例子import tensorflow as tfsess=tf.Session()#原创 2020-08-13 23:30:01 · 4029 阅读 · 3 评论 -
【TensorFlow】(七)tf.feature_column.crossed_column()函数的作用及用法
1.作用对hash映射之后的特征进行交叉。优势:特征交叉,在有些情况下,特征独自编码与多维特征交叉后的特征特性会有不一样的结果。使用方式:tf.feature_column.crossed_column( keys, hash_bucket_size, hash_key=None)输入:keys 可迭代识别功能交叉。每个元素可以是: 字符串:将使用相应的功能,它必须是字符串类型。 CategoricalColumn:将类别转化为的张量。将采用此塔产生...原创 2020-08-13 23:29:22 · 3981 阅读 · 0 评论 -
【TensorFlow】(六)tf.feature_column.categorical_column_with_vocabulary_file()函数的作用及用法
如果单词有些时候比较多,这时候可以直接从文件中读取文字列表。同tf.feature_column.categorical_column_with_vocabulary_list()函数的区别:如果单词有些时候比较多,使用文件存储单词,使用该函数;若单词较少且已知,可以使用vocabulary_list函数,对单词做hash。原创 2020-08-13 22:30:28 · 1410 阅读 · 0 评论 -
【TensorFlow】(五)tf.feature_column.categorical_column_with_vocabulary_list()函数的作用及用法
1.作用A sequence of categorical terms where ids are set by hashing.(翻译:将一个类别序列,进行hash映射。根据单词的序列顺序,把单词根据index转换成one hot encoding)输入:key 一个唯一的字符串识别输入功能。 vocabulary_file 词汇文件名。或者词的set集合。 vocabulary_size 在词汇中元素的个数。这必须是不大于长度vocabulary_file,如果低.原创 2020-08-12 22:02:34 · 3240 阅读 · 0 评论 -
【TensorFlow】(四)tf.feature_column.embedding_column()函数
tf.feature_column.embedding_column()函数将sparse/categrical特征转化为dense 向量。shared_embedding_columns跟embedding_column,不同之处在于它产生嵌入共享相同的嵌入权重列的列表。原创 2020-08-12 21:42:26 · 6224 阅读 · 0 评论 -
【TensorFlow】(三)tf.feature_column.shared_embedding_columns()函数的用法
将sparse、categorical输入,转为dense column。这类似于embedding_column,不同之处在于它产生嵌入共享相同的嵌入权重列的列表。在TensorFlow2.0中叫tf.feature_column.shared_embeddings()。原创 2020-08-12 21:19:56 · 4790 阅读 · 0 评论 -
【TensorFlow】(二)tf.feature_column.categorical_column_with_hash_bucket()函数的用法
tf.feature_column.categorical_column_with_hash_bucket()函数的用法,参数的意义,不同hash_buckets_size产生的影响。该方法的缺点:会出现哈希冲突问题。原创 2020-08-12 20:49:22 · 6044 阅读 · 6 评论 -
【TensorFlow】(一) tf.feature_column.categorical_column_with_identity()函数的使用
tf.feature_column.categorical_column_with_identity()函数的使用;tf.Session()的作用;tf.global_variables_initializer()的作用。原创 2020-08-12 19:53:45 · 3793 阅读 · 2 评论 -
【TF】tf.feature_column特征处理方法汇总
1. 背景tf.estimator是tensorflow的一个高级API接口,它最大的特点在于兼容分布式和单机两种场景,工程师可以在同一套代码结构下即实现单机训练也可以实现分布式训练,正是因为这样的特点,目前包括阿里在内的很多公司都在使用这一接口来构建自己的深度学习模型。特征预处理是几乎所有机器学习模型所必须的一个过程,常见的特征预处理方法包括:连续变量分箱化、离散变量one-hot、离散指标embedding等,tensorflow给我们提供了一个功能强大的特征处理函数tf.feature_col原创 2020-08-17 22:43:41 · 1366 阅读 · 0 评论