简体   繁体   English

如何将Dense层的参数的数据类型设置为float16?

[英]how can I set the data type of parameters of Dense layer to float16?

I want to use Tensorflow Dense layer with float16 parameters. 我想将Tensorflow Dense层与float16参数一起使用。 The default data types of bias and weights are both float32, I tried setting the data type by setting the initializer tf.truncated_normal_initializer(dtype=tf.float16) but it doesn't seem to have any effect. 偏压和权重的默认数据类型均为float32,我尝试通过设置初始化程序tf.truncated_normal_initializer(dtype=tf.float16)来设置数据类型,但似乎没有任何作用。

import tensorflow as tf
A = tf.get_variable(name='foo', shape=[3, 3])
dense = tf.layers.dense(inputs=A, units=3, kernel_initializer=tf.truncated_normal_initializer(dtype=tf.float16))
varis = tf.trainable_variables(scope=None)
print(varis[1])  # <tf.Variable 'dense/kernel:0' shape=(3, 3) dtype=float32_ref>

How can I use Tensorflow Dense with float16 parameters? 如何使用带有float16参数的Tensorflow Dense

I figured out a way to do this, that is to set the input data type of the dense layer to tf.float16 我想出了一种方法来执行此操作,即将密层的输入数据类型设置为tf.float16

import tensorflow as tf
A = tf.get_variable(name='foo', shape=[3, 3], dtype=tf.float16)
dense = tf.layers.dense(inputs=A, units=3)
varis = tf.trainable_variables(scope=None)
print(varis[1])  # <tf.Variable 'dense/kernel:0' shape=(3, 3) dtype=float16_ref>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在数组 class 中添加对 float16 类型的支持 - how to add support for float16 type in array class 在OpenCV中运行神经网络时,如何解决“错误:(-215)pbBlob.raw_data_type()== caffe :: FLOAT16在函数blobFromProto中的问题” - How to fix, “error: (-215) pbBlob.raw_data_type() == caffe::FLOAT16 in function blobFromProto” when running neural network in OpenCV float8、float16、float32、float64、float128 可以包含多少位? - How many digits can float8, float16, float32, float64, and float128 contain? 从 java 中的箭头文件读取 float16 数据类型列的正确方法是什么? - What is the correct way to read float16 data type column from arrow file in java? Tensorflow Float16 for VGG19 模型参数 - Tensorflow Float16 for VGG19 model parameters ONNX 量化 Model 类型错误:类型“张量(float16)” - ONNX Quantized Model Type Error: Type 'tensor(float16)' 熊猫SparseSeries可以将值存储在float16 dtype中吗? - Can pandas SparseSeries store values in the float16 dtype? 如何在 Keras 中使用 float16 微调 resnet50? - How to fine tune resnet50 with float16 in Keras? 如何重复使用Dense图层? - How can I reuse a Dense layer? 是否可以使用 float16 使用 tensorflow 1 进行训练? - Is it possible to train with tensorflow 1 using float16?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM