You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

tf.variable.cs 2.3 kB

6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*****************************************************************************
  2. Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ******************************************************************************/
  13. using System.Collections.Generic;
  14. namespace Tensorflow
  15. {
  16. public partial class tensorflow
  17. {
  18. public VariableV1[] global_variables(string scope = null)
  19. {
  20. return (ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES, scope) as List<VariableV1>)
  21. .ToArray();
  22. }
  23. public Operation global_variables_initializer()
  24. {
  25. var g = variables.global_variables();
  26. return variables.variables_initializer(g.ToArray());
  27. }
  28. public RefVariable get_variable(string name,
  29. TensorShape shape = null,
  30. TF_DataType dtype = TF_DataType.DtInvalid,
  31. object initializer = null, // IInitializer or Tensor
  32. bool? trainable = null,
  33. bool? use_resource = null,
  34. bool validate_shape = true,
  35. VariableSynchronization synchronization = VariableSynchronization.Auto,
  36. VariableAggregation aggregation = VariableAggregation.None)
  37. {
  38. var scope = Tensorflow.variable_scope.get_variable_scope();
  39. var store = Tensorflow.variable_scope._get_default_variable_store();
  40. return scope.get_variable(store,
  41. name,
  42. shape: shape,
  43. dtype: dtype,
  44. use_resource: use_resource,
  45. validate_shape: validate_shape,
  46. initializer: initializer,
  47. trainable: trainable);
  48. }
  49. }
  50. }