FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix allocate tensor for string #171 · MSavameri/TensorFlow.NET@2579afc · GitHub

Repository navigation

Commit 2579afc

Browse files
committed
Fix allocate tensor for string SciSharp#171
1 parent 8ae2feb commit 2579afc

2 files changed

Lines changed: 10 additions & 18 deletions

File tree

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ private IntPtr Allocate(NDArray nd)
3636
size = (ulong)(nd.size * nd.dtypesize);
3737
}
3838

39+
var dataType = ToTFDataType(nd.dtype);
40+
// shape
41+
var dims = nd.shape.Select(x => (long)x).ToArray();
42+
3943
switch (nd.dtype.Name)
4044
{
4145
case "Int16":
@@ -51,37 +55,25 @@ private IntPtr Allocate(NDArray nd)
5155
Marshal.Copy(nd.Data<double>(), 0, dotHandle, nd.size);
5256
break;
5357
case "String":
54-
/*var value = nd.Data<string>()[0];
55-
var bytes = Encoding.UTF8.GetBytes(value);
56-
dotHandle = Marshal.AllocHGlobal(bytes.Length + 1);
57-
Marshal.Copy(bytes, 0, dotHandle, bytes.Length);
58-
size = (ulong)bytes.Length;*/
59-
6058
var str = nd.Data<string>()[0];
6159
ulong dst_len = c_api.TF_StringEncodedSize((ulong)str.Length);
62-
//dotHandle = Marshal.AllocHGlobal((int)dst_len);
63-
//size = c_api.TF_StringEncode(str, (ulong)str.Length, dotHandle, dst_len, status);
64-
6560
var dataType1 = ToTFDataType(nd.dtype);
6661
// shape
6762
var dims1 = nd.shape.Select(x => (long)x).ToArray();
6863

6964
var tfHandle1 = c_api.TF_AllocateTensor(dataType1,
7065
dims1,
7166
nd.ndim,
72-
dst_len);
67+
dst_len + sizeof(Int64));
7368

7469
dotHandle = c_api.TF_TensorData(tfHandle1);
75-
c_api.TF_StringEncode(str, (ulong)str.Length, dotHandle, dst_len, status);
70+
Marshal.WriteInt64(dotHandle, 0);
71+
c_api.TF_StringEncode(str, (ulong)str.Length, dotHandle + sizeof(Int64), dst_len, status);
7672
return tfHandle1;
77-
break;
7873
default:
7974
throw new NotImplementedException("Marshal.Copy failed.");
8075
}
81-
82-
var dataType = ToTFDataType(nd.dtype);
83-
// shape
84-
var dims = nd.shape.Select(x => (long)x).ToArray();
76+
8577
// Free the original buffer and set flag
8678
Deallocator deallocator = (IntPtr values, IntPtr len, ref bool closure) =>
8779
{

‎src/TensorFlowNET.Core/Train/Saving/Saver.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ public string save(Session sess,
162162

163163
if (!_is_empty)
164164
{
165-
var model_checkpoint_path1 = sess.run(_saver_def.SaveTensorName, new FeedItem[] {
165+
model_checkpoint_path = sess.run(_saver_def.SaveTensorName, new FeedItem[] {
166166
new FeedItem(_saver_def.FilenameTensorName, checkpoint_file)
167167
});
168168
}
169169

170-
throw new NotImplementedException("");
170+
throw new NotImplementedException("Saver.save");
171171

172172
return model_checkpoint_path;
173173
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL