【问题标题】:AttributeError: module 'keras.engine' has no attribute 'Layer'AttributeError:模块 'keras.engine' 没有属性 'Layer'
【发布时间】:2021-06-17 03:06:59
【问题描述】:

当我尝试运行 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] 可以 不加载动态库“cudart64_110.dll”;错误: 未找到 cudart64_110.dll 2021-06-17 08:25:18.586852:我 tensorflow/stream_executor/cuda/cudart_stub.cc:29] 忽略上面的 cudart 如果您的机器上没有设置 GPU,则会出现 dlerror。使用 TensorFlow 后端。 Traceback(最近一次通话最后一次):文件 “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**

这里是这个模型文件中所有的导入文件

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

请帮我解决

【问题讨论】:

    标签: python tensorflow machine-learning keras computer-vision


    【解决方案1】:

    嗯,由于TensorflowKeras 之间的兼容性问题,您会收到此错误。您会看到 Keras 在幕后使用 Tensorflow 进行各种矩阵操作。

    我会推荐你​​升级Keras和降级Tensorflow

     pip install keras==2.4.3
    
     pip install tensorflow==2.4.1
    

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

    【讨论】:

    • 用python 3.7就可以了
    • @Nusry 是的,没关系
    • 安装后,我在 Keras 初始化程序中收到此错误 `LOCAL.GENERATED_WITH_V2 = tf.__internal__.tf2.enabled() AttributeError: module 'tensorflow._api.v2.__internal__' has no attribute 'tf2 '`
    • @Nusry 哦,好吧,在这种情况下,你可以试试!pip install tensorflow==2.1,让我们知道它是否解决了问题
    • 谢谢。我刚刚从我的虚拟环境中删除了 Keras 文件并尝试使用您的版本它可以工作
    【解决方案2】:

    你应该改用:keras.layers.Layer (KL.Layer)

    【讨论】:

      猜你喜欢
      • 2022-11-30
      • 2018-12-13
      • 1970-01-01
      • 2021-08-26
      • 2018-04-14
      • 2019-02-18
      • 1970-01-01
      • 2020-01-01
      • 2019-07-20
      相关资源
      最近更新 更多