Skip to content

Commit b345efa

Browse files
committed
Solve ObjectDetection functions
1 parent cc0b994 commit b345efa

4 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/TensorFlowNET.Core/Sessions/BaseSession.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ private unsafe NDArray fetchValue(IntPtr output)
217217
var str = UTF8Encoding.Default.GetString(bytes, 9, bytes[8]);
218218
nd = np.array(str).reshape();
219219
break;
220+
case TF_DataType.TF_UINT8:
221+
var _bytes = new byte[tensor.size];
222+
for (ulong i = 0; i < tensor.size; i++)
223+
_bytes[i] = *(byte*)(offset + (int)(tensor.itemsize * i));
224+
nd = np.array(_bytes).reshape(ndims);
225+
break;
220226
case TF_DataType.TF_INT16:
221227
var shorts = new short[tensor.size];
222228
for (ulong i = 0; i < tensor.size; i++)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ private IntPtr Allocate(NDArray nd)
6767
case "Double":
6868
Marshal.Copy(nd1.Data<double>(), 0, dotHandle, nd.size);
6969
break;
70-
//case "Byte":
70+
case "Byte":
71+
Marshal.Copy(nd1.Data<byte>(), 0, dotHandle, nd.size);
7172
/*var bb = nd.Data<byte>();
7273
var bytes = Marshal.AllocHGlobal(bb.Length);
7374
Marshal.Copy(bb, 0, bytes, bb.Length);

src/TensorFlowNET.Core/Tensors/Tensor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ public TF_DataType ToTFDataType(Type type)
195195
case "Double":
196196
return TF_DataType.TF_DOUBLE;
197197
case "Byte":
198+
return TF_DataType.TF_UINT8;
198199
case "String":
199200
return TF_DataType.TF_STRING;
200201
default:

test/TensorFlowNET.Examples/ObjectDetection.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class ObjectDetection : Python, IExample
2828

2929
public bool Run()
3030
{
31-
//buildOutputImage(null);
31+
PrepareData();
3232

3333
// read in the input image
3434
var imgArr = ReadTensorFromImageFile(Path.Join(imageDir, "input.jpg"));
@@ -91,7 +91,7 @@ public void PrepareData()
9191
// download the pbtxt file
9292
if (!File.Exists(Path.Join(modelDir, "mscoco_label_map.pbtxt")))
9393
{
94-
string url = $"https://github.com/tensorflow/models/blob/master/research/object_detection/data/mscoco_label_map.pbtxt";
94+
string url = $"https://raw.githubusercontent.com/tensorflow/models/master/research/object_detection/data/mscoco_label_map.pbtxt";
9595
Utility.Web.Download(url, modelDir, "mscoco_label_map.pbtxt");
9696
}
9797
}
@@ -123,7 +123,6 @@ private void buildOutputImage(NDArray[] resultArr)
123123
float score = scores[i];
124124
if (score > MIN_SCORE)
125125
{
126-
//var boxes = resultArr[1].Data<float[,,]>();
127126
float[] boxes = resultArr[1].Data<float>();
128127
float top = boxes[i * 4] * bitmap.Height;
129128
float left = boxes[i * 4 + 1] * bitmap.Width;

0 commit comments

Comments
 (0)