上下文-我在保存/加载EfficientNetB 7时遇到错误,我看到的一篇文章建议安装tf-nightly。这真的让我的Google Colab崩溃了!我卸载了tf-nightly,重新启动了我的运行时,现在当我去运行导入单元格时,我得到了下面的错误。
我重新安装了tensorflow 2.6.0。
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-25-5d853ee59f92> in <module>()
11 import tensorflow as tf
12 from tensorflow import keras
---> 13 from tensorflow.keras import Model
14 from tensorflow.keras.models import Sequential
15 from tensorflow.keras.utils import to_categorical
11 frames
/usr/local/lib/python3.7/dist-packages/keras/layers/core/dropout.py in <module>()
24
25 @keras_export('keras.layers.Dropout')
---> 26 class Dropout(base_layer.BaseRandomLayer):
27 """Applies Dropout to the input.
28
AttributeError: module 'keras.engine.base_layer' has no attribute 'BaseRandomLayer'
我以前也遇到过此导入的问题:
from tensorflow.keras import backend as keras
以下是我的所有导入:
import os
import glob
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from skimage.io import imread
from skimage.transform import resize
from sklearn.preprocessing import OneHotEncoder
from sklearn.model_selection import train_test_split
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import Model
from tensorflow.keras.models import Sequential
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.losses import categorical_crossentropy
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.layers import Dense, Flatten, Conv2D, MaxPooling2D, Dropout, BatchNormalization
from tensorflow.keras.callbacks import ModelCheckpoint, LearningRateScheduler
from datetime import datetime
from sklearn.metrics import confusion_matrix, accuracy_score, f1_score, precision_score, recall_score
import skimage.io as io
import skimage.transform as trans
from tensorflow.keras import models
from tensorflow.keras import layers
from tensorflow.keras import optimizers
from tensorflow.keras.models import *
from tensorflow.keras.layers import *
from tensorflow.keras.optimizers import *
from tensorflow.keras.callbacks import ModelCheckpoint, LearningRateScheduler
from tensorflow.keras import backend as keras
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from keras_preprocessing.image import ImageDataGenerator
from tensorflow.keras.optimizers.schedules import ExponentialDecay
import scipy.misc as sc
import h5py
from sklearn.semi_supervised import LabelSpreading
from sklearn.model_selection import GridSearchCV
from tensorflow.keras.applications import * #Efficient Net included here
import shutil
from sklearn import model_selection
from tqdm import tqdm
# import warnings
# warnings.filterwarnings("ignore", category=DeprecationWarning)
2条答案
按热度按时间sdnqo3pr1#
尝试将python版本回滚到3.6。如果使用的是Anaconda,请运行
conda install python=3.6
然后安装keras
pip install keras==2.0.8
个我在Ubuntu上用过。
utugiqy62#
安装tensorflow==2.8.0后,我能够解决这个问题。