Open thong12889 opened 3 years ago
Can you provide the full reproduce environment?
public static string GetFormattedString(TF_DataType dtype, NDArray nd)
{
if (nd.size == 0)
return "[]";
switch (dtype)
{
case TF_DataType.TF_STRING:
return string.Join(string.Empty, nd.ToArray<byte>()
.Select(x => x < 32 || x > 127 ? "\\x" + x.ToString("x") : Convert.ToChar(x).ToString()));
case TF_DataType.TF_BOOL:
return (nd.GetByte(0) > 0).ToString();
case TF_DataType.TF_RESOURCE:
return "<unprintable>";
default:
return nd.ToString();
}
}
private void predictBtn_Click(object sender, EventArgs e)
{
var imgByte = File.ReadAllBytes(imageDir);
var imgNDarr = np.array(imgByte);
var imgByteString = GetFormattedString(TF_DataType.TF_STRING, imgNDarr);
using (var sess = Session.LoadFromSavedModel(pbFile))
{
var graph = sess.graph;
Tensor tensorNum = graph.OperationByName("num_detections");
Tensor tensorBoxes = graph.OperationByName("detection_boxes");
Tensor tensorScores = graph.OperationByName("detection_scores");
Tensor tensorClasses = graph.OperationByName("detection_classes");
Tensor imgTensor = graph.OperationByName("encoded_image_string_tensor");
Tensor[] outTensorArr = new Tensor[] { tensorNum, tensorBoxes, tensorScores, tensorClasses };
var results = sess.run(outTensorArr, new FeedItem(imgTensor, imgByteString));
buildOutputImage(results);
}
}
Did you mean this ?
Correct, but where is the pb file?
Sorry, here is my pb file.
https://drive.google.com/file/d/1lFzFnGz8AeFtn9i8mN5ZxVZWcudcCvT8/view?usp=sharing
I exported model from Cloud AutoML and my input name is "encoded_image_string_tensor".
How can I convert image to 1-D string ?
P.S. I can use this model in python.