tensorflow 混合精度训练相关报错

如题,在混合精度开发的时候遇到的报错。

先列环境:V100服务器   ubuntu16.04  tensorflow 1.14.0   cuda10.0   python3.6 

 

报错一:ValueError: "opt" must be an instance of a tf.train.Optimizer or a tf.keras.optimizers.Optimizer, but got:

解决方案:

将ad=keras.optimizers.Adam()换成

ad=tf.compat.v1.train.AdamOptimizer(learning_rate=0.005)

 

报错二:You already have existing Sessions that do not use mixed precision. enable_mixed_precision_graph_rewrite() will not affect these Sessions.

解决方案(请教大神的):

先tf.train.experimental.enable_mixed_precision_graph_rewrite(optim) ,再sess=tf.Session()

为了防止对后面的loss等参数有影响,建议在clear_session()后就执行tf.train.experimental.enable_mixed_precision_graph_rewrite(ad)

另:输出混合精度日志:

os.environ['TF_AUTO_MIXED_PRECISION_GRAPH_REWRITE_LOG_PATH'] ="/you/log/dir"

你可能感兴趣的:(报错解决,tensorflow,混合精度训练)