weights_loading_scope.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:tflearn 作者: tflearn 项目源码 文件源码
def demonstrate_loading_two_instances_of_model1():
    print("="*60 + " Demonstrate loading weights from model1 into two instances of model1 in scopeA and scopeB")
    tf.reset_default_graph()
    with tf.variable_scope("scopeA") as scope:
        m1a = Model1()
        print ("-" * 40 + " Trying to load model1 weights: should fail")
        try:
            m1a.model.load("model1.tfl", weights_only=True)
        except Exception as err:
            print ("Loading failed, with error as expected, because variables are in scopeA")
            print ("error: %s" % str(err))
        print ("-" * 40)

        print ("=" * 60 + " Trying to load model1 weights: should succeed")
        m1a.model.load("model1.tfl", scope_for_restore="scopeA", verbose=True, weights_only=True)

    with tf.variable_scope("scopeB") as scope:
        m1b = Model1()
        m1b.model.load("model1.tfl", scope_for_restore="scopeB", verbose=True, weights_only=True)
    print ("="*60 + " Successfully restored weights to two instances of model1, in different scopes")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号