| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cb7e017 commit 8dd1eec
16 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,10 +13,8 @@ public class MnistModelLoader : IModelLoader<MnistDataSet> | |||
| 13 | 13 | private const string TEST_IMAGES = "t10k-images-idx3-ubyte.gz"; | |
| 14 | 14 | private const string TEST_LABELS = "t10k-labels-idx1-ubyte.gz"; | |
| 15 | 15 | ||
| 16 | - public static async Task<Datasets<MnistDataSet>> LoadAsync(string trainDir, bool oneHot = false, int? trainSize = null, int? validationSize = null, int? testSize = null, bool showProgressInConsole = false) | ||
| 16 | + public async Task<Datasets<MnistDataSet>> LoadAsync(string trainDir, bool oneHot = false, int? trainSize = null, int? validationSize = null, int? testSize = null, bool showProgressInConsole = false) | ||
| 17 | 17 | { | |
| 18 | - var loader = new MnistModelLoader(); | ||
| 19 | - | ||
| 20 | 18 | var setting = new ModelLoadSetting | |
| 21 | 19 | { | |
| 22 | 20 | TrainDir = trainDir, | |
@@ -33,7 +31,7 @@ public static async Task<Datasets<MnistDataSet>> LoadAsync(string trainDir, bool | |||
| 33 | 31 | if (testSize.HasValue) | |
| 34 | 32 | setting.TestSize = testSize.Value; | |
| 35 | 33 | ||
| 36 | - return await loader.LoadAsync(setting); | ||
| 34 | + return await LoadAsync(setting); | ||
| 37 | 35 | } | |
| 38 | 36 | ||
| 39 | 37 | public async Task<Datasets<MnistDataSet>> LoadAsync(ModelLoadSetting setting) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,7 +42,7 @@ public Tensor[] TFE_ExecuteCancelable(Context ctx, | |||
| 42 | 42 | int num_outputs) | |
| 43 | 43 | { | |
| 44 | 44 | var status = tf.Status; | |
| 45 | - using var op = GetOp(ctx, op_name, status); | ||
| 45 | + var op = GetOp(ctx, op_name, status); | ||
| 46 | 46 | c_api.TFE_OpSetDevice(op, device_name, status.Handle); | |
| 47 | 47 | if (status.ok()) | |
| 48 | 48 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,9 @@ namespace Tensorflow.Eager | |||
| 15 | 15 | /// </summary> | |
| 16 | 16 | public partial class EagerRunner | |
| 17 | 17 | { | |
| 18 | - UnorderedMap<Context, SafeOpHandle> thread_local_eager_operation_map = new UnorderedMap<Context, SafeOpHandle>(); | ||
| 18 | + UnorderedMap<string, SafeOpHandle> thread_local_eager_operation_map = new UnorderedMap<string, SafeOpHandle>(); | ||
| 19 | + public void ClearEagerOperationMap() | ||
| 20 | + => thread_local_eager_operation_map.Clear(); | ||
| 19 | 21 | ||
| 20 | 22 | public Tensor[] TFE_FastPathExecute(FastPathOpExecInfo op_exec_info) | |
| 21 | 23 | { | |
@@ -31,7 +33,7 @@ public Tensor[] TFE_FastPathExecute(FastPathOpExecInfo op_exec_info) | |||
| 31 | 33 | op_exec_info.run_callbacks = op_exec_info.run_gradient_callback || op_exec_info.run_post_exec_callbacks; | |
| 32 | 34 | ||
| 33 | 35 | var status = tf.Status; | |
| 34 | - using var op = GetOp(op_exec_info.ctx, op_exec_info.op_name, status); | ||
| 36 | + var op = GetOp(op_exec_info.ctx, op_exec_info.op_name, status); | ||
| 35 | 37 | ||
| 36 | 38 | var op_def = tf.get_default_graph().GetOpDef(op_exec_info.op_name); | |
| 37 | 39 | ||
@@ -56,8 +58,8 @@ public Tensor[] TFE_FastPathExecute(FastPathOpExecInfo op_exec_info) | |||
| 56 | 58 | } | |
| 57 | 59 | } | |
| 58 | 60 | ||
| 59 | - c_api.TFE_OpSetDevice(op, op_exec_info.device_name, status.Handle); | ||
| 60 | - status.Check(true); | ||
| 61 | + // c_api.TFE_OpSetDevice(op, op_exec_info.device_name, status.Handle); | ||
| 62 | + // status.Check(true); | ||
| 61 | 63 | ||
| 62 | 64 | // Add inferred attrs and inputs. | |
| 63 | 65 | for (int i = 0; i < op_def.InputArg.Count; i++) | |
@@ -145,7 +147,6 @@ public Tensor[] TFE_FastPathExecute(FastPathOpExecInfo op_exec_info) | |||
| 145 | 147 | ||
| 146 | 148 | var flat_result = retVals.Select(x => new EagerTensor(x)).ToArray(); | |
| 147 | 149 | ||
| 148 | - | ||
| 149 | 150 | if (op_exec_info.run_callbacks) | |
| 150 | 151 | { | |
| 151 | 152 | RunCallbacks(op_exec_info, | |
@@ -158,19 +159,19 @@ public Tensor[] TFE_FastPathExecute(FastPathOpExecInfo op_exec_info) | |||
| 158 | 159 | ||
| 159 | 160 | SafeOpHandle GetOp(Context ctx, string op_or_function_name, Status status) | |
| 160 | 161 | { | |
| 161 | - /*if (thread_local_eager_operation_map.find(ctx, out var op)) | ||
| 162 | + if (thread_local_eager_operation_map.find(op_or_function_name, out var op)) | ||
| 162 | 163 | c_api.TFE_OpReset(op, op_or_function_name, ctx.DeviceName, status.Handle); | |
| 163 | 164 | else | |
| 164 | 165 | { | |
| 165 | 166 | op = c_api.TFE_NewOp(ctx.Handle, op_or_function_name, status.Handle); | |
| 166 | - thread_local_eager_operation_map[ctx] = op; | ||
| 167 | + thread_local_eager_operation_map[op_or_function_name] = op; | ||
| 167 | 168 | } | |
| 168 | 169 | ||
| 169 | - status.Check(true); | ||
| 170 | - return op;*/ | ||
| 171 | - var op = c_api.TFE_NewOp(ctx.Handle, op_or_function_name, status.Handle); | ||
| 172 | 170 | status.Check(true); | |
| 173 | 171 | return op; | |
| 172 | + /*var op = c_api.TFE_NewOp(ctx.Handle, op_or_function_name, status.Handle); | ||
| 173 | + status.Check(true); | ||
| 174 | + return op;*/ | ||
| 174 | 175 | } | |
| 175 | 176 | ||
| 176 | 177 | bool HasAccumulator() | |
@@ -268,16 +269,7 @@ void SetOpAttrWithDefaults(Context ctx, SafeOpHandle op, AttrDef attr, | |||
| 268 | 269 | ||
| 269 | 270 | if (attr_value == null) | |
| 270 | 271 | { | |
| 271 | - if (is_list != 0) | ||
| 272 | - #pragma warning disable CS0642 // Possible mistaken empty statement | ||
| 273 | - ; | ||
| 274 | - #pragma warning restore CS0642 // Possible mistaken empty statement | ||
| 275 | - //SetOpAttrListDefault | ||
| 276 | - else | ||
| 277 | - #pragma warning disable CS0642 // Possible mistaken empty statement | ||
| 278 | - ; | ||
| 279 | - #pragma warning restore CS0642 // Possible mistaken empty statement | ||
| 280 | - //SetOpAttrScalarDefault | ||
| 272 | + | ||
| 281 | 273 | } | |
| 282 | 274 | else | |
| 283 | 275 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,5 +39,7 @@ bool RecordGradient(string op_name, | |||
| 39 | 39 | bool MustRecordGradient(); | |
| 40 | 40 | ||
| 41 | 41 | int TapeSetPossibleGradientTypes(params Tensor[] args); | |
| 42 | + | ||
| 43 | + void ClearEagerOperationMap(); | ||
| 42 | 44 | } | |
| 43 | 45 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,14 +44,14 @@ bool _shape_is_compatible_0dim(Shape _this, Shape _other) | |||
| 44 | 44 | return true; | |
| 45 | 45 | } | |
| 46 | 46 | ||
| 47 | - if (other.IsSparseTensor) | ||
| 47 | + if (other is SparseTensor) | ||
| 48 | 48 | { | |
| 49 | 49 | return self.dtype.is_compatible_with(other.dtype); | |
| 50 | 50 | } | |
| 51 | 51 | ||
| 52 | 52 | return self.dtype.is_compatible_with(other.dtype) && | |
| 53 | 53 | _shape_is_compatible_0dim(self.shape, other.shape) && | |
| 54 | - !self.IsSparseTensor; | ||
| 54 | + !(self is SparseTensor); | ||
| 55 | 55 | } | |
| 56 | 56 | ||
| 57 | 57 | public static Dimension dimension_at_index(Shape shape, int index) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,10 +30,6 @@ namespace Tensorflow | |||
| 30 | 30 | public class BaseSession : DisposableObject | |
| 31 | 31 | { | |
| 32 | 32 | protected Graph _graph; | |
| 33 | - protected bool _opened; | ||
| 34 | - protected bool _closed; | ||
| 35 | - protected int _current_version; | ||
| 36 | - protected byte[] _target; | ||
| 37 | 33 | public Graph graph => _graph; | |
| 38 | 34 | ||
| 39 | 35 | public BaseSession(IntPtr handle, Graph g) | |
@@ -46,18 +42,15 @@ public BaseSession(string target = "", Graph g = null, ConfigProto config = null | |||
| 46 | 42 | { | |
| 47 | 43 | _graph = g ?? ops.get_default_graph(); | |
| 48 | 44 | if (!_graph.building_function) | |
| 49 | - _graph.as_default(); | ||
| 50 | - _target = Encoding.UTF8.GetBytes(target); | ||
| 51 | - | ||
| 52 | - using (var opts = new SessionOptions(target, config)) | ||
| 53 | 45 | { | |
| 54 | - lock (Locks.ProcessWide) | ||
| 55 | - { | ||
| 56 | - status = status ?? new Status(); | ||
| 57 | - _handle = c_api.TF_NewSession(_graph, opts.Handle, status.Handle); | ||
| 58 | - status.Check(true); | ||
| 59 | - } | ||
| 46 | + if (ops.get_default_graph() != _graph) | ||
| 47 | + _graph.as_default(); | ||
| 60 | 48 | } | |
| 49 | + | ||
| 50 | + using var opts = new SessionOptions(target, config); | ||
| 51 | + status = status ?? tf.Status; | ||
| 52 | + _handle = c_api.TF_NewSession(_graph, opts.Handle, status.Handle); | ||
| 53 | + status.Check(true); | ||
| 61 | 54 | } | |
| 62 | 55 | ||
| 63 | 56 | public virtual void run(Operation op, params FeedItem[] feed_dict) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,80 +26,6 @@ namespace Tensorflow | |||
| 26 | 26 | [SuppressMessage("ReSharper", "InvokeAsExtensionMethod")] | |
| 27 | 27 | public partial class Tensor | |
| 28 | 28 | { | |
| 29 | - public unsafe void CopyTo(NDArray nd) | ||
| 30 | - { | ||
| 31 | - //if (!nd.Shape.IsContiguous) | ||
| 32 | - //throw new ArgumentException("NDArray has to be contiguous (ndarray.Shape.IsContiguous)."); | ||
| 33 | - | ||
| 34 | - var length = (int)(nd.size * nd.dtypesize); | ||
| 35 | - | ||
| 36 | - switch (nd.dtype) | ||
| 37 | - { | ||
| 38 | - /*case NumpyDType.Boolean: | ||
| 39 | - { | ||
| 40 | - CopyTo(new Span<bool>(nd.Address.ToPointer(), length)); | ||
| 41 | - break; | ||
| 42 | - } | ||
| 43 | - case NumpyDType.Byte: | ||
| 44 | - { | ||
| 45 | - CopyTo(new Span<byte>(nd.Address.ToPointer(), length)); | ||
| 46 | - break; | ||
| 47 | - } | ||
| 48 | - case NumpyDType.Int16: | ||
| 49 | - { | ||
| 50 | - CopyTo(new Span<short>(nd.Address.ToPointer(), length)); | ||
| 51 | - break; | ||
| 52 | - } | ||
| 53 | - case NumpyDType.UInt16: | ||
| 54 | - { | ||
| 55 | - CopyTo(new Span<ushort>(nd.Address.ToPointer(), length)); | ||
| 56 | - break; | ||
| 57 | - } | ||
| 58 | - case NumpyDType.Int32: | ||
| 59 | - { | ||
| 60 | - CopyTo(new Span<int>(nd.Address.ToPointer(), length)); | ||
| 61 | - break; | ||
| 62 | - } | ||
| 63 | - case NumpyDType.UInt32: | ||
| 64 | - { | ||
| 65 | - CopyTo(new Span<uint>(nd.Address.ToPointer(), length)); | ||
| 66 | - break; | ||
| 67 | - } | ||
| 68 | - case NumpyDType.Int64: | ||
| 69 | - { | ||
| 70 | - CopyTo(new Span<long>(nd.Address.ToPointer(), length)); | ||
| 71 | - break; | ||
| 72 | - } | ||
| 73 | - case NumpyDType.UInt64: | ||
| 74 | - { | ||
| 75 | - CopyTo(new Span<ulong>(nd.Address.ToPointer(), length)); | ||
| 76 | - break; | ||
| 77 | - } | ||
| 78 | - case NumpyDType.Char: | ||
| 79 | - { | ||
| 80 | - CopyTo(new Span<char>(nd.Address.ToPointer(), length)); | ||
| 81 | - break; | ||
| 82 | - } | ||
| 83 | - case NumpyDType.Double: | ||
| 84 | - { | ||
| 85 | - CopyTo(new Span<double>(nd.Address.ToPointer(), length)); | ||
| 86 | - break; | ||
| 87 | - } | ||
| 88 | - case NumpyDType.Single: | ||
| 89 | - { | ||
| 90 | - CopyTo(new Span<float>(nd.Address.ToPointer(), length)); | ||
| 91 | - break; | ||
| 92 | - }*/ | ||
| 93 | - default: | ||
| 94 | - throw new NotSupportedException(); | ||
| 95 | - } | ||
| 96 | - } | ||
| 97 | - | ||
| 98 | - public void CopyTo<T>(Span<T> destination) where T : unmanaged | ||
| 99 | - { | ||
| 100 | - throw new NotImplementedException(""); | ||
| 101 | - } | ||
| 102 | - | ||
| 103 | 29 | public TensorSpec ToTensorSpec() | |
| 104 | 30 | => new TensorSpec(shape, dtype, name); | |
| 105 | 31 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,7 +32,7 @@ public partial class Tensor | |||
| 32 | 32 | ||
| 33 | 33 | public Tensor() | |
| 34 | 34 | { | |
| 35 | - isCreatedInGraphMode = !tf.executing_eagerly(); | ||
| 35 | + _isCreatedInGraphMode = !tf.executing_eagerly(); | ||
| 36 | 36 | } | |
| 37 | 37 | ||
| 38 | 38 | /// <summary> | |
@@ -45,7 +45,7 @@ public unsafe Tensor(SafeTensorHandle handle, bool clone = false) | |||
| 45 | 45 | if (clone && handle != null) | |
| 46 | 46 | _handle = TF_NewTensor(shape, dtype, data: TensorDataPointer.ToPointer()); | |
| 47 | 47 | ||
| 48 | - isCreatedInGraphMode = !tf.executing_eagerly(); | ||
| 48 | + _isCreatedInGraphMode = !tf.executing_eagerly(); | ||
| 49 | 49 | } | |
| 50 | 50 | ||
| 51 | 51 | /// <summary> | |
@@ -59,13 +59,13 @@ public unsafe Tensor(SafeTensorHandle handle, bool clone = false) | |||
| 59 | 59 | public unsafe Tensor(IntPtr data_ptr, Shape shape, TF_DataType dtype) | |
| 60 | 60 | { | |
| 61 | 61 | _handle = TF_NewTensor(shape, dtype, data: data_ptr.ToPointer()); | |
| 62 | - isCreatedInGraphMode = !tf.executing_eagerly(); | ||
| 62 | + _isCreatedInGraphMode = !tf.executing_eagerly(); | ||
| 63 | 63 | } | |
| 64 | 64 | ||
| 65 | 65 | public unsafe Tensor(NDArray nd) | |
| 66 | 66 | { | |
| 67 | 67 | _handle = TF_NewTensor(nd.shape, nd.dtype, nd.data.ToPointer()); | |
| 68 | - isCreatedInGraphMode = !tf.executing_eagerly(); | ||
| 68 | + _isCreatedInGraphMode = !tf.executing_eagerly(); | ||
| 69 | 69 | } | |
| 70 | 70 | ||
| 71 | 71 | #region scala | |
@@ -107,13 +107,13 @@ public Tensor(Operation op, int value_index, TF_DataType dtype) | |||
| 107 | 107 | _value_index = value_index; | |
| 108 | 108 | _override_dtype = dtype; | |
| 109 | 109 | _id = ops.uid(); | |
| 110 | - isCreatedInGraphMode = !tf.executing_eagerly(); | ||
| 110 | + _isCreatedInGraphMode = !tf.executing_eagerly(); | ||
| 111 | 111 | } | |
| 112 | 112 | ||
| 113 | 113 | protected unsafe void InitTensor(Shape shape, TF_DataType dtype) | |
| 114 | 114 | { | |
| 115 | 115 | _handle = TF_NewTensor(shape, dtype, null); | |
| 116 | - isCreatedInGraphMode = !tf.executing_eagerly(); | ||
| 116 | + _isCreatedInGraphMode = !tf.executing_eagerly(); | ||
| 117 | 117 | } | |
| 118 | 118 | ||
| 119 | 119 | protected unsafe void InitTensor(Shape shape, byte[] bytes, TF_DataType dtype) | |
@@ -122,12 +122,12 @@ protected unsafe void InitTensor(Shape shape, byte[] bytes, TF_DataType dtype) | |||
| 122 | 122 | _handle = StringTensor(new byte[][] { bytes }, Shape.Scalar); | |
| 123 | 123 | else | |
| 124 | 124 | _handle = TF_NewTensor(bytes, shape, dtype); | |
| 125 | - isCreatedInGraphMode = !tf.executing_eagerly(); | ||
| 125 | + _isCreatedInGraphMode = !tf.executing_eagerly(); | ||
| 126 | 126 | } | |
| 127 | 127 | ||
| 128 | 128 | protected unsafe void InitTensor(Array array, Shape? shape = null) | |
| 129 | 129 | { | |
| 130 | - isCreatedInGraphMode = !tf.executing_eagerly(); | ||
| 130 | + _isCreatedInGraphMode = !tf.executing_eagerly(); | ||
| 131 | 131 | ||
| 132 | 132 | shape = shape ?? array.GetShape(); | |
| 133 | 133 | var dtype = array.GetDataType(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,11 +17,8 @@ limitations under the License. | |||
| 17 | 17 | using Tensorflow.NumPy; | |
| 18 | 18 | using System; | |
| 19 | 19 | using System.Diagnostics.CodeAnalysis; | |
| 20 | - using System.Globalization; | ||
| 21 | 20 | using System.Linq; | |
| 22 | - using System.Runtime.InteropServices; | ||
| 23 | 21 | using Tensorflow.Eager; | |
| 24 | - using Tensorflow.Framework; | ||
| 25 | 22 | using Tensorflow.Keras.Engine; | |
| 26 | 23 | using static Tensorflow.Binding; | |
| 27 | 24 | ||
@@ -97,12 +94,9 @@ public partial class Tensor : DisposableObject, | |||
| 97 | 94 | /// </summary> | |
| 98 | 95 | public SafeTensorHandleHandle EagerTensorHandle => _eagerTensorHandle; | |
| 99 | 96 | ||
| 100 | - protected bool isCreatedInGraphMode; | ||
| 97 | + protected bool _isCreatedInGraphMode; | ||
| 101 | 98 | ||
| 102 | - public bool IsCreatedInGraphMode => isCreatedInGraphMode; | ||
| 103 | - public bool IsSparseTensor => this is SparseTensor; | ||
| 104 | - | ||
| 105 | - public Tensor TensorShape => tf.shape(this); | ||
| 99 | + public bool IsCreatedInGraphMode => _isCreatedInGraphMode; | ||
| 106 | 100 | ||
| 107 | 101 | /// <summary> | |
| 108 | 102 | /// Returns the shape of a tensor. | |
@@ -157,7 +151,6 @@ public int[] _shape_tuple() | |||
| 157 | 151 | /// Keras History: (Layer, (node_index, tensor_index)) | |
| 158 | 152 | /// </summary> | |
| 159 | 153 | public KerasHistory KerasHistory { get; set; } | |
| 160 | - public Tensor KerasMask { get; set; } | ||
| 161 | 154 | ||
| 162 | 155 | /// <summary> | |
| 163 | 156 | /// Updates the shape of this tensor. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -383,6 +383,9 @@ public static int uid_layer() | |||
| 383 | 383 | public static void reset_uid() | |
| 384 | 384 | { | |
| 385 | 385 | uid_number = -1; | |
| 386 | + graph_uid_number = -1; | ||
| 387 | + uid_number_for_function = 0; | ||
| 388 | + uid_number_for_layer = 0; | ||
| 386 | 389 | } | |
| 387 | 390 | ||
| 388 | 391 | public static void colocate_with(bool ignore_existing = false) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments