Skip to content

Commit 9264a19

Browse files
committed
fix string data.
1 parent d3e2124 commit 9264a19

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎src/TensorFlowNET.Core/NumPy/NDArray.Implicit.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static implicit operator NDArray(double value)
3737
=> new NDArray(value);
3838

3939
public static implicit operator Tensor(NDArray nd)
40-
=> constant_op.constant(nd);
40+
=> nd._tensor;
4141

4242
public static implicit operator NDArray(Tensor tensor)
4343
=> new NDArray(tensor);

‎src/TensorFlowNET.Core/Tensors/Tensor.Value.cs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ public NDArray numpy()
4949

5050
protected NDArray GetNDArray(TF_DataType dtype)
5151
{
52-
/*if (dtype == TF_DataType.TF_STRING)
53-
return np.array(StringData());*/
52+
if (dtype == TF_DataType.TF_STRING)
53+
{
54+
var str= StringData();
55+
return new NDArray(str, new Shape(str.Length));
56+
}
57+
5458
return new NDArray(this);
5559
}
5660

‎src/TensorFlowNET.Core/ops.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ public static Tensor convert_to_tensor(object value,
171171
_ => constant_op.constant(value, dtype: dtype, name: name)
172172
};
173173

174+
if (dtype == TF_DataType.TF_STRING)
175+
return ret;
176+
174177
var original_dtype = value.GetDataType();
175178
if (dtype != TF_DataType.DtInvalid && dtype != original_dtype)
176179
ret = gen_math_ops.cast(ret, dtype.as_base_dtype(), name: name);

0 commit comments

Comments
 (0)