예제 #1
0
        public variable_scope(VariableScope scope,
                              string default_name       = "",
                              Tensor[] values           = null,
                              bool?reuse                = null,
                              bool auxiliary_name_scope = true)
        {
            _scope              = scope;
            _default_name       = default_name;
            _values             = values;
            _current_name_scope = null;
            _reuse              = reuse;
            _use_resource       = false;
            if (_default_name == null && _scope == null)
            {
                throw new TypeError("If default_name is None then scope is required");
            }

            if (_values == null)
            {
                _values = new Tensor[0];
            }
            _in_graph_mode = true;
            if (_in_graph_mode)
            {
                _graph = ops._get_graph_from_inputs(_values);
            }
            _auxiliary_name_scope = auxiliary_name_scope;
        }
예제 #2
0
        public variable_scope(string name,
                              string default_name       = "",
                              Tensor[] values           = null,
                              bool?reuse                = null,
                              bool auxiliary_name_scope = true)
        {
            _name               = name;
            _default_name       = default_name;
            _values             = values;
            _current_name_scope = null;
            _reuse              = reuse;
            _use_resource       = false;
            if (_default_name == null && _name == null)
            {
                throw new TypeError("If default_name is None then name is required");
            }

            _auxiliary_name_scope = auxiliary_name_scope;
        }
예제 #3
0
        private VariableScope _enter_scope_uncached()
        {
            ops.NameScope     current_name_scope;
            PureVariableScope pure_variable_scope = null;
            VariableScope     entered_pure_variable_scope;

            if (_auxiliary_name_scope)
            {
                // Create a new name scope later
                current_name_scope = null;
            }
            else
            {
                // Reenter the current name scope
                string name_scope = ops.get_name_scope();
                if (!string.IsNullOrEmpty(name_scope))
                {
                    // Hack to reenter
                    name_scope += "/";
                }
                current_name_scope = ops.name_scope(name_scope);
            }

            if (!string.IsNullOrEmpty(_name) || _scope != null)
            {
                var name_scope = _scope == null ? _name : _scope.name.Split('/').Last();
                if (current_name_scope == null)
                {
                    current_name_scope = ops.name_scope(name_scope);
                }
                current_name_scope.__enter__();
                string current_name_scope_name = current_name_scope;
                _current_name_scope = current_name_scope;
                string old_name_scope = _scope == null ? current_name_scope_name : _scope.original_name_scope;

                if (_scope == null)
                {
                    pure_variable_scope = new PureVariableScope(_name, old_name_scope: old_name_scope);
                }
                else
                {
                    pure_variable_scope = new PureVariableScope(_scope, old_name_scope: old_name_scope);
                }
                pure_variable_scope.__enter__();
                entered_pure_variable_scope = pure_variable_scope;
                _cached_pure_variable_scope = pure_variable_scope;
                return(entered_pure_variable_scope);
            }
            else
            {
                current_name_scope = ops.name_scope(_default_name);
                current_name_scope.__enter__();
                string current_name_scope_name = current_name_scope;
                _current_name_scope = current_name_scope;
                string unique_default_name = _get_unique_variable_scope(_default_name);
                pure_variable_scope = new PureVariableScope(unique_default_name,
                                                            old_name_scope: current_name_scope_name);
                pure_variable_scope.__enter__();
                entered_pure_variable_scope = pure_variable_scope;
                _cached_pure_variable_scope = pure_variable_scope;
                return(entered_pure_variable_scope);
            }
        }