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

Question:

while I am trying to run the Parking_Slot_mask_rcnn.py file I got the error as follows in mrcnn/model.py file how can I solve

**> 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:UsersnusryDesktopparkingslot-mastercoco.py", line 56, in

from mrcnn import model as modellib, utils File "C:UsersnusryDesktopparkingslot-mastermrcnnmodel.py", line 268,
in
class ProposalLayer(KE.Layer): AttributeError: module ‘keras.engine’ has no attribute ‘Layer**

here all the import in this model file file

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

And this is line No 268 Code:

class ProposalLayer(KE.Layer):

Installed:

  Tensorflow version Version: 2.5.0
    
  Keras  Version Version: 2.2.0

Please help me to sort out

Asked By: Nusry KR

||

Answers:

You should use: keras.layers.Layer instead (KL.Layer)

Answered By: Tran Huu Hoang

Well, you are getting this error because of the compatibility issue between Tensorflow and Keras. You see under the hood Keras uses Tensorflow for various matrix manipulation.

I will recommend you to upgrade Keras and downgrade Tensorflow

 pip install keras==2.4.3

 pip install tensorflow==2.4.1

I have these versions and I was successfully able to run the code.

Keras Engine Layers Screenshot

Answered By: coderina

had the same issue, needed to change both instances of KE.Layer to KE.base_layer.Layer in the model.py file.
Works perfectly after.

Answered By: ArieAI