Beispiel #1
0
 def test_reuse_variables_enables_flag(self):
     """reuse_variables call enable reuse flag"""
     base_scope = self.get_scope('base')
     with nn.VariableScope(reuse=False, name=base_scope):
         with nn.VariableScope(reuse=False, name='top') as vs:
             vs.reuse_variables()
             self._check_reuse(True)
Beispiel #2
0
 def test_update_scope(self):
     """VariableScope updates current variable scope"""
     scopes = [self.get_scope(suffix) for suffix in ['aaa', 'bbb', 'ccc']]
     with nn.VariableScope(reuse=False, name=scopes[0]):
         self._check_scope(scopes[0])
         with nn.VariableScope(reuse=False, name=scopes[1]):
             self._check_scope(scopes[1])
             with nn.VariableScope(reuse=False, name=scopes[2]):
                 self._check_scope(scopes[2])
Beispiel #3
0
    def test_reusing_VS_object_correctly_reset_scope(self):
        """Reusing VariableScope changes scope and flag correctly"""
        scope, reuse = self.get_scope(), False
        with nn.VariableScope(reuse=reuse, name=scope) as vs:
            pass

        with nn.VariableScope(True, 'scope_to_be_ignored'):
            with vs:
                self._check_scope(scope)
                self._check_reuse(reuse)
Beispiel #4
0
    def test_flag_reset_after_reuse_variables(self):
        """reuse_variables is not in effect after close"""
        base_scope = self.get_scope('base')
        reuse = False
        with nn.VariableScope(reuse=reuse, name=base_scope):
            with nn.VariableScope(reuse=False, name='top1') as vs:
                vs.reuse_variables()
            self._check_reuse(reuse)

        reuse = True
        with nn.VariableScope(reuse=reuse, name=base_scope):
            with nn.VariableScope(reuse=False, name='top2') as vs:
                vs.reuse_variables()
            self._check_reuse(reuse)
Beispiel #5
0
 def test_VariableScope_correctly_closes_scope(self):
     """VariableScope revert current variable scope after close"""
     scopes = [self.get_scope(scope) for scope in ['aaa', 'bbb', 'ccc']]
     for scope in scopes:
         expected_scope = be._get_scope()
         expected_reuse = be._get_flag()
         with nn.VariableScope(False, scope):
             pass
         self._check_scope(expected_scope)
         self._check_reuse(expected_reuse)
Beispiel #6
0
    def test_update_reuse_flag(self):
        """VariableScope updates current reuse flag"""
        reuse = False
        with nn.VariableScope(reuse=reuse, name=self.get_scope()):
            self._check_reuse(reuse)
            reuse = False
            with nn.VariableScope(reuse=reuse, name='scope'):
                self._check_reuse(reuse)
            reuse = True
            with nn.VariableScope(reuse=reuse, name='scope'):
                self._check_reuse(reuse)

        reuse = True
        with nn.VariableScope(reuse=reuse, name=self.get_scope()):
            self._check_reuse(reuse)
            reuse = False
            with nn.VariableScope(reuse=reuse, name='scope'):
                self._check_reuse(reuse)
                reuse = True
            with nn.VariableScope(reuse=reuse, name='scope'):
                self._check_reuse(reuse)