AttributeError: module 'keras.engine' has no attribute 'Layer'

AttributeError: module 'keras.engine' has no attribute 'Layer'

当我尝试 运行 Parking_Slot_mask_rcnn.py 文件时,我在 mrcnn/model.py 文件中收到如下错误 我该如何解决

**> 2021-06-17 08:25:18.585897:W

tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found 2021-06-17 08:25:18.586852: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. Using TensorFlow backend. Traceback (most recent call last): File "Parking_Slot_mask_rcnn.py", line 20, in import coco File "C:\Users\nusry\Desktop\parkingslot-master\coco.py", line 56, in from mrcnn import model as modellib, utils File "C:\Users\nusry\Desktop\parkingslot-master\mrcnn\model.py", line 268, in class ProposalLayer(KE.Layer): AttributeError: module 'keras.engine' has no attribute 'Layer**

在此模型文件文件中全部导入

import os
import random
import datetime
import re
import math
import logging
from collections import OrderedDict
import multiprocessing
import numpy as np
import tensorflow as tf
import keras
import keras.backend as K
import keras.layers as KL
import keras.engine as KE
import keras.models as KM

from mrcnn import utils

这是第 268 行代码:

class ProposalLayer(KE.Layer):

已安装:

  Tensorflow version Version: 2.5.0
    
  Keras  Version Version: 2.2.0

请帮我整理一下

您应该使用:keras.layers.Layer 代替 (KL.Layer)

嗯,您收到此错误是因为 TensorflowKeras 之间存在兼容性问题。你看到引擎盖下 Keras 使用 Tensorflow 进行各种矩阵操作。

我会建议您升级 Keras 并降级 Tensorflow

 pip install keras==2.4.3

 pip install tensorflow==2.4.1

我有这些版本并且我能够成功运行代码。