| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 773a3ba commit 899d15e
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -188,6 +188,9 @@ public Tensor rank(Tensor input, string name = null) | |||
| 188 | 188 | public Tensor slice<Tb, Ts>(Tensor input, Tb[] begin, Ts[] size, string name = null) | |
| 189 | 189 | => array_ops.slice(input, begin, size, name: name); | |
| 190 | 190 | ||
| 191 | + public Tensor squeeze(Tensor input, int axis, string name = null, int squeeze_dims = -1) | ||
| 192 | + => array_ops.squeeze(input, new[] { axis }, name); | ||
| 193 | + | ||
| 191 | 194 | public Tensor squeeze(Tensor input, int[] axis = null, string name = null, int squeeze_dims = -1) | |
| 192 | 195 | => array_ops.squeeze(input, axis, name); | |
| 193 | 196 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,37 @@ | |||
| 1 | + /***************************************************************************** | ||
| 2 | + Copyright 2021 Haiping Chen. All Rights Reserved. | ||
| 3 | + | ||
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + you may not use this file except in compliance with the License. | ||
| 6 | + You may obtain a copy of the License at | ||
| 7 | + | ||
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + | ||
| 10 | + Unless required by applicable law or agreed to in writing, software | ||
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + See the License for the specific language governing permissions and | ||
| 14 | + limitations under the License. | ||
| 15 | + ******************************************************************************/ | ||
| 16 | + | ||
| 17 | + using System.Collections.Generic; | ||
| 18 | + using Tensorflow.IO; | ||
| 19 | + | ||
| 20 | + namespace Tensorflow | ||
| 21 | + { | ||
| 22 | + public partial class tensorflow | ||
| 23 | + { | ||
| 24 | + public AudioAPI audio { get; } = new AudioAPI(); | ||
| 25 | + | ||
| 26 | + public class AudioAPI | ||
| 27 | + { | ||
| 28 | + audio_ops audio_ops = new audio_ops(); | ||
| 29 | + | ||
| 30 | + public Tensors decode_wav(Tensor contents, int desired_channels = -1, int desired_samples = -1, string name = null) | ||
| 31 | + => audio_ops.decode_wav(contents, | ||
| 32 | + desired_channels: desired_channels, | ||
| 33 | + desired_samples: desired_samples, | ||
| 34 | + name: name); | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,6 +22,7 @@ public partial class tensorflow | |||
| 22 | 22 | ||
| 23 | 23 | public class DataOps | |
| 24 | 24 | { | |
| 25 | + public int AUTOTUNE = -1; | ||
| 25 | 26 | public DatasetManager Dataset { get; } = new DatasetManager(); | |
| 26 | 27 | } | |
| 27 | 28 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,9 +26,11 @@ public partial class tensorflow | |||
| 26 | 26 | public class IoApi | |
| 27 | 27 | { | |
| 28 | 28 | io_ops ops; | |
| 29 | + public GFile gfile; | ||
| 29 | 30 | public IoApi() | |
| 30 | 31 | { | |
| 31 | 32 | ops = new io_ops(); | |
| 33 | + gfile = new GFile(); | ||
| 32 | 34 | } | |
| 33 | 35 | ||
| 34 | 36 | public Tensor read_file(string filename, string name = null) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -80,8 +80,8 @@ public Tensor string_length(Tensor input, string name = null, string unit = "BYT | |||
| 80 | 80 | public Tensor format(string template, Tensor[] inputs, string placeholder = "{}", int summarize = 3, string name = null) | |
| 81 | 81 | => ops.string_format(inputs, template: template, placeholder: placeholder, summarize: summarize, name: name); | |
| 82 | 82 | ||
| 83 | - public RaggedTensor split(Tensor input, string sep = "", int maxsplit = -1, string name = null) | ||
| 84 | - => ops.string_split_v2(input, sep: sep, maxsplit : maxsplit, name : name); | ||
| 83 | + public RaggedTensor split(Tensor input, char sep = ' ', int maxsplit = -1, string name = null) | ||
| 84 | + => ops.string_split_v2(input, sep: sep.ToString(), maxsplit : maxsplit, name : name); | ||
| 85 | 85 | ||
| 86 | 86 | public (RaggedTensor, RaggedTensor) unicode_decode_with_offsets(Tensor input, string input_encoding, | |
| 87 | 87 | string errors = "replace", int replacement_char = 0xFFFD, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,7 @@ You may obtain a copy of the License at | |||
| 14 | 14 | limitations under the License. | |
| 15 | 15 | ******************************************************************************/ | |
| 16 | 16 | ||
| 17 | + using System; | ||
| 17 | 18 | using System.Collections.Generic; | |
| 18 | 19 | using System.IO; | |
| 19 | 20 | using System.Linq; | |
@@ -49,5 +50,18 @@ public class GFile | |||
| 49 | 50 | foreach (var f in walk_v2(dir, topdown)) | |
| 50 | 51 | yield return f; | |
| 51 | 52 | } | |
| 53 | + | ||
| 54 | + public string[] listdir(string data_dir) | ||
| 55 | + => Directory.GetDirectories(data_dir) | ||
| 56 | + .Select(x => x.Split(Path.DirectorySeparatorChar).Last()) | ||
| 57 | + .ToArray(); | ||
| 58 | + | ||
| 59 | + public string[] glob(string data_dir) | ||
| 60 | + { | ||
| 61 | + var dirs = new List<string>(); | ||
| 62 | + foreach(var dir in Directory.GetDirectories(data_dir)) | ||
| 63 | + dirs.AddRange(Directory.GetFiles(dir)); | ||
| 64 | + return dirs.ToArray(); | ||
| 65 | + } | ||
| 52 | 66 | } | |
| 53 | 67 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,29 @@ | |||
| 1 | + /***************************************************************************** | ||
| 2 | + Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved. | ||
| 3 | + | ||
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + you may not use this file except in compliance with the License. | ||
| 6 | + You may obtain a copy of the License at | ||
| 7 | + | ||
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + | ||
| 10 | + Unless required by applicable law or agreed to in writing, software | ||
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + See the License for the specific language governing permissions and | ||
| 14 | + limitations under the License. | ||
| 15 | + ******************************************************************************/ | ||
| 16 | + | ||
| 17 | + using System.Collections.Generic; | ||
| 18 | + using Tensorflow.Contexts; | ||
| 19 | + using static Tensorflow.Binding; | ||
| 20 | + | ||
| 21 | + namespace Tensorflow | ||
| 22 | + { | ||
| 23 | + public class audio_ops | ||
| 24 | + { | ||
| 25 | + public Tensors decode_wav(Tensor contents, int desired_channels = -1, int desired_samples = -1, string name = null) | ||
| 26 | + => tf.Context.ExecuteOp("DecodeWav", name, new ExecuteOpArgs(contents) | ||
| 27 | + .SetAttributes(new { desired_channels, desired_samples })); | ||
| 28 | + } | ||
| 29 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -73,11 +73,19 @@ public Tensor string_format(Tensor[] inputs, string template = "%s", string plac | |||
| 73 | 73 | } | |
| 74 | 74 | }.SetAttributes(new { template, placeholder, summarize })); | |
| 75 | 75 | ||
| 76 | - public RaggedTensor string_split_v2(Tensor input, string sep = "", int maxsplit = -1, string name = null) | ||
| 76 | + public RaggedTensor string_split_v2(Tensor input, string sep = " ", int maxsplit = -1, string name = null) | ||
| 77 | 77 | { | |
| 78 | 78 | return tf_with(ops.name_scope(name, "StringSplit"), scope => | |
| 79 | 79 | { | |
| 80 | 80 | var sep_tensor = ops.convert_to_tensor(sep, dtype: TF_DataType.TF_STRING); | |
| 81 | + if(input.rank == 0) | ||
| 82 | + { | ||
| 83 | + return string_split_v2(array_ops.stack(new[] { input }), | ||
| 84 | + sep: sep, | ||
| 85 | + maxsplit: maxsplit, | ||
| 86 | + name: name)[0]; | ||
| 87 | + } | ||
| 88 | + | ||
| 81 | 89 | var result = tf.Context.ExecuteOp("StringSplitV2", name, | |
| 82 | 90 | new ExecuteOpArgs(input, sep) | |
| 83 | 91 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -134,7 +134,7 @@ Tensor[] nested_row_splits | |||
| 134 | 134 | => new[] { _row_splits }; | |
| 135 | 135 | ||
| 136 | 136 | public override string ToString() | |
| 137 | - => $"tf.RaggedTensor: shape={shape} [{string.Join(", ", _values.StringData().Take(10))}]"; | ||
| 137 | + => $"tf.RaggedTensor: shape={_values.TensorShape} [{string.Join(", ", _values.StringData().Take(10))}]"; | ||
| 138 | 138 | ||
| 139 | 139 | public static implicit operator Tensor(RaggedTensor indexedSlices) | |
| 140 | 140 | => indexedSlices._to_variant(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -92,6 +92,12 @@ public static implicit operator Tensor(Tensors tensors) | |||
| 92 | 92 | public static implicit operator Tensor[](Tensors tensors) | |
| 93 | 93 | => tensors.items.ToArray(); | |
| 94 | 94 | ||
| 95 | + public void Deconstruct(out Tensor a, out Tensor b) | ||
| 96 | + { | ||
| 97 | + a = items[0]; | ||
| 98 | + b = items[1]; | ||
| 99 | + } | ||
| 100 | + | ||
| 95 | 101 | public override string ToString() | |
| 96 | 102 | => items.Count() == 1 | |
| 97 | 103 | ? items.First().ToString() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments