Skip to content

Commit 8048b62

Browse files
committed
Add RepeatDataSetCrash test.
1 parent 3d943a1 commit 8048b62

7 files changed

Lines changed: 47 additions & 7 deletions

File tree

src/TensorFlowNET.Core/Data/DatasetV2.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public class DatasetV2 : IDatasetV2
2525

2626
public TensorSpec[] element_spec => structure;
2727

28+
public int length => cardinality().numpy();
29+
2830
public IDatasetV2 cache(string filename = "")
2931
=> new CacheDataset(this, filename: filename);
3032

@@ -136,7 +138,9 @@ public Tensor cardinality(string name = null)
136138
=> tf.Context.ExecuteOp("DatasetCardinality", name, new ExecuteOpArgs(variant_tensor));
137139

138140
public override string ToString()
139-
=> $"{GetType().Name} shapes: {string.Join(", ", structure.Select(x => x.shape))}, types: {string.Join(", ", structure.Select(x => "tf." + x.dtype.as_numpy_name()))}";
141+
=> $"{GetType().Name} shapes: {string.Join(", ", structure.Select(x => x.shape))}, " +
142+
$"types: {string.Join(", ", structure.Select(x => "tf." + x.dtype.as_numpy_name()))}, " +
143+
$"len: {length}";
140144

141145
public IEnumerator<(Tensor, Tensor)> GetEnumerator()
142146
{

src/TensorFlowNET.Keras/Engine/Layer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private Tensor compute_mask(Tensor inputs, Tensor mask = null)
158158
/// <returns></returns>
159159
protected virtual Tensors Call(Tensors inputs, Tensor state = null, bool? training = null)
160160
{
161-
throw new NotImplementedException("");
161+
return inputs;
162162
}
163163

164164
protected virtual string _name_scope()

src/TensorFlowNET.Keras/Engine/Model.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ void _reset_compile_cache()
5757

5858
void _init_batch_counters()
5959
{
60-
_train_counter = tf.Variable(0,
60+
_train_counter = tf.Variable(0L,
6161
dtype: TF_DataType.TF_INT64,
6262
aggregation: VariableAggregation.OnlyFirstReplica);
6363

64-
_test_counter = tf.Variable(0,
64+
_test_counter = tf.Variable(0L,
6565
dtype: TF_DataType.TF_INT64,
6666
aggregation: VariableAggregation.OnlyFirstReplica);
6767

68-
_predict_counter = tf.Variable(0,
68+
_predict_counter = tf.Variable(0L,
6969
dtype: TF_DataType.TF_INT64,
7070
aggregation: VariableAggregation.OnlyFirstReplica);
7171
}

src/TensorFlowNET.Keras/Utils/Compress.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public static void UnZip(String gzArchiveName, String destFolder)
5353
var flag = gzArchiveName.Split(Path.DirectorySeparatorChar).Last().Split('.').First() + ".bin";
5454
if (File.Exists(Path.Combine(destFolder, flag))) return;
5555

56+
var destFileName = gzArchiveName.Replace(".zip", string.Empty);
57+
if (File.Exists(destFileName)) return;
58+
5659
Binding.tf_output_redirect.WriteLine($"Extracting.");
5760
var task = Task.Run(() =>
5861
{
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using BenchmarkDotNet.Attributes;
2+
using System;
3+
using System.Collections.Generic;
4+
using NumSharp;
5+
using static Tensorflow.Binding;
6+
using static Tensorflow.KerasApi;
7+
8+
namespace Tensorflow.Benchmark.Crash
9+
{
10+
public class RepeatDataSetCrash
11+
{
12+
[Benchmark]
13+
public void Run()
14+
{
15+
var data = tf.convert_to_tensor(np.arange(0, 50000 * 10).astype(np.float32).reshape(50000, 10));
16+
17+
var dataset = keras.preprocessing.timeseries_dataset_from_array(data,
18+
sequence_length: 10,
19+
sequence_stride: 1,
20+
shuffle: false,
21+
batch_size: 32);
22+
23+
while (true)
24+
foreach (var d in dataset)
25+
;
26+
}
27+
}
28+
}

src/TensorFlowNet.Benchmarks/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
using BenchmarkDotNet.Running;
33
using System;
44
using System.Reflection;
5+
using Tensorflow.Benchmark.Crash;
56
using Tensorflow.Benchmark.Leak;
7+
using static Tensorflow.Binding;
68

79
namespace TensorFlowBenchmark
810
{
911
class Program
1012
{
1113
static void Main(string[] args)
1214
{
15+
print(tf.VERSION);
16+
new RepeatDataSetCrash().Run();
1317
new GpuLeakByCNN().Run();
1418

1519
if (args?.Length > 0)

src/TensorFlowNet.Benchmarks/Tensorflow.Benchmark.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
1616
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
17+
<DefineConstants>DEBUG;TRACE</DefineConstants>
1718
</PropertyGroup>
1819

1920
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
@@ -35,8 +36,8 @@
3536
</ItemGroup>
3637

3738
<ItemGroup>
38-
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
39-
<PackageReference Include="SciSharp.TensorFlow.Redist-Windows-GPU" Version="2.5.0" />
39+
<PackageReference Include="BenchmarkDotNet" Version="0.13.0" />
40+
<PackageReference Include="SciSharp.TensorFlow.Redist" Version="2.5.0" />
4041
</ItemGroup>
4142

4243
<ItemGroup>

0 commit comments

Comments
 (0)