| @@ -188,6 +188,9 @@ namespace Tensorflow | |||||
| public Tensor slice<Tb, Ts>(Tensor input, Tb[] begin, Ts[] size, string name = null) | public Tensor slice<Tb, Ts>(Tensor input, Tb[] begin, Ts[] size, string name = null) | ||||
| => array_ops.slice(input, begin, size, name: name); | => array_ops.slice(input, begin, size, name: name); | ||||
| public Tensor squeeze(Tensor input, int axis, string name = null, int squeeze_dims = -1) | |||||
| => array_ops.squeeze(input, new[] { axis }, name); | |||||
| public Tensor squeeze(Tensor input, int[] axis = null, string name = null, int squeeze_dims = -1) | public Tensor squeeze(Tensor input, int[] axis = null, string name = null, int squeeze_dims = -1) | ||||
| => array_ops.squeeze(input, axis, name); | => array_ops.squeeze(input, axis, name); | ||||
| @@ -0,0 +1,37 @@ | |||||
| /***************************************************************************** | |||||
| Copyright 2021 Haiping Chen. All Rights Reserved. | |||||
| Licensed under the Apache License, Version 2.0 (the "License"); | |||||
| you may not use this file except in compliance with the License. | |||||
| You may obtain a copy of the License at | |||||
| http://www.apache.org/licenses/LICENSE-2.0 | |||||
| Unless required by applicable law or agreed to in writing, software | |||||
| distributed under the License is distributed on an "AS IS" BASIS, | |||||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| See the License for the specific language governing permissions and | |||||
| limitations under the License. | |||||
| ******************************************************************************/ | |||||
| using System.Collections.Generic; | |||||
| using Tensorflow.IO; | |||||
| namespace Tensorflow | |||||
| { | |||||
| public partial class tensorflow | |||||
| { | |||||
| public AudioAPI audio { get; } = new AudioAPI(); | |||||
| public class AudioAPI | |||||
| { | |||||
| audio_ops audio_ops = new audio_ops(); | |||||
| public Tensors decode_wav(Tensor contents, int desired_channels = -1, int desired_samples = -1, string name = null) | |||||
| => audio_ops.decode_wav(contents, | |||||
| desired_channels: desired_channels, | |||||
| desired_samples: desired_samples, | |||||
| name: name); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -22,6 +22,7 @@ namespace Tensorflow | |||||
| public class DataOps | public class DataOps | ||||
| { | { | ||||
| public int AUTOTUNE = -1; | |||||
| public DatasetManager Dataset { get; } = new DatasetManager(); | public DatasetManager Dataset { get; } = new DatasetManager(); | ||||
| } | } | ||||
| } | } | ||||
| @@ -26,9 +26,11 @@ namespace Tensorflow | |||||
| public class IoApi | public class IoApi | ||||
| { | { | ||||
| io_ops ops; | io_ops ops; | ||||
| public GFile gfile; | |||||
| public IoApi() | public IoApi() | ||||
| { | { | ||||
| ops = new io_ops(); | ops = new io_ops(); | ||||
| gfile = new GFile(); | |||||
| } | } | ||||
| public Tensor read_file(string filename, string name = null) | public Tensor read_file(string filename, string name = null) | ||||
| @@ -80,8 +80,8 @@ namespace Tensorflow | |||||
| public Tensor format(string template, Tensor[] inputs, string placeholder = "{}", int summarize = 3, string name = null) | public Tensor format(string template, Tensor[] inputs, string placeholder = "{}", int summarize = 3, string name = null) | ||||
| => ops.string_format(inputs, template: template, placeholder: placeholder, summarize: summarize, name: name); | => ops.string_format(inputs, template: template, placeholder: placeholder, summarize: summarize, name: name); | ||||
| public RaggedTensor split(Tensor input, string sep = "", int maxsplit = -1, string name = null) | |||||
| => ops.string_split_v2(input, sep: sep, maxsplit : maxsplit, name : name); | |||||
| public RaggedTensor split(Tensor input, char sep = ' ', int maxsplit = -1, string name = null) | |||||
| => ops.string_split_v2(input, sep: sep.ToString(), maxsplit : maxsplit, name : name); | |||||
| public (RaggedTensor, RaggedTensor) unicode_decode_with_offsets(Tensor input, string input_encoding, | public (RaggedTensor, RaggedTensor) unicode_decode_with_offsets(Tensor input, string input_encoding, | ||||
| string errors = "replace", int replacement_char = 0xFFFD, | string errors = "replace", int replacement_char = 0xFFFD, | ||||
| @@ -14,6 +14,7 @@ | |||||
| limitations under the License. | limitations under the License. | ||||
| ******************************************************************************/ | ******************************************************************************/ | ||||
| using System; | |||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.IO; | using System.IO; | ||||
| using System.Linq; | using System.Linq; | ||||
| @@ -49,5 +50,18 @@ namespace Tensorflow.IO | |||||
| foreach (var f in walk_v2(dir, topdown)) | foreach (var f in walk_v2(dir, topdown)) | ||||
| yield return f; | yield return f; | ||||
| } | } | ||||
| public string[] listdir(string data_dir) | |||||
| => Directory.GetDirectories(data_dir) | |||||
| .Select(x => x.Split(Path.DirectorySeparatorChar).Last()) | |||||
| .ToArray(); | |||||
| public string[] glob(string data_dir) | |||||
| { | |||||
| var dirs = new List<string>(); | |||||
| foreach(var dir in Directory.GetDirectories(data_dir)) | |||||
| dirs.AddRange(Directory.GetFiles(dir)); | |||||
| return dirs.ToArray(); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,29 @@ | |||||
| /***************************************************************************** | |||||
| Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved. | |||||
| Licensed under the Apache License, Version 2.0 (the "License"); | |||||
| you may not use this file except in compliance with the License. | |||||
| You may obtain a copy of the License at | |||||
| http://www.apache.org/licenses/LICENSE-2.0 | |||||
| Unless required by applicable law or agreed to in writing, software | |||||
| distributed under the License is distributed on an "AS IS" BASIS, | |||||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| See the License for the specific language governing permissions and | |||||
| limitations under the License. | |||||
| ******************************************************************************/ | |||||
| using System.Collections.Generic; | |||||
| using Tensorflow.Contexts; | |||||
| using static Tensorflow.Binding; | |||||
| namespace Tensorflow | |||||
| { | |||||
| public class audio_ops | |||||
| { | |||||
| public Tensors decode_wav(Tensor contents, int desired_channels = -1, int desired_samples = -1, string name = null) | |||||
| => tf.Context.ExecuteOp("DecodeWav", name, new ExecuteOpArgs(contents) | |||||
| .SetAttributes(new { desired_channels, desired_samples })); | |||||
| } | |||||
| } | |||||
| @@ -73,11 +73,19 @@ namespace Tensorflow | |||||
| } | } | ||||
| }.SetAttributes(new { template, placeholder, summarize })); | }.SetAttributes(new { template, placeholder, summarize })); | ||||
| public RaggedTensor string_split_v2(Tensor input, string sep = "", int maxsplit = -1, string name = null) | |||||
| public RaggedTensor string_split_v2(Tensor input, string sep = " ", int maxsplit = -1, string name = null) | |||||
| { | { | ||||
| return tf_with(ops.name_scope(name, "StringSplit"), scope => | return tf_with(ops.name_scope(name, "StringSplit"), scope => | ||||
| { | { | ||||
| var sep_tensor = ops.convert_to_tensor(sep, dtype: TF_DataType.TF_STRING); | var sep_tensor = ops.convert_to_tensor(sep, dtype: TF_DataType.TF_STRING); | ||||
| if(input.rank == 0) | |||||
| { | |||||
| return string_split_v2(array_ops.stack(new[] { input }), | |||||
| sep: sep, | |||||
| maxsplit: maxsplit, | |||||
| name: name)[0]; | |||||
| } | |||||
| var result = tf.Context.ExecuteOp("StringSplitV2", name, | var result = tf.Context.ExecuteOp("StringSplitV2", name, | ||||
| new ExecuteOpArgs(input, sep) | new ExecuteOpArgs(input, sep) | ||||
| { | { | ||||
| @@ -134,7 +134,7 @@ namespace Tensorflow | |||||
| => new[] { _row_splits }; | => new[] { _row_splits }; | ||||
| public override string ToString() | public override string ToString() | ||||
| => $"tf.RaggedTensor: shape={shape} [{string.Join(", ", _values.StringData().Take(10))}]"; | |||||
| => $"tf.RaggedTensor: shape={_values.TensorShape} [{string.Join(", ", _values.StringData().Take(10))}]"; | |||||
| public static implicit operator Tensor(RaggedTensor indexedSlices) | public static implicit operator Tensor(RaggedTensor indexedSlices) | ||||
| => indexedSlices._to_variant(); | => indexedSlices._to_variant(); | ||||
| @@ -92,6 +92,12 @@ namespace Tensorflow | |||||
| public static implicit operator Tensor[](Tensors tensors) | public static implicit operator Tensor[](Tensors tensors) | ||||
| => tensors.items.ToArray(); | => tensors.items.ToArray(); | ||||
| public void Deconstruct(out Tensor a, out Tensor b) | |||||
| { | |||||
| a = items[0]; | |||||
| b = items[1]; | |||||
| } | |||||
| public override string ToString() | public override string ToString() | ||||
| => items.Count() == 1 | => items.Count() == 1 | ||||
| ? items.First().ToString() | ? items.First().ToString() | ||||