簡體   English   中英

如何將Dense層的參數的數據類型設置為float16?

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

我想將Tensorflow Dense層與float16參數一起使用。 偏壓和權重的默認數據類型均為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>

如何使用帶有float16參數的Tensorflow Dense

我想出了一種方法來執行此操作,即將密層的輸入數據類型設置為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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM