【问题标题】:Attribute Error: module 'tensorflow' has no attribute 'contrib'属性错误:模块“tensorflow”没有属性“contrib”
【发布时间】:2021-04-21 06:45:19
【问题描述】:

我正在尝试加载 tensorflow zoo 模型,但我遇到了这个错误,我无法修复这个我是 ai/ml 的新手。这是加载动物园模型的代码:

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'    # Suppress TensorFlow logging
import tensorflow as tf
from object_detection.utils import label_map_util
from object_detection.utils import config_util
from object_detection.utils import visualization_utils as viz_utils
from object_detection.builders import model_builder

tf.get_logger().setLevel('ERROR')           # Suppress TensorFlow logging (2)

# Enable GPU dynamic memory allocation
gpus = tf.config.experimental.list_physical_devices('GPU')
for gpu in gpus:
    tf.config.experimental.set_memory_growth(gpu, True)

# Load pipeline config and build a detection model
configs = config_util.get_configs_from_pipeline_file(PATH_TO_CFG)
model_config = configs['model']
detection_model = model_builder.build(model_config=model_config,                                     
is_training=False)

# Restore checkpoint
ckpt = tf.compat.v2.train.Checkpoint(model=detection_model)
ckpt.restore(os.path.join(PATH_TO_CKPT, 'ckpt-0')).expect_partial()

@tf.function
def detect_fn(image):
    """Detect objects in image."""

    image, shapes = detection_model.preprocess(image)
    prediction_dict = detection_model.predict(image, shapes)
    detections = detection_model.postprocess(prediction_dict, shapes)

    return detections, prediction_dict, tf.reshape(shapes, [-1])

【问题讨论】:

标签: python tensorflow object-detection


【解决方案1】:

正如@yudhiesh 所述,tf.contrib 在 Tensorflow >=2.0 中已被弃用。 tf.contrib 库已移至 Tensorflow addons

看看Tensorflow release note

【讨论】:

    猜你喜欢
    • 2019-09-16
    • 2021-06-23
    • 1970-01-01
    • 2022-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-17
    • 1970-01-01
    相关资源
    最近更新 更多