【问题标题】:How to "Iterate" on Computer Vision machine learning model?如何“迭代”计算机视觉机器学习模型?
【发布时间】:2019-10-03 13:54:35
【问题描述】:

我使用 google cloud vision api 创建了一个模型。我花了无数个小时标记数据,并训练了一个模型。在将近 20 小时的“训练”模型结束时,它仍然是一波三折。

如何迭代这个模型?我不想失去迄今为止所做的“学习”。它的工作效率约为 3/5 次。

我最好的猜测是我应该再次遍历对象,找到错误的地方,并相应地标记。但我不确定最好的方法。我应该将所有“错过”的图像标记为测试数据图像吗?我可以阅读有关此主题的最佳做法或资源吗?

【问题讨论】:

    标签: opencv tensorflow google-cloud-platform google-vision vision-api


    【解决方案1】:

    我绝不是专家,但以下是我的建议,按最重要到最不重要的顺序排列:

    1) 如果可能,添加更多数据。更多数据总是一件好事,有助于提高网络预测的稳健性。

    2) Add dropout layers to prevent over-fitting

    3) 修改kernel and bias initialisers

    4) [与您的问题最相关的答案] 保存模型的训练权重并在训练前将它们重新加载到新模型中。

    5) 更改您正在使用的模型架构类型。然后,修改 epoch 数、验证拆分、损失评估公式等。

    希望这会有所帮助!


    编辑:关于数字 4 的更多信息

    因此,您可以在模型训练期间或之后保存和加载模型权重。 See here 了解有关保存的更深入信息。

    概括地说,让我们介绍一下基础知识。我假设您正在使用 keras,但同样适用于 tf:

    训练后保存模型

    只需调用:

    model_json = model.to_json()
    with open("{Your_Model}.json", "w") as json_file:
        json_file.write(model_json)
    
    # serialize weights to HDF5
    model.save_weights("{Your_Model}.h5")
    print("Saved model to disk")
    

    加载模型

    您可以像这样从 json 加载模型结构:

    from keras.models import model_from_json 
    
    json_file = open('{Your_Model.json}', 'r')
    loaded_model_json = json_file.read()
    json_file.close()
    model = model_from_json(loaded_model_json)
    

    如果您愿意,还可以加载权重:

    model.load_weights('{Your_Weights}.h5', by_name=True)
    

    然后编译模型,您就可以重新训练/预测了。 by_name 对我来说是将权重重新加载到相同的模型架构中必不可少的;忽略它可能会导致错误。

    在训练期间检查模型

    cp_callback = tf.keras.callbacks.ModelCheckpoint(filepath={checkpoint_path},
                                                     save_weights_only=True,
                                                     verbose=1)
    
    # Train the model with the new callback
    model.fit(train_images, 
              train_labels,  
              epochs=10,
              validation_data=(test_images,test_labels),
              callbacks=[cp_callback])  # Pass callback to training
    

    【讨论】:

    • 我特别好奇怎么做4
    • 当然,你去!编辑了我的答案。
    • @thisguy123 请注意:加载先前模型的权重有点像引导程序,但您不想过度训练网络。密切关注您的损失/准确性指标。我发现更改验证指标 + 内核偏差初始值对我也有很大帮助。
    猜你喜欢
    • 1970-01-01
    • 2013-09-29
    • 1970-01-01
    • 2020-04-28
    • 2012-03-25
    • 1970-01-01
    • 2010-12-04
    • 1970-01-01
    • 2023-03-11
    相关资源
    最近更新 更多