Skip to content

Commit 9d08a31

Browse files
committed
Keras for .NET package meta and clean code.
1 parent 41df785 commit 9d08a31

86 files changed

Lines changed: 940 additions & 1043 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/TensorFlowNET.Console/MemoryMonitor.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Diagnostics;
4-
using System.Text;
53
using static Tensorflow.Binding;
64

75
namespace Tensorflow

src/TensorFlowNET.Console/MemoryTestingCases.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
using NumSharp;
1+
using NumSharp;
2+
using System;
53
using static Tensorflow.Binding;
64

75
namespace Tensorflow
@@ -59,7 +57,7 @@ public Action<int> MathAdd
5957
public Action<int> Gradient
6058
=> (iterate) =>
6159
{
62-
for(int i = 0; i< iterate; i++)
60+
for (int i = 0; i < iterate; i++)
6361
{
6462
var w = tf.constant(3112.0f);
6563
using var tape = tf.GradientTape();

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Tensorflow.Keras.Engine;
2-
3-
namespace Tensorflow.Keras.ArgsDefinition
1+
namespace Tensorflow.Keras.ArgsDefinition
42
{
53
public class NodeArgs
64
{

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Collections.Generic;
2-
using Tensorflow.Keras.Engine;
32

43
namespace Tensorflow.Keras.ArgsDefinition
54
{

src/TensorFlowNET.Core/Keras/Engine/IModel.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
5-
namespace Tensorflow.Keras.Engine
1+
namespace Tensorflow.Keras.Engine
62
{
73
public interface IModel
84
{

src/TensorFlowNET.Core/Keras/Engine/INode.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
1+
using System.Collections.Generic;
42

53
namespace Tensorflow.Keras.Engine
64
{

src/TensorFlowNET.Core/Keras/Layers/ILayer.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
1+
using System.Collections.Generic;
42
using Tensorflow.Keras.Engine;
53

64
namespace Tensorflow.Keras

src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public Normal(Tensor loc, Tensor scale, bool validate_args = false, bool allow_n
5757
this._loc = array_ops.identity(loc, name);
5858
this._scale = array_ops.identity(scale, name);
5959
base._dtype = this._scale.dtype;
60-
// base._reparameterization_type = new ReparameterizationType("FULLY_REPARAMETERIZED");
61-
base._validate_args = validate_args;
60+
// base._reparameterization_type = new ReparameterizationType("FULLY_REPARAMETERIZED");
61+
base._validate_args = validate_args;
6262
base._allow_nan_stats = allow_nan_stats;
6363
base._parameters = parameters;
6464
base._graph_parents = new List<Tensor>(new Tensor[] { this._loc, this._scale });

src/TensorFlowNET.Core/Operations/NnOps/LayerRNNCell.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ You may obtain a copy of the License at
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
******************************************************************************/
16-
using static Tensorflow.Binding;
17-
using Tensorflow.Keras.Engine;
1816
using System;
17+
using Tensorflow.Keras.Engine;
18+
using static Tensorflow.Binding;
1919

2020
namespace Tensorflow
2121
{

src/TensorFlowNET.Core/Operations/image_ops_impl.cs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,9 @@ public static Tensor rot90(Tensor image, int k = 1, string name = null)
242242
image = ops.convert_to_tensor(image, name: "image");
243243
image = _AssertAtLeast3DImage(image);
244244

245-
// can't get k to convert to tensor without throwing error about it being an int---
246-
// might rework later. for now, k2 == k as Tensor
247-
Tensor k2 = ops.convert_to_tensor(k, dtype: dtypes.int32, name: "k");
245+
// can't get k to convert to tensor without throwing error about it being an int---
246+
// might rework later. for now, k2 == k as Tensor
247+
Tensor k2 = ops.convert_to_tensor(k, dtype: dtypes.int32, name: "k");
248248
k2.TensorShape.assert_has_rank(0);
249249
k2 = gen_ops.mod(k2, tf.constant(4));
250250

@@ -465,8 +465,8 @@ public static Tensor pad_to_bounding_box(Tensor image, int offset_height, int of
465465

466466
var assert_ops = _CheckAtLeast3DImage(image, require_static: false);
467467

468-
// batch: [0], height: [1], width: [2], depth: [3]
469-
int[] bhwd = _ImageDimensions(image, rank: 4);
468+
// batch: [0], height: [1], width: [2], depth: [3]
469+
int[] bhwd = _ImageDimensions(image, rank: 4);
470470

471471
var after_padding_width = target_width - offset_width - bhwd[2];
472472

@@ -544,8 +544,8 @@ public static Tensor crop_to_bounding_box(Tensor image, int offset_height, int o
544544

545545
var assert_ops = _CheckAtLeast3DImage(image, require_static: false);
546546

547-
// batch: [0], height: [1], width: [2], depth: [3]
548-
int[] bhwd = _ImageDimensions(image, rank: 4);
547+
// batch: [0], height: [1], width: [2], depth: [3]
548+
int[] bhwd = _ImageDimensions(image, rank: 4);
549549

550550
assert_ops[assert_ops.Length] = _assert(check_ops.assert_greater_equal(tf.constant(offset_height),
551551
tf.constant(0)), typeof(ValueError),
@@ -976,7 +976,7 @@ public static Tensor per_image_standardization(Tensor image)
976976

977977
image = image - image_mean;
978978
image = tf.div(image, adjusted_stddev, name: scope); // name: scope in python version
979-
return convert_image_dtype(image, orig_dtype, saturate: true);
979+
return convert_image_dtype(image, orig_dtype, saturate: true);
980980
});
981981
}
982982

@@ -1177,9 +1177,9 @@ public static Tensor adjust_jpeg_quality(Tensor image, Tensor jpeg_quality, stri
11771177
image = ops.convert_to_tensor(image, name: "image");
11781178
var channels = image.TensorShape.as_list()[image.TensorShape.dims.Length - 1];
11791179
var orig_dtype = image.dtype;
1180-
// python code checks to ensure jpeq_quality is a tensor; unnecessary here since
1181-
// it is passed as a tensor
1182-
image = gen_ops.encode_jpeg_variable_quality(image, quality: jpeg_quality);
1180+
// python code checks to ensure jpeq_quality is a tensor; unnecessary here since
1181+
// it is passed as a tensor
1182+
image = gen_ops.encode_jpeg_variable_quality(image, quality: jpeg_quality);
11831183

11841184
image = gen_ops.decode_jpeg(image, channels: channels);
11851185
return convert_image_dtype(image, orig_dtype, saturate: true);
@@ -1587,8 +1587,8 @@ Tensor[] do_pad(Tensor[] images, Tensor remainder)
15871587
{
15881588
if (k > 0)
15891589
{
1590-
// handle flat_imgs
1591-
Tensor[] flat_imgs = new Tensor[] { };
1590+
// handle flat_imgs
1591+
Tensor[] flat_imgs = new Tensor[] { };
15921592
foreach ((Tensor x, Tensor t) in imgs.Zip(tails, Tuple.Create))
15931593
{
15941594
flat_imgs[flat_imgs.Length] = array_ops.reshape(x, array_ops.concat(new Tensor[] { constant_op.constant(-1), t }, 0));
@@ -1602,42 +1602,42 @@ Tensor[] do_pad(Tensor[] images, Tensor remainder)
16021602
true_fn: () => padded_func_pass(),
16031603
false_fn: () => flat_imgs);
16041604

1605-
// handle downscaled
1606-
Tensor[] downscaled = new Tensor[] { };
1605+
// handle downscaled
1606+
Tensor[] downscaled = new Tensor[] { };
16071607
foreach (Tensor x in padded)
16081608
{
16091609
downscaled[downscaled.Length] = gen_ops.avg_pool(x, ksize: divisor, strides: divisor, padding: "VALID");
16101610
}
16111611

1612-
// handle tails
1613-
tails = new Tensor[] { };
1612+
// handle tails
1613+
tails = new Tensor[] { };
16141614
foreach (Tensor x in gen_array_ops.shape_n(downscaled))
16151615
{
16161616
tails[tails.Length] = new Tensor(x.dims.Skip(1).Take(tails.Length - 1).ToArray());
16171617
}
16181618

16191619
imgs = new Tensor[] { };
1620-
// tuples weren't working; this is hacky, but should work similarly.
1621-
// zip loads the values into a tuple (Tensor, Tensor, Tensor) for each
1622-
// zip entry; this just gets the length of the longest array, and loops
1623-
// that many times, getting values (like zip) and using them similarly.
1624-
for (int x = 0; x < Math.Max(Math.Max(downscaled.Length, heads.Length), tails.Length); x++)
1620+
// tuples weren't working; this is hacky, but should work similarly.
1621+
// zip loads the values into a tuple (Tensor, Tensor, Tensor) for each
1622+
// zip entry; this just gets the length of the longest array, and loops
1623+
// that many times, getting values (like zip) and using them similarly.
1624+
for (int x = 0; x < Math.Max(Math.Max(downscaled.Length, heads.Length), tails.Length); x++)
16251625
{
16261626
imgs[imgs.Length] = array_ops.reshape(downscaled[x], array_ops.concat(new Tensor[] { heads[x], tails[x] }, 0));
16271627
}
16281628
}
16291629
}
16301630

1631-
// python code uses * to unpack imgs; how to replicate that here?
1632-
// don't think that this is doing the same thing as the python code.
1633-
(ssim_per_channel, cs) = _ssim_per_channel(
1634-
img1: imgs[0],
1635-
img2: imgs[1],
1636-
max_val: max_val,
1637-
filter_size: filter_size,
1638-
filter_sigma: filter_sigma,
1639-
k1: k1,
1640-
k2: k2);
1631+
// python code uses * to unpack imgs; how to replicate that here?
1632+
// don't think that this is doing the same thing as the python code.
1633+
(ssim_per_channel, cs) = _ssim_per_channel(
1634+
img1: imgs[0],
1635+
img2: imgs[1],
1636+
max_val: max_val,
1637+
filter_size: filter_size,
1638+
filter_sigma: filter_sigma,
1639+
k1: k1,
1640+
k2: k2);
16411641
mcs.append(gen_nn_ops.relu(cs));
16421642
}
16431643

0 commit comments

Comments
 (0)