Browse Source

Add optimize_dataset to IDatasetV2.

tags/v0.20
Oceania2018 5 years ago
parent
commit
2efaaa8826
5 changed files with 180 additions and 7 deletions
  1. +3
    -0
      src/TensorFlowNET.Core/Binding.Util.cs
  2. +9
    -7
      src/TensorFlowNET.Core/Eager/EagerRunner.TFE_FastPathExecute.cs
  3. +3
    -0
      src/TensorFlowNET.Core/Eager/c_api.eager.cs
  4. +12
    -0
      src/TensorFlowNET.Core/Framework/Models/AutotuneAlgorithm.cs
  5. +153
    -0
      src/TensorFlowNET.Core/Operations/dataset_ops.cs

+ 3
- 0
src/TensorFlowNET.Core/Binding.Util.cs View File

@@ -271,7 +271,10 @@ namespace Tensorflow
foreach(var val in values)
{
if (i < start)
{
i++;
continue;
}
yield return (i, val);
}
}


+ 9
- 7
src/TensorFlowNET.Core/Eager/EagerRunner.TFE_FastPathExecute.cs View File

@@ -159,13 +159,9 @@ namespace Tensorflow.Eager

if (op_exec_info.run_callbacks)
{
if (!RunCallbacks(
op_exec_info,
RunCallbacks(op_exec_info,
kFastPathExecuteInputStartIndex + op_def.InputArg.Count(),
flattened_inputs.ToArray(), flattened_attrs.ToArray(), flat_result))
{
return null;
}
flattened_inputs.ToArray(), flattened_attrs.ToArray(), flat_result);
}

return flat_result;
@@ -319,7 +315,12 @@ namespace Tensorflow.Eager
Dictionary<string, long> attr_list_sizes,
Status status)
{
if(type == TF_AttrType.TF_ATTR_SHAPE && values is TensorShape[] values1)
if (type == TF_AttrType.TF_ATTR_STRING && values is string[] values3)
{
c_api.TFE_OpSetAttrStringList(op, key, new IntPtr[0], values3.Select(x => x.Length).ToArray(), values3.Length);
attr_list_sizes[key] = values3.Length;
}
else if (type == TF_AttrType.TF_ATTR_SHAPE && values is TensorShape[] values1)
{
// Make one pass through the input counting the total number of
// dims across all the input lists.
@@ -340,6 +341,7 @@ namespace Tensorflow.Eager
else if(type == TF_AttrType.TF_ATTR_TYPE && values is TF_DataType[] values2)
{
c_api.TFE_OpSetAttrTypeList(op, key, values2, values2.Length);
attr_list_sizes[key] = values2.Length;
}
else
{


+ 3
- 0
src/TensorFlowNET.Core/Eager/c_api.eager.cs View File

@@ -160,6 +160,9 @@ namespace Tensorflow
[DllImport(TensorFlowLibName)]
public static extern void TFE_OpSetAttrShapeList(SafeOpHandle op, string attr_name, IntPtr[] dims, int[] num_dims, int num_values, SafeStatusHandle out_status);

[DllImport(TensorFlowLibName)]
public static extern void TFE_OpSetAttrStringList(SafeOpHandle op, string attr_name, IntPtr[] values, int[] lengths, int num_values);

[DllImport(TensorFlowLibName)]
public static extern void TFE_OpSetAttrBool(SafeOpHandle op, string attr_name, bool value);



+ 12
- 0
src/TensorFlowNET.Core/Framework/Models/AutotuneAlgorithm.cs View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Tensorflow.Framework.Models
{
public enum AutotuneAlgorithm
{
HILL_CLIMB = 0,
GRADIENT_DESCENT = 1,
}
}

+ 153
- 0
src/TensorFlowNET.Core/Operations/dataset_ops.cs View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using Tensorflow.Framework.Models;
using static Tensorflow.Binding;

namespace Tensorflow
@@ -174,5 +175,157 @@ namespace Tensorflow

throw new NotImplementedException("");
}

/// <summary>
/// Creates a dataset by applying optimizations to `input_dataset`.
/// </summary>
/// <param name="input_dataset"></param>
/// <param name="optimizations"></param>
/// <param name="output_types"></param>
/// <param name="output_shapes"></param>
/// <param name="optimization_configs"></param>
/// <param name="name"></param>
/// <returns></returns>
public Tensor optimize_dataset(Tensor input_dataset, Tensor optimizations,
TF_DataType[] output_types, TensorShape[] output_shapes,
string[] optimization_configs = null,
string name = null)
{
if (optimization_configs == null)
optimization_configs = new string[0];

if (tf.context.executing_eagerly())
{
var results = tf.Runner.TFE_FastPathExecute(tf.context, tf.context.device_name,
"OptimizeDataset", name,
null,
input_dataset, optimizations,
"output_types", output_types,
"output_shapes", output_shapes,
"optimization_configs", optimization_configs);
return results[0];
}

throw new NotImplementedException("");
}

/// <summary>
/// Identity transformation that models performance.
/// </summary>
/// <param name="input_dataset"></param>
/// <param name="output_types"></param>
/// <param name="output_shapes"></param>
/// <param name="algorithm"></param>
/// <param name="cpu_budget"></param>
/// <param name="name"></param>
/// <returns></returns>
public Tensor model_dataset(Tensor input_dataset,
TF_DataType[] output_types, TensorShape[] output_shapes,
AutotuneAlgorithm algorithm, long cpu_budget,
string name = null)
{
if (tf.context.executing_eagerly())
{
var results = tf.Runner.TFE_FastPathExecute(tf.context, tf.context.device_name,
"ModelDataset", name,
null,
input_dataset,
"algorithm", algorithm,
"cpu_budget", cpu_budget,
"output_types", output_types,
"output_shapes", output_shapes);
return results[0];
}

throw new NotImplementedException("");
}

/// <summary>
/// A container for an iterator resource.
/// </summary>
/// <param name="output_types"></param>
/// <param name="output_shapes"></param>
/// <param name="name"></param>
/// <returns>A tuple of `Tensor` objects (handle, deleter).</returns>
public (Tensor, Tensor) anonymous_iterator_v2(TF_DataType[] output_types, TensorShape[] output_shapes, string name = null)
{
if (tf.context.executing_eagerly())
{
var results = tf.Runner.TFE_FastPathExecute(tf.context, tf.context.device_name,
"AnonymousIteratorV2", name,
null,
"output_types", output_types,
"output_shapes", output_shapes);
return (results[0], results[1]);
}

throw new NotImplementedException("");
}

/// <summary>
/// Makes a new iterator from the given `dataset` and stores it in `iterator`.
/// </summary>
/// <param name="dataset"></param>
/// <param name="iterator"></param>
/// <param name="name"></param>
/// <returns>The created Operation.</returns>
public ITensorOrOperation make_iterator(Tensor dataset, Tensor iterator, string name = null)
{
if (tf.context.executing_eagerly())
{
var results = tf.Runner.TFE_FastPathExecute(tf.context, tf.context.device_name,
"MakeIterator", name,
null,
dataset, iterator);
return null;
}

throw new NotImplementedException("");
}

/// <summary>
/// A container for an iterator resource.
/// </summary>
/// <param name="handle"></param>
/// <param name="deleter"></param>
/// <param name="name"></param>
/// <returns>The created Operation.</returns>
public ITensorOrOperation delete_iterator(Tensor handle, Tensor deleter, string name = null)
{
if (tf.context.executing_eagerly())
{
var results = tf.Runner.TFE_FastPathExecute(tf.context, tf.context.device_name,
"DeleteIterator", name,
null,
handle, deleter);
return null;
}

throw new NotImplementedException("");
}

/// <summary>
/// Gets the next output from the given iterator .
/// </summary>
/// <param name="iterator"></param>
/// <param name="output_types"></param>
/// <param name="output_shapes"></param>
/// <param name="name"></param>
/// <returns></returns>
public Tensor[] iterator_get_next(Tensor iterator, TF_DataType[] output_types, TensorShape[] output_shapes, string name = null)
{
if (tf.context.executing_eagerly())
{
var results = tf.Runner.TFE_FastPathExecute(tf.context, tf.context.device_name,
"IteratorGetNext", name,
null,
iterator,
"output_types", output_types,
"output_shapes", output_shapes);
return results;
}

throw new NotImplementedException("");
}
}
}

Loading…
Cancel
Save