首页 > 解决方案 > 喀拉斯。基本模型的权重设置为“无”,但出现错误

问题描述

编码:

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',但由于某种原因,此错误并未消失。这里有什么问题?

标签: pythontensorflowkerasneural-network

解决方案


您需要删除以下的双引号None

base_model = MobileNetV2(
    include_top=False, 
    input_shape=(100, 100, 3),
    weights=None
)

推荐阅读