【问题标题】:How to save create and save submodel from keras mobilenet?如何从 keras mobilenet 保存创建和保存子模型?
【发布时间】:2019-06-21 10:52:28
【问题描述】:

我在 keras 中创建了 mobilenet v2 模型以及 lambda 函数,该函数为我提供了倒数第二层的输出。如何保存这个特定的子模型(我想用 tfjs-converter 转换它并在 tensorflow-js 中使用它)?

from keras.applications.mobilenet_v2 import MobileNetV2
model = MobileNetV2(input_shape=None, alpha=0.35, depth_multiplier=1, include_top=True, weights='imagenet', input_tensor=None, pooling=None, classes=1000)
get_3rd_layer_output = K.function([model.layers[0].input],
                                      [model.layers[-2].output])

【问题讨论】:

    标签: tensorflow keras


    【解决方案1】:

    您可以创建 Keras 模型而不是 Keras 函数,并使用 model.save(filepath) 方法保存它:

    custom_model = keras.models.Model(inputs=model.layers[0].input, 
                                      outputs=model.layers[-2].output)
    
    custom_model.save('model.h5')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-14
      • 2020-11-15
      • 2019-04-12
      • 1970-01-01
      • 2018-05-02
      • 1970-01-01
      相关资源
      最近更新 更多