Browse Source

Add implicitation for Operation to RefVariable

tags/v0.20
Oceania2018 5 years ago
parent
commit
08224a9a93
4 changed files with 26 additions and 10 deletions
  1. +6
    -2
      src/TensorFlowNET.Core/Operations/Operation.Implicit.cs
  2. +1
    -1
      src/TensorFlowNET.Core/Operations/Operation.cs
  3. +7
    -6
      src/TensorFlowNET.Core/TensorFlow.Binding.csproj
  4. +12
    -1
      src/TensorFlowNET.Core/Variables/RefVariable.cs

+ 6
- 2
src/TensorFlowNET.Core/Operations/Operation.Implicit.cs View File

@@ -27,8 +27,12 @@ namespace Tensorflow
public static implicit operator Operation(IntPtr handle)
=> new Operation(handle);

public static implicit operator IntPtr(Operation op) => op._handle;
public static implicit operator Tensor(Operation op) => op.output;
public static implicit operator IntPtr(Operation op)
=> op._handle;
public static implicit operator Tensor(Operation op)
=> op.output;
public static implicit operator RefVariable(Operation op)
=> new RefVariable(op);

public override string ToString()
{


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

@@ -106,7 +106,7 @@ namespace Tensorflow
_outputs = new Tensor[NumOutputs];
for (int i = 0; i < NumOutputs; i++)
_outputs[i] = new Tensor(this, i, OutputType(i));
// Dict mapping op name to file and line information for op colocation
// context managers.
_control_flow_context = _graph._get_control_flow_context();


+ 7
- 6
src/TensorFlowNET.Core/TensorFlow.Binding.csproj View File

@@ -5,7 +5,7 @@
<AssemblyName>TensorFlow.NET</AssemblyName>
<RootNamespace>Tensorflow</RootNamespace>
<TargetTensorFlow>1.14.1</TargetTensorFlow>
<Version>0.14.2.0</Version>
<Version>0.15.0</Version>
<Authors>Haiping Chen, Meinrad Recheis, Eli Belash</Authors>
<Company>SciSharp STACK</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
@@ -18,13 +18,15 @@
<Description>Google's TensorFlow full binding in .NET Standard.
Building, training and infering deep learning models.
https://tensorflownet.readthedocs.io</Description>
<AssemblyVersion>0.14.2.0</AssemblyVersion>
<AssemblyVersion>0.15.0.0</AssemblyVersion>
<PackageReleaseNotes>Changes since v0.14.0:
1: Add TransformGraphWithStringInputs.
2: tf.trainer.load_graph, tf.trainer.freeze_graph
3: Import Protobuf.Text</PackageReleaseNotes>
3: Import Protobuf.Text
4: Support YOLOv3 object detection
5: Add implicitation for Operation to RefVariable</PackageReleaseNotes>
<LangVersion>7.3</LangVersion>
<FileVersion>0.14.2.0</FileVersion>
<FileVersion>0.15.0.0</FileVersion>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<SignAssembly>true</SignAssembly>
@@ -33,7 +35,7 @@ https://tensorflownet.readthedocs.io</Description>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>TRACE;DEBUG;SERIALIZABLE</DefineConstants>
<DefineConstants>TRACE;DEBUG;SERIALIZABLE_</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
@@ -62,7 +64,6 @@ https://tensorflownet.readthedocs.io</Description>

<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.11.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NumSharp.Lite" Version="0.1.0" />
<PackageReference Include="Protobuf.Text" Version="0.4.0" />
</ItemGroup>


+ 12
- 1
src/TensorFlowNET.Core/Variables/RefVariable.cs View File

@@ -61,7 +61,11 @@ namespace Tensorflow
{
_in_graph_mode = true;

if (variable_def != null)
if(initial_value is Operation op)
{
_init_from_op(op);
}
else if (variable_def != null)
{
if (initial_value != null)
throw new ValueError("variable_def and initial_value are mutually exclusive.");
@@ -73,6 +77,13 @@ namespace Tensorflow
}
}

private void _init_from_op(Operation op)
{
var g = ops.get_default_graph();
_initializer_op = op;
_variable = op.output;
}

private void _init_from_proto(VariableDef variable_def, string import_scope = "")
{
var g = ops.get_default_graph();


Loading…
Cancel
Save