Python 属性错误:模块';tensorflow.keras.mixed#u精度';没有属性';制定全球政策';
我需要添加到我的代码中以节省一些内存。具体来说,我尝试在中的第27行附近添加混合精度策略,下面是代码摘录Python 属性错误:模块';tensorflow.keras.mixed#u精度';没有属性';制定全球政策';,python,python-3.x,tensorflow,keras,google-colaboratory,Python,Python 3.x,Tensorflow,Keras,Google Colaboratory,我需要添加到我的代码中以节省一些内存。具体来说,我尝试在中的第27行附近添加混合精度策略,下面是代码摘录 import argparse import datetime import os import numpy as np from ravens import agents from ravens import Dataset import tensorflow as tf # tf.keras.mixed_precision.set_global_policy('mixed_float
import argparse
import datetime
import os
import numpy as np
from ravens import agents
from ravens import Dataset
import tensorflow as tf
# tf.keras.mixed_precision.set_global_policy('mixed_float16')
# OR
# policy = tf.keras.mixed_precision.Policy('mixed_float16')
# mixed_precision.set_global_policy(policy)
这两种方法都会导致属性错误,如下所示,我使用的是带有TF2.3.0的GoogleColab
使用tf.keras.mixed\u precision.set\u global\u policy('mixed\u float16')
Traceback (most recent call last):
File "train.py", line 28, in <module>
tf.keras.mixed_precision.set_global_policy('mixed_float16')
AttributeError: module 'tensorflow.keras.mixed_precision' has no attribute 'set_global_policy'
Traceback (most recent call last):
File "train.py", line 29, in <module>
policy = tf.keras.mixed_precision.Policy('mixed_float16')
AttributeError: module 'tensorflow.keras.mixed_precision' has no attribute 'Policy'
导致
Traceback (most recent call last):
File "train.py", line 28, in <module>
tf.keras.mixed_precision.set_global_policy('mixed_float16')
AttributeError: module 'tensorflow.keras.mixed_precision' has no attribute 'set_global_policy'
Traceback (most recent call last):
File "train.py", line 29, in <module>
policy = tf.keras.mixed_precision.Policy('mixed_float16')
AttributeError: module 'tensorflow.keras.mixed_precision' has no attribute 'Policy'
回溯(最近一次呼叫最后一次):
文件“train.py”,第29行,在
policy=tf.keras.mixed\u precision.policy('mixed\u float16'))
AttributeError:模块“tensorflow.keras.mixed_precision”没有属性“Policy”
任何帮助或提示都将不胜感激 对于
tf<2.4
您应该使用
tf.keras.mixed_precision.experimental.Policy(
name, loss_scale='auto'
)
对于ex,在tf 2.3中
policy = tf.keras.mixed_precision.experimental.Policy('mixed_float16')
tf.keras.mixed_precision.experimental.set_policy(policy)
在tf2.4中
tf.keras.mixed_precision.set_global_policy('mixed_float16')
在tf 2.4中,此功能不再是实验性的