TensorFlow系列——一些api的使用场景及方式

1、string_split:

在制作tfrecord的时候,将多个类别特征使用分隔符组装到一起,用一个特征列来存储,降低存储代价。而在训练时候使用string_split将其分隔,分别处理。

参考:

https://www.tensorflow.org/api_docs/python/tf/compat/v1/string_split

结合使用的api:

tf.map_fn

2、filter

对TensorFlow的dataset进行过滤

参考:

https://stackoverflow.com/questions/48825785/how-can-i-filter-tf-data-dataset-by-specific-values

3、keras里的summary()

打印出模型的结构

https://stackoverflow.com/questions/61511786/question-regarding-how-to-directly-apply-softmax-onto-a-logits-with-tf-keras-act

4、为模型添加正则化器:

regularizer = tf.keras.regularizers.l2(l2_factor)

使用时:mylayer.add_loss(self.regularizer(column_weight)),其中mylayer是自定义的tf.keras.layers.Layer,而column_weight为参数tensor。


版权声明:本文为h_jlwg6688原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。