本文介绍了AttributeError: 模块 'keras.engine' 没有属性 'Layer'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

tensorflow/stream_executor/platform/default/dso_loader.cc:64] 可以不加载动态库cudart64_110.dll";错误:cudart64_110.dll 未找到 2021-06-17 08:25:18.586852:我tensorflow/stream_executor/cuda/cudart_stub.cc:29] 忽略cudartdlerror 如果您的机器上没有设置 GPU.使用TensorFlow 后端.回溯(最近一次通话):文件Parking_Slot_mask_rcnn.py",第 20 行,在导入 coco 文件C:\Users\nusry\Desktop\parkingslot-master\coco.py",第 56 行,在从mrcnn导入模型作为modellib,utils文件C:\Users\nusry\Desktop\parkingslot-master\mrcnn\model.py",第268行,在类 ProposalLayer(KE.Layer): AttributeError: 模块 'keras.engine' 没有属性 '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

这是第 268 行代码:

And this is line No 268 Code:

class ProposalLayer(KE.Layer):

已安装:

  Tensorflow version Version: 2.5.0
    
  Keras  Version Version: 2.2.0

请帮我整理一下

推荐答案

好吧,您收到此错误是因为 TensorflowKeras 之间的兼容性问题.你会看到Keras 使用Tensorflow 进行各种矩阵操作.

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.

我会建议你升级 Keras 和降级 Tensorflow

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.

这篇关于AttributeError: 模块 'keras.engine' 没有属性 'Layer'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 07:30