[英]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.