Browse Source

fix AutoNumPy crash when in multiple thread.

tags/TensorFlowOpLayer
Oceania2018 4 years ago
parent
commit
f3a5d19087
6 changed files with 10 additions and 11 deletions
  1. +0
    -1
      src/TensorFlowNET.Core/Graphs/Graph.Import.cs
  2. +8
    -1
      src/TensorFlowNET.Core/NumPy/AutoNumPyAttribute.cs
  3. +1
    -0
      src/TensorFlowNET.Core/Numpy/NDArray.cs
  4. +0
    -1
      src/TensorFlowNET.Core/Operations/math_ops.cs
  5. +1
    -1
      src/TensorFlowNET.Core/Tensors/constant_op.cs
  6. +0
    -7
      test/TensorFlowNET.UnitTest/Utilities/FluentExtension.cs

+ 0
- 1
src/TensorFlowNET.Core/Graphs/Graph.Import.cs View File

@@ -52,7 +52,6 @@ namespace Tensorflow
using (var status = new Status())
using (var graph_def = new Buffer(bytes))
{
as_default();
c_api.TF_ImportGraphDefOptionsSetPrefix(opts.Handle, prefix);
c_api.TF_GraphImportGraphDef(_handle, graph_def.Handle, opts.Handle, status.Handle);
status.Check(true);


+ 8
- 1
src/TensorFlowNET.Core/NumPy/AutoNumPyAttribute.cs View File

@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using static Tensorflow.Binding;

namespace Tensorflow.NumPy
@@ -10,9 +11,12 @@ namespace Tensorflow.NumPy
public sealed class AutoNumPyAttribute : OnMethodBoundaryAspect
{
bool _changedMode = false;

bool _locked = false;
static object locker = new Object();
public override void OnEntry(MethodExecutionArgs args)
{
Monitor.Enter(locker, ref _locked);
if (!tf.executing_eagerly())
{
tf.Context.eager_mode();
@@ -24,6 +28,9 @@ namespace Tensorflow.NumPy
{
if (_changedMode)
tf.Context.restore_mode();

if (_locked)
Monitor.Exit(locker);
}
}
}

+ 1
- 0
src/TensorFlowNET.Core/Numpy/NDArray.cs View File

@@ -30,6 +30,7 @@ namespace Tensorflow.NumPy

[AutoNumPy]
public NDArray reshape(Shape newshape) => new NDArray(tf.reshape(this, newshape));
[AutoNumPy]
public NDArray astype(TF_DataType dtype) => new NDArray(math_ops.cast(this, dtype));
public NDArray ravel() => throw new NotImplementedException("");
public void shuffle(NDArray nd) => np.random.shuffle(nd);


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

@@ -126,7 +126,6 @@ namespace Tensorflow
return tf_with(ops.name_scope(name, "Cast", new { x }), scope =>
{
name = scope;
x = ops.convert_to_tensor(x, name: "x");
if (x.dtype.as_base_dtype() != base_type)
x = gen_math_ops.cast(x, base_type, name: name);



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

@@ -101,7 +101,7 @@ namespace Tensorflow
value is NDArray nd &&
nd.dtype != dtype)
{
value = nd.astype(dtype);
value = math_ops.cast(nd, dtype);
}

// non ascii char


+ 0
- 7
test/TensorFlowNET.UnitTest/Utilities/FluentExtension.cs View File

@@ -197,13 +197,6 @@ namespace TensorFlowNET.UnitTest
return new AndConstraint<NDArrayAssertions>(this);
}

public AndConstraint<NDArrayAssertions> BeScalar(object value)
{
Subject.shape.IsScalar.Should().BeTrue();
Subject.GetValue().Should().Be(value);
return new AndConstraint<NDArrayAssertions>(this);
}

public AndConstraint<NDArrayAssertions> BeOfType(Type typeCode)
{
Subject.dtype.Should().Be(typeCode);


Loading…
Cancel
Save