Browse Source

add audio.decode_wav

tags/v0.60-tf.numpy
Oceania2018 4 years ago
parent
commit
899d15e367
10 changed files with 104 additions and 4 deletions
  1. +3
    -0
      src/TensorFlowNET.Core/APIs/tf.array.cs
  2. +37
    -0
      src/TensorFlowNET.Core/APIs/tf.audio.cs
  3. +1
    -0
      src/TensorFlowNET.Core/APIs/tf.data.cs
  4. +2
    -0
      src/TensorFlowNET.Core/APIs/tf.io.cs
  5. +2
    -2
      src/TensorFlowNET.Core/APIs/tf.strings.cs
  6. +14
    -0
      src/TensorFlowNET.Core/IO/gfile.cs
  7. +29
    -0
      src/TensorFlowNET.Core/Operations/audio_ops.cs
  8. +9
    -1
      src/TensorFlowNET.Core/Operations/string_ops.cs
  9. +1
    -1
      src/TensorFlowNET.Core/Tensors/Ragged/RaggedTensor.cs
  10. +6
    -0
      src/TensorFlowNET.Core/Tensors/Tensors.cs

+ 3
- 0
src/TensorFlowNET.Core/APIs/tf.array.cs View File

@@ -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);




+ 37
- 0
src/TensorFlowNET.Core/APIs/tf.audio.cs View File

@@ -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);
}
}
}

+ 1
- 0
src/TensorFlowNET.Core/APIs/tf.data.cs View File

@@ -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();
} }
} }


+ 2
- 0
src/TensorFlowNET.Core/APIs/tf.io.cs View File

@@ -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)


+ 2
- 2
src/TensorFlowNET.Core/APIs/tf.strings.cs View File

@@ -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
- 0
src/TensorFlowNET.Core/IO/gfile.cs View File

@@ -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();
}
} }
} }

+ 29
- 0
src/TensorFlowNET.Core/Operations/audio_ops.cs View File

@@ -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 }));
}
}

+ 9
- 1
src/TensorFlowNET.Core/Operations/string_ops.cs View File

@@ -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)
{ {


+ 1
- 1
src/TensorFlowNET.Core/Tensors/Ragged/RaggedTensor.cs View File

@@ -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();


+ 6
- 0
src/TensorFlowNET.Core/Tensors/Tensors.cs View File

@@ -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()


Loading…
Cancel
Save