Jadeeeeeeeeeee 2022-11-22 12:20
浏览 2
已结题

报错了,深度学习python3.9+tensorflow2.8+keras2.8尝试猫狗分类的例子,可是报错了报错了,到处查试了好多还是不知道怎么搞,求指导

初学深度学习用猫狗分类的例子自己敲代码试试,可是报错了报错了,到处查试了好多还是不知道怎么搞,求指导
初学,想照着猫狗分类那个简单的例子先自己敲一遍代码试试,然后刚开始就卒了。哭
from tensorflow import keras
from keras import layers
from keras import models

model = models.Sequential()
model.add(layers.Conv2D(32, (3,3), activation = "relu", input_shape = (150,150,3)))
model.add(layers.MaxPooling2D((2,2)))
model.add(layers.Conv2D(64, (3,3), activation = "relu"))
model.add(layers.MaxPooling2D((2,2)))
model.add(layers.Conv2D(128, (3,3), activation = "relu"))
model.add(layers.MaxPooling2D((2,2)))
model.add(layers.Conv2D(128, (3,3), activation = "relu"))
model.add(layers.MaxPooling2D((2,2)))
model.add(layers.Flatten())
model.add(layers.Dense(512, activation = "relu"))
model.add(layers.Dense(1, activation = "sigmoid"))
model.summary()

下面是这个报错,我也确实没咋看明白。哭
AttributeError                            Traceback (most recent call last)
Input In [13], in <cell line: 2>()
      1 from tensorflow import keras
----> 2 from keras import layers
      3 from keras import models
      5 model = keras.models.Sequential()

File ~\anaconda3\lib\site-packages\keras\__init__.py:25, in <module>
     22 from keras import distribute
     24 # See b/110718070#comment18 for more details about this import.
---> 25 from keras import models
     27 from keras.engine.input_layer import Input
     28 from keras.engine.sequential import Sequential

File ~\anaconda3\lib\site-packages\keras\models.py:20, in <module>
     18 import tensorflow.compat.v2 as tf
     19 from keras import backend
---> 20 from keras import metrics as metrics_module
     21 from keras import optimizer_v1
     22 from keras.engine import functional

File ~\anaconda3\lib\site-packages\keras\metrics.py:26, in <module>
     23 import warnings
     25 import numpy as np
---> 26 from keras import activations
     27 from keras import backend
     28 from keras.engine import base_layer

File ~\anaconda3\lib\site-packages\keras\activations.py:20, in <module>
     17 import tensorflow.compat.v2 as tf
     19 from keras import backend
---> 20 from keras.layers import advanced_activations
     21 from keras.utils.generic_utils import deserialize_keras_object
     22 from keras.utils.generic_utils import serialize_keras_object

File ~\anaconda3\lib\site-packages\keras\layers\__init__.py:31, in <module>
     28 from keras.engine.base_preprocessing_layer import PreprocessingLayer
     30 # Image preprocessing layers.
---> 31 from keras.layers.preprocessing.image_preprocessing import CenterCrop
     32 from keras.layers.preprocessing.image_preprocessing import RandomCrop
     33 from keras.layers.preprocessing.image_preprocessing import RandomFlip

File ~\anaconda3\lib\site-packages\keras\layers\preprocessing\image_preprocessing.py:24, in <module>
     22 from keras.engine import base_layer
     23 from keras.engine import base_preprocessing_layer
---> 24 from keras.preprocessing import image as image_preprocessing
     25 from keras.utils import control_flow_util
     26 from tensorflow.python.ops import stateless_random_ops

File ~\anaconda3\lib\site-packages\keras\preprocessing\__init__.py:26, in <module>
     24 from keras.preprocessing import text
     25 from keras.preprocessing import timeseries
---> 26 from keras.utils import all_utils as utils
     28 # This exists for compatibility with prior version of keras_preprocessing.
     29 keras_preprocessing.set_keras_submodules(backend=backend, utils=utils)

File ~\anaconda3\lib\site-packages\keras\utils\all_utils.py:34, in <module>
     32 from keras.utils.generic_utils import serialize_keras_object
     33 from keras.utils.layer_utils import get_source_inputs
---> 34 from keras.utils.multi_gpu_utils import multi_gpu_model
     35 from keras.utils.np_utils import normalize
     36 from keras.utils.np_utils import to_categorical

File ~\anaconda3\lib\site-packages\keras\utils\multi_gpu_utils.py:20, in <module>
     18 from keras import backend
     19 from keras.engine.training import Model
---> 20 from keras.layers.core import Lambda
     21 from keras.layers.merge import concatenate
     24 def _get_available_devices():

File ~\anaconda3\lib\site-packages\keras\layers\core\__init__.py:20, in <module>
     18 from keras.layers.core.activity_regularization import ActivityRegularization
     19 from keras.layers.core.dense import Dense
---> 20 from keras.layers.core.dropout import Dropout
     21 from keras.layers.core.flatten import Flatten
     22 from keras.layers.core.lambda_layer import Lambda

File ~\anaconda3\lib\site-packages\keras\layers\core\dropout.py:26, in <module>
     21 import tensorflow.compat.v2 as tf
     22 from tensorflow.python.util.tf_export import keras_export
     25 @keras_export('keras.layers.Dropout')
---> 26 class Dropout(base_layer.BaseRandomLayer):
     27   """Applies Dropout to the input.
     28 
     29   The Dropout layer randomly sets input units to 0 with a frequency of `rate`
   (...)
     74       training mode (adding dropout) or in inference mode (doing nothing).
     75   """
     77   def __init__(self, rate, noise_shape=None, seed=None, **kwargs):

AttributeError: module 'keras.engine.base_layer' has no attribute 'BaseRandomLayer'


我自己搜了下,感觉这个报错网上大多说是tensorflow和keras版本不对,我就查了下我自己安装的版本,python3.9,tensorflow2.8,keras2.8,感觉好像也没搜到说不行的,大部分说的版本对应最多就到tensorflow2.7了,没找到说2.8的,然后我试了试改一下import的部分,比如加了一句from tensorflow import keras之类的,或者试了试tf.keras.model.什么,还是一样的报错,不知道是版本的问题还是我import写错了,或者是下面的代码不对
我应该怎么弄现在,是要降tensorflow或者keras的版本吗,还是只是版本没问题,只是我哪里写错了呀
  • 写回答

0条回答

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

      • 系统已结题 11月30日
      • 创建了问题 11月22日

      悬赏问题

      • ¥15 Java的运用111111111111
      • ¥15 koa2 + ts 声明文件不生效
      • ¥15 Mac系统word显示此文档已被删除或当前无法访问.
      • ¥15 Unity用代码实现Tilemap
      • ¥15 怎么求广播地址以及网络地址?
      • ¥15 想知道unity如何实现物体贴地运动
      • ¥15 从A地到B地有多条路径可以到达,现要从A地到B地运物资问题
      • ¥30 用java设计小游戏扑克牌比大小,52张牌的图片选世界篮球明星图或其它都行
      • ¥15 ATM管理员功能代码及解释
      • ¥15 EasyExcel导出下载文件响应流为空