Skip to content

Commit fda7e6d

Browse files
committed
2 parents 566a092 + fd64ad1 commit fda7e6d

30 files changed

+359
-167
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ In comparison to other projects, like for instance [TensorFlowSharp](https://www
2626

2727
### How to use
2828

29-
| TensorFlow | tf native1.14 | tf native 1.15 | tf native 2.3 |
30-
| -------------------------- | ------------- | -------------- | ------------- |
31-
| tf.net 0.3x, tf.keras 0.2 | | | x |
32-
| tf.net 0.2x | | x | x |
33-
| tf.net 0.15 | x | x | |
34-
| tf.net 0.14 | x | | |
29+
| TensorFlow | tf native1.14, cuda 10.0 | tf native 1.15, cuda 10.0 | tf native 2.3, cuda 10.1 | tf native 2.4, cuda 11 |
30+
| -------------------------- | ------------- | -------------- | ------------- | ------------- |
31+
| tf.net 0.3x, tf.keras 0.2 | | | x | not compatible |
32+
| tf.net 0.2x | | x | x | |
33+
| tf.net 0.15 | x | x | | |
34+
| tf.net 0.14 | x | | | |
3535

3636
Troubleshooting of running example or installation, please refer [here](tensorflowlib/README.md).
3737

src/SciSharp.TensorFlow.Redist/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,19 @@ https://www.nuget.org/packages/SciSharp.TensorFlow.Redist
2222

2323
Related merged [commits](https://github.com/SciSharp/TensorFlow.NET/commit/854a5ba61ad0e400623821236bd117cc24c6cb77).
2424

25+
26+
27+
#### Download pre-build package
28+
29+
[Mac OSX CPU](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-2.4.0.tar.gz), [Linux CPU](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.4.0.tar.gz), [Linux GPU](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-2.4.0.tar.gz), [Windows CPU](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-2.4.0.tar.gz), [Windows GPU](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-windows-x86_64-2.4.0.zip)
30+
31+
32+
2533
#### Pack and Deploy ####
2634

2735
On Windows, the tar command does not support extracting archives with symlinks. So when `dotnet pack` runs on Windows it will only package the Windows binaries.
2836

2937
1. Run `dotnet pack SciSharp.TensorFlow.Redist.nupkgproj` under `src/SciSharp.TensorFlow.Redist` directory in Linux.
30-
2. Run `dotnet nuget push SciSharp.TensorFlow.Redist.2.3.1.nupkg -k APIKEY -s https://api.nuget.org/v3/index.json -t 600`
38+
2. Run `dotnet nuget push SciSharp.TensorFlow.Redist.2.4.0.nupkg -k APIKEY -s https://api.nuget.org/v3/index.json -t 600`
3139

3240

src/TensorFlowNET.Core/Data/DatasetV2.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using System.Linq;
55
using Tensorflow.Framework.Models;
6+
using static Tensorflow.Binding;
67

78
namespace Tensorflow
89
{
@@ -98,6 +99,20 @@ public IDatasetV2 apply_options()
9899
return dataset;
99100
}
100101

102+
public Tensor dataset_cardinality(string name = null)
103+
{
104+
if (tf.Context.executing_eagerly())
105+
{
106+
var results = tf.Runner.TFE_FastPathExecute(tf.Context, tf.Context.DeviceName,
107+
"DatasetCardinality", name,
108+
null,
109+
variant_tensor);
110+
return results[0];
111+
}
112+
113+
throw new NotImplementedException("");
114+
}
115+
101116
public override string ToString()
102117
=> $"{GetType().Name} shapes: {string.Join(", ", structure.Select(x => x.shape))}, types: {string.Join(", ", structure.Select(x => "tf." + x.dtype.as_numpy_name()))}";
103118

@@ -117,7 +132,9 @@ public override string ToString()
117132
break;
118133
}
119134

120-
yield return (results[0], results.Length == 1 ? null : results[1]);
135+
yield return results.Length == 2
136+
? (results[0], results[1])
137+
: (null, results[0]);
121138
}
122139
}
123140

src/TensorFlowNET.Core/Data/IDatasetV2.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,7 @@ IDatasetV2 map(Func<Tensor, (Tensor, Tensor), (Tensor, Tensor)> map_func,
7474
/// </summary>
7575
/// <returns></returns>
7676
IDatasetV2 apply_options();
77+
78+
Tensor dataset_cardinality(string name = null);
7779
}
7880
}

src/TensorFlowNET.Core/Data/MapDataset.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using Tensorflow.Functions;
3+
using static Tensorflow.Binding;
34

45
namespace Tensorflow
56
{
@@ -14,7 +15,12 @@ public MapDataset(IDatasetV2 input_dataset,
1415
bool preserve_cardinality = false,
1516
bool use_legacy_function = false) : base(input_dataset)
1617
{
17-
var func = new ConcreteFunction(map_func, input_dataset.element_spec[0].dtype);
18+
using var func = new ConcreteFunction($"autograph_{map_func.Method.Name}");
19+
var input = tf.placeholder(input_dataset.element_spec[0].dtype);
20+
var output = map_func(input);
21+
func.ToGraph(input, output);
22+
23+
structure = func.OutputStructure;
1824

1925
variant_tensor = ops.map_dataset(input_dataset.variant_tensor,
2026
func,

src/TensorFlowNET.Core/Functions/ConcreteFunction.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ public void ToGraph(Tensors inputs, Tensors outputs)
109109
inputs,
110110
outputs,
111111
null);
112+
113+
OutputStructure = outputs.Select(x => x.ToTensorSpec()).ToArray();
112114
}
113115

114116
public Tensors Invoke(Tensors inputs)
@@ -128,6 +130,9 @@ ForwardBackwardCall SelectForwardAndBackwardFunctions(Tensors args, int possible
128130
return new ForwardBackwardCall(functions, args, tape_watching: true);
129131
}
130132

133+
public override string ToString()
134+
=> Name;
135+
131136
public void Dispose()
132137
{
133138
c_api.TFE_ContextRemoveFunction(tf.Context.Handle, Name, tf.Status.Handle);

src/TensorFlowNET.Core/Keras/ArgsDefinition/TensorLikeDataAdapterArgs.cs renamed to src/TensorFlowNET.Core/Keras/ArgsDefinition/DataAdapterArgs.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
namespace Tensorflow.Keras.ArgsDefinition
44
{
5-
public class TensorLikeDataAdapterArgs
5+
public class DataAdapterArgs
66
{
77
public Tensor X { get; set; }
88
public Tensor Y { get; set; }
9+
public IDatasetV2 Dataset { get; set; }
910
public int BatchSize { get; set; } = 32;
1011
public int Steps { get; set; }
1112
public int Epochs { get; set; }

src/TensorFlowNET.Core/Keras/ArgsDefinition/DataHandlerArgs.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class DataHandlerArgs
66
{
77
public Tensor X { get; set; }
88
public Tensor Y { get; set; }
9+
public IDatasetV2 Dataset { get; set; }
910
public int BatchSize { get; set; } = 32;
1011
public int StepsPerEpoch { get; set; } = -1;
1112
public int InitialEpoch { get; set; } = 0;

src/TensorFlowNET.Core/Operations/image_ops_impl.cs

Lines changed: 63 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,74 +1702,79 @@ public static Tensor sobel_edges(Tensor image)
17021702
public static Tensor decode_image(Tensor contents, int channels = 0, TF_DataType dtype = TF_DataType.TF_UINT8,
17031703
string name = null, bool expand_animations = true)
17041704
{
1705-
Func<ITensorOrOperation> _jpeg = () =>
1705+
return tf_with(ops.name_scope(name, "decode_image"), scope =>
17061706
{
1707-
int jpeg_channels = channels;
1708-
var good_channels = math_ops.not_equal(jpeg_channels, 4, name: "check_jpeg_channels");
1709-
string channels_msg = "Channels must be in (None, 0, 1, 3) when decoding JPEG 'images'";
1710-
var assert_channels = control_flow_ops.Assert(good_channels, new string[] { channels_msg });
1711-
return tf_with(ops.control_dependencies(new[] { assert_channels }), delegate
1707+
var substr = tf.strings.substr(contents, 0, 3);
1708+
1709+
Func<ITensorOrOperation> _jpeg = () =>
17121710
{
1713-
return convert_image_dtype(gen_image_ops.decode_jpeg(contents, channels), dtype);
1714-
});
1715-
};
1711+
int jpeg_channels = channels;
1712+
var good_channels = math_ops.not_equal(jpeg_channels, 4, name: "check_jpeg_channels");
1713+
string channels_msg = "Channels must be in (None, 0, 1, 3) when decoding JPEG 'images'";
1714+
var assert_channels = control_flow_ops.Assert(good_channels, new string[] { channels_msg });
1715+
return tf_with(ops.control_dependencies(new[] { assert_channels }), delegate
1716+
{
1717+
return convert_image_dtype(gen_image_ops.decode_jpeg(contents, channels), dtype);
1718+
});
1719+
};
17161720

1717-
Func<ITensorOrOperation> _gif = () =>
1718-
{
1719-
int gif_channels = channels;
1720-
var good_channels = math_ops.logical_and(
1721-
math_ops.not_equal(gif_channels, 1, name: "check_gif_channels"),
1722-
math_ops.not_equal(gif_channels, 4, name: "check_gif_channels"));
1723-
1724-
string channels_msg = "Channels must be in (None, 0, 3) when decoding GIF images";
1725-
var assert_channels = control_flow_ops.Assert(good_channels, new string[] { channels_msg });
1726-
return tf_with(ops.control_dependencies(new[] { assert_channels }), delegate
1721+
/*Func<ITensorOrOperation> _gif = () =>
17271722
{
1728-
var result = convert_image_dtype(gen_image_ops.decode_gif(contents), dtype);
1729-
if (!expand_animations)
1730-
result = array_ops.gather(result, 0);
1731-
return result;
1732-
});
1733-
};
1723+
int gif_channels = channels;
1724+
var good_channels = math_ops.logical_and(
1725+
math_ops.not_equal(gif_channels, 1, name: "check_gif_channels"),
1726+
math_ops.not_equal(gif_channels, 4, name: "check_gif_channels"));
1727+
1728+
string channels_msg = "Channels must be in (None, 0, 3) when decoding GIF images";
1729+
var assert_channels = control_flow_ops.Assert(good_channels, new string[] { channels_msg });
1730+
return tf_with(ops.control_dependencies(new[] { assert_channels }), delegate
1731+
{
1732+
var result = convert_image_dtype(gen_image_ops.decode_gif(contents), dtype);
1733+
if (!expand_animations)
1734+
result = array_ops.gather(result, 0);
1735+
return result;
1736+
});
1737+
};
17341738
1735-
Func<ITensorOrOperation> _bmp = () =>
1736-
{
1737-
int bmp_channels = channels;
1738-
var signature = tf.strings.substr(contents, 0, 2);
1739-
var is_bmp = math_ops.equal(signature, "BM", name: "is_bmp");
1740-
string decode_msg = "Unable to decode bytes as JPEG, PNG, GIF, or BMP";
1741-
var assert_decode = control_flow_ops.Assert(is_bmp, new string[] { decode_msg });
1742-
var good_channels = math_ops.not_equal(bmp_channels, 1, name: "check_channels");
1743-
string channels_msg = "Channels must be in (None, 0, 3) when decoding BMP images";
1744-
var assert_channels = control_flow_ops.Assert(good_channels, new string[] { channels_msg });
1745-
return tf_with(ops.control_dependencies(new[] { assert_decode, assert_channels }), delegate
1739+
Func<ITensorOrOperation> _bmp = () =>
17461740
{
1747-
return convert_image_dtype(gen_image_ops.decode_bmp(contents), dtype);
1748-
});
1749-
};
1741+
int bmp_channels = channels;
1742+
var signature = tf.strings.substr(contents, 0, 2);
1743+
var is_bmp = math_ops.equal(signature, "BM", name: "is_bmp");
1744+
string decode_msg = "Unable to decode bytes as JPEG, PNG, GIF, or BMP";
1745+
var assert_decode = control_flow_ops.Assert(is_bmp, new string[] { decode_msg });
1746+
var good_channels = math_ops.not_equal(bmp_channels, 1, name: "check_channels");
1747+
string channels_msg = "Channels must be in (None, 0, 3) when decoding BMP images";
1748+
var assert_channels = control_flow_ops.Assert(good_channels, new string[] { channels_msg });
1749+
return tf_with(ops.control_dependencies(new[] { assert_decode, assert_channels }), delegate
1750+
{
1751+
return convert_image_dtype(gen_image_ops.decode_bmp(contents), dtype);
1752+
});
1753+
};
17501754
1751-
Func<ITensorOrOperation> _png = () =>
1752-
{
1753-
return convert_image_dtype(gen_image_ops.decode_png(
1754-
contents,
1755-
channels,
1756-
dtype: dtype),
1757-
dtype);
1758-
};
1755+
Func<ITensorOrOperation> _png = () =>
1756+
{
1757+
return convert_image_dtype(gen_image_ops.decode_png(
1758+
contents,
1759+
channels,
1760+
dtype: dtype),
1761+
dtype);
1762+
};
17591763
1760-
Func<ITensorOrOperation> check_gif = () =>
1761-
{
1762-
return control_flow_ops.cond(is_gif(contents), _gif, _bmp, name: "cond_gif");
1763-
};
1764+
Func<ITensorOrOperation> check_gif = () =>
1765+
{
1766+
var gif = tf.constant(new byte[] { 0x47, 0x49, 0x46 }, TF_DataType.TF_STRING);
1767+
var is_gif = math_ops.equal(substr, gif, name: name);
1768+
return control_flow_ops.cond(is_gif, _gif, _bmp, name: "cond_gif");
1769+
};
17641770
1765-
Func<ITensorOrOperation> check_png = () =>
1766-
{
1767-
return control_flow_ops.cond(is_png(contents), _png, check_gif, name: "cond_png");
1768-
};
1771+
Func<ITensorOrOperation> check_png = () =>
1772+
{
1773+
return control_flow_ops.cond(is_png(contents), _png, check_gif, name: "cond_png");
1774+
};*/
17691775

1770-
return tf_with(ops.name_scope(name, "decode_image"), scope =>
1771-
{
1772-
return control_flow_ops.cond(is_jpeg(contents), _jpeg, check_png, name: "cond_jpeg");
1776+
// return control_flow_ops.cond(is_jpeg(contents), _jpeg, check_png, name: "cond_jpeg");
1777+
return _jpeg() as Tensor;
17731778
});
17741779
}
17751780

src/TensorFlowNET.Core/Tensorflow.Binding.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<AssemblyName>TensorFlow.NET</AssemblyName>
66
<RootNamespace>Tensorflow</RootNamespace>
77
<TargetTensorFlow>2.2.0</TargetTensorFlow>
8-
<Version>0.31.1</Version>
8+
<Version>0.31.2</Version>
99
<LangVersion>8.0</LangVersion>
1010
<Authors>Haiping Chen, Meinrad Recheis, Eli Belash</Authors>
1111
<Company>SciSharp STACK</Company>
@@ -19,7 +19,7 @@
1919
<Description>Google's TensorFlow full binding in .NET Standard.
2020
Building, training and infering deep learning models.
2121
https://tensorflownet.readthedocs.io</Description>
22-
<AssemblyVersion>0.31.1.0</AssemblyVersion>
22+
<AssemblyVersion>0.31.2.0</AssemblyVersion>
2323
<PackageReleaseNotes>tf.net 0.20.x and above are based on tensorflow native 2.x.
2424

2525
* Eager Mode is added finally.
@@ -30,7 +30,7 @@ https://tensorflownet.readthedocs.io</Description>
3030
TensorFlow .NET v0.30 is focused on making more Keras API work including:
3131
* tf.keras.datasets
3232
* Building keras model in subclass, functional and sequential api</PackageReleaseNotes>
33-
<FileVersion>0.31.1.0</FileVersion>
33+
<FileVersion>0.31.2.0</FileVersion>
3434
<PackageLicenseFile>LICENSE</PackageLicenseFile>
3535
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
3636
<SignAssembly>true</SignAssembly>

0 commit comments

Comments
 (0)