gpt4 book ai didi

python - `TypeError: get_config() missing 1 required positional argument: ' self '` 尝试在 Tensorflow 中保存模型时

转载 作者:行者123 更新时间:2023-11-28 16:58:39 27 4
gpt4 key购买 nike

请帮我解决以下问题。我似乎无法保存我的模型。如您所见,我确实引用了 Sequential() 方法的实例

model = tf.keras.models.Sequential()
model.add(tf.keras.layers.InputLayer(input_shape=[timePortion,1 ]))
model.add(tf.keras.layers.Conv1D(kernel_size=timePortion,
filters=1000,
strides=1,
use_bias=False,
activation="relu",
kernel_initializer=tf.keras.initializers.VarianceScaling))
model.summary()
model.add(tf.keras.layers.Dropout(rate=0.2))
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(32,
activation='relu',
kernel_initializer=tf.keras.initializers.VarianceScaling))
model.add(tf.keras.layers.Dense(8,
activation='relu',
kernel_initializer=tf.keras.initializers.VarianceScaling))
model.add(tf.keras.layers.Dense(1,
kernel_initializer=tf.keras.initializers.VarianceScaling))
model.summary()
model.compile(optimizer=tf.keras.optimizers.Adam(lr=0.001),
loss="mean_squared_error",
metrics=["accuracy","mae"])
filepath = "model.h5"
model.fit(inputs,
labels,
steps_per_epoch=1,
epochs=2,
shuffle=False,
verbose=1)
tf.keras.models.save_model(model,
filepath,
overwrite=True,
include_optimizer=True)

我在将模型保存在 Jupyter 笔记本中时遇到问题。该文件实际上已创建,但随后出现此错误。这很奇怪,因为我正在引用模型实例。

TypeError: get_config() missing 1 required positional argument: 'self'

最佳答案

问题在于无法序列化的内核初始化程序,因为您尚未实例化它。要实例化它,请添加圆括号 ():

kernel_initializer=tf.keras.initializers.VarianceScaling()

关于python - `TypeError: get_config() missing 1 required positional argument: ' self '` 尝试在 Tensorflow 中保存模型时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55883079/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com