您当前的位置: 首页 >  tensorflow

Better Bench

暂无认证

  • 2浏览

    0关注

    695博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【Tensorflow+keras】解决使用model.load_weights时报错 ‘str‘ object has no attribute ‘decode‘

Better Bench 发布时间:2021-06-14 16:09:19 ,浏览量:2

1 环境

python 3.6 Tensorflow 2.0

在使用Tensorflow 的keras API,加载权重模型时,报错’str’ object has no attribute ‘decode’

from tensorflow.keras import *
from tensorflow.keras.layers import * 

model = testmodel()
model = Model(model.input, Dense(1, activation='linear', kernel_initializer='normal')(model.layers[-2].output))

checkpoint = callbacks.ModelCheckpoint('current_best.h5')
history = model.fit_generator(
            training_gen(1000, SNRdb),
            steps_per_epoch=50,
            epochs=500,
            validation_data=validation_gen(1000, SNRdb),
            validation_steps=1,
            callbacks=[checkpoint],
            verbose=2)
model = model.load_weights('current_best.h5')

2 解决办法

在保存模型的时候,模型格式为.tf

checkpoint = callbacks.ModelCheckpoint('current_best.tf',save_format='tf')

加载模型的时,改为

model = model.load_weights('current_best.tf')
关注
打赏
1665674626
查看更多评论
立即登录/注册

微信扫码登录

0.0410s