DHU DeepLearning & Practice_在使用预训练模型提取特征时遇到的问题

文章目录

  • 使用的库列表
  • 问题1:cannot import name 'VGG16' from 'keras.applications'
  • 问题2:module 'keras.optimizers' has no attribute 'SGD'
  • 问题3:KeyError: 'acc'
  • 问题4:UserWarning: The 'lr' argument is deprecated, use 'learning_rate' instead

使用的库列表

tensorflow 2.7.0
keras 2.7.0

问题1:cannot import name ‘VGG16’ from ‘keras.applications’

改为from tensorflow.keras.applications import VGG16即可
输出结果:

Downloading data from https://storage.googleapis.com/tensorflow/keras-applications/vgg16/vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5
58892288/58889256 [==============================] - 50s 1us/step
58900480/58889256 [==============================] - 50s 1us/step

问题2:module ‘keras.optimizers’ has no attribute ‘SGD’

改为from tensorflow import optimizers即可

问题3:KeyError: ‘acc’

发生错误的代码:acc = history.history['acc']
改为acc = history.history['accuracy']即可

问题4:UserWarning: The ‘lr’ argument is deprecated, use ‘learning_rate’ instead

发生错误的代码:model.compile(……,optimizer=optimizers.RMSprop(lr=1e-5),……
改为model.compile(……,optimizer=optimizers.RMSprop(learning_rate=1e-5),……]即可

你可能感兴趣的:(学校课程记录,tensorflow,keras,深度学习)