Skip to content

Commit f1b7e11

Browse files
committed
yolo.build_nework() SciSharp#359
1 parent 8f258c5 commit f1b7e11

17 files changed

Lines changed: 257 additions & 31 deletions

File tree

src/TensorFlowHub/TensorFlowHub.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
<PackageIconUrl>https://avatars3.githubusercontent.com/u/44989469?s=200&amp;v=4</PackageIconUrl>
1818
</PropertyGroup>
1919
<ItemGroup>
20-
<PackageReference Include="NumSharp" Version="0.20.0" />
20+
<PackageReference Include="NumSharp" Version="0.20.1" />
2121
</ItemGroup>
2222
</Project>

src/TensorFlowNET.Core/APIs/tf.array.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ namespace Tensorflow
2222
{
2323
public partial class tensorflow
2424
{
25+
/// <summary>
26+
/// A convenient alias for None, useful for indexing arrays.
27+
/// </summary>
28+
public string newaxis = "";
29+
2530
/// <summary>
2631
/// Concatenates tensors along one dimension.
2732
/// </summary>

src/TensorFlowNET.Core/APIs/tf.math.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ public Tensor divide<T>(Tensor x, T[] y, string name = null) where T : struct
315315
public Tensor pow<T1, T2>(T1 x, T2 y)
316316
=> gen_math_ops.pow(x, y);
317317

318+
public Tensor range(object start, object limit = null, object delta = null, TF_DataType dtype = TF_DataType.DtInvalid, string name = "range")
319+
=> math_ops.range(start, limit: limit, delta: delta, dtype: dtype, name: name);
320+
318321
/// <summary>
319322
/// Computes the sum of elements across dimensions of a tensor.
320323
/// </summary>
@@ -325,10 +328,12 @@ public Tensor reduce_sum(Tensor input, int? axis = null, int? reduction_indices
325328
{
326329
if(!axis.HasValue && reduction_indices.HasValue)
327330
return math_ops.reduce_sum(input, reduction_indices.Value);
331+
else if (axis.HasValue && !reduction_indices.HasValue)
332+
return math_ops.reduce_sum(input, axis.Value);
328333
return math_ops.reduce_sum(input);
329334
}
330335

331-
public Tensor reduce_sum(Tensor input, int axis, int? reduction_indices = null)
336+
public Tensor reduce_sum(Tensor input, int[] axis, int? reduction_indices = null)
332337
=> math_ops.reduce_sum(input, axis);
333338

334339
/// <summary>

src/TensorFlowNET.Core/APIs/tf.reshape.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ namespace Tensorflow
1818
{
1919
public partial class tensorflow
2020
{
21-
public Tensor reshape(Tensor tensor,
22-
Tensor shape,
21+
public Tensor reshape<T1, T2>(T1 tensor,
22+
T2 shape,
2323
string name = null) => gen_array_ops.reshape(tensor, shape, name);
2424

2525
public Tensor reshape(Tensor tensor,

src/TensorFlowNET.Core/APIs/tf.tile.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@ namespace Tensorflow
2020
{
2121
public partial class tensorflow
2222
{
23-
public Tensor tile(Tensor input,
24-
Tensor multiples,
23+
public Tensor tile<T>(Tensor input,
24+
T multiples,
2525
string name = null) => gen_array_ops.tile(input, multiples, name);
26-
public Tensor tile(NDArray input,
27-
int[] multiples,
28-
string name = null) => gen_array_ops.tile(input, multiples, name);
29-
3026
}
3127
}

src/TensorFlowNET.Core/Operations/gen_array_ops.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public static (Tensor, Tensor) broadcast_gradient_args(Tensor s0, Tensor s1, str
224224
public static Tensor reshape<T1, T2>(T1 tensor, T2 shape, string name = null)
225225
{
226226
var _op = _op_def_lib._apply_op_helper("Reshape", name, new { tensor, shape });
227-
return _op.outputs[0];
227+
return _op.output;
228228
}
229229

230230
public static Tensor reshape(Tensor tensor, int[] shape, string name = null)
@@ -334,12 +334,7 @@ public static Tensor[] split(Tensor axis, Tensor value, int num_split, string na
334334
return _op.outputs;
335335
}
336336

337-
public static Tensor tile(Tensor input, Tensor multiples, string name = null)
338-
{
339-
var _op = _op_def_lib._apply_op_helper("Tile", name, new { input, multiples });
340-
return _op.outputs[0];
341-
}
342-
public static Tensor tile(NDArray input, int[] multiples, string name = null)
337+
public static Tensor tile<T>(Tensor input, T multiples, string name = null)
343338
{
344339
var _op = _op_def_lib._apply_op_helper("Tile", name, new { input, multiples });
345340
return _op.outputs[0];

src/TensorFlowNET.Core/Operations/math_ops.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,13 @@ public static Tensor reduce_sum(Tensor input_tensor, Tensor axis = null, bool ke
422422
return _may_reduce_to_scalar(keepdims, axis, m);
423423
}
424424

425+
public static Tensor reduce_sum(Tensor input_tensor, int[] axis, bool keepdims = false, string name = null)
426+
{
427+
var r = _ReductionDims(input_tensor, axis);
428+
var m = gen_math_ops._sum(input_tensor, r, keep_dims: keepdims, name: name);
429+
return _may_reduce_to_scalar(keepdims, axis, m);
430+
}
431+
425432
public static Tensor reduce_sum(Tensor input_tensor, int axis, bool keepdims = false, string name = null)
426433
{
427434
var m = gen_math_ops._sum(input_tensor, axis, keep_dims: keepdims, name: name);
@@ -492,7 +499,7 @@ private static Tensor _ReductionDims(Tensor x, int[] axis)
492499
public static Tensor rsqrt(Tensor x, string name = null)
493500
=> gen_math_ops.rsqrt(x, name: name);
494501

495-
public static Tensor range(object start, object limit = null, object delta = null, TF_DataType dtype = TF_DataType.DtInvalid, string name = "range" )
502+
public static Tensor range(object start, object limit = null, object delta = null, TF_DataType dtype = TF_DataType.DtInvalid, string name = "range")
496503
{
497504
if(limit == null)
498505
{

src/TensorFlowNET.Core/TensorFlowNET.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Docs: https://tensorflownet.readthedocs.io</Description>
6262

6363
<ItemGroup>
6464
<PackageReference Include="Google.Protobuf" Version="3.5.1" />
65-
<PackageReference Include="NumSharp" Version="0.20.0" />
65+
<PackageReference Include="NumSharp" Version="0.20.1" />
6666
</ItemGroup>
6767

6868
<ItemGroup>

src/TensorFlowNET.Core/Tensors/Tensor.Index.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public Tensor this[params string[] slices]
3131
{
3232
get
3333
{
34-
var slice_spec = slices.Select(x => x == null ? null : new Slice(x)).ToArray();
34+
var slice_spec = slices.Select(x => new Slice(x)).ToArray();
3535
var begin = new List<int>();
3636
var end = new List<int>();
3737
var strides = new List<int>();
@@ -43,13 +43,20 @@ public Tensor this[params string[] slices]
4343

4444
foreach (var s in slice_spec)
4545
{
46-
if(s == null)
46+
if(s.IsNewAxis)
4747
{
4848
begin.Add(0);
4949
end.Add(0);
50-
strides.Add(0);
50+
strides.Add(1);
5151
new_axis_mask |= (1 << index);
5252
}
53+
else if (s.IsEllipsis)
54+
{
55+
begin.Add(0);
56+
end.Add(0);
57+
strides.Add(1);
58+
ellipsis_mask |= (1 << index);
59+
}
5360
else
5461
{
5562
if (s.Start.HasValue)

src/TensorFlowNET.Core/Tensors/TensorShape.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ public TensorShape concatenate(TensorShape other)
143143
}
144144
}
145145

146+
public TensorShape merge_with(TensorShape other)
147+
{
148+
if (dims.Length == 0)
149+
return other;
150+
151+
throw new NotImplementedException("merge_with");
152+
}
153+
146154
public override string ToString()
147155
{
148156
return shape.ToString();

0 commit comments

Comments
 (0)