python - 喀拉斯。基本模型的权重设置为“无”,但出现错误
问题描述
编码:
from tensorflow.keras.applications import MobileNetV2
from tensorflow.keras.layers import Dense
base_model = MobileNetV2(
include_top=False,
input_shape=(100, 100, 3),
weights="None",
)
layer = Dense(256, activation='relu')(base_model.output)
out = Dense(28)(layer)
model = Model(base_model.input, out)
这段代码会导致错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-190-5cf5e34e46ca> in <module>
9 include_top=False,
10 input_shape=(128, 128, 3),
---> 11 weights="None",
12 )
13
ValueError: The `weights` argument should be either `None` (random initialization), `imagenet` (pre-training on ImageNet), or the path to the weights file to be loaded.
如您所见,weights
已设置为'None'
,但由于某种原因,此错误并未消失。这里有什么问题?
解决方案
您需要删除以下的双引号None
:
base_model = MobileNetV2(
include_top=False,
input_shape=(100, 100, 3),
weights=None
)
推荐阅读
- linux - Linux读取外盘数据,无法挂载
- node.js - 使用相同的 package.json 文件定义多运行配置
- cordova - Cordova 支持 finally 方法吗?
- php - PHP登录页面为空白而不是回显结果
- mysql - 使用 MySQL 配置 ejabberd 时出错
- php - 连接已重置 - 加载样式表
- python-3.x - 从python中的列表创建可能的数字
- python - 试图从新的顶部反转帖子,但我在 Flask 中不断收到错误
- javascript - Gulp webpack 只加载 jquery 一次
- django - Django:python manage.py migrate --noinput