.NET based ecosystem of open-source software for mathematics, science, and engineering.
static SciSharp.Models.IImageClassificationTask task ;
tensorflow tf = new tensorflow();
SciSharp.Models.ModelWizard wizard = new SciSharp.Models.ModelWizard();
public void Predict(string PascImage) {
var img_bgr = CvInvoke.Imread(PascImage, Emgu.CV.CvEnum.ImreadModes.Color);
Mat output = new Mat();
CvInvoke.CvtColor(img_bgr, output, Emgu.CV.CvEnum.ColorConversion. Bgr2Rgb);
var output1 = output.ToImage<Rgb,byte>().Resize(299,299,Emgu.CV.CvEnum.Inter.Linear);
output1.ToUMat().ConvertTo(output, Emgu.CV.CvEnum.DepthType.Cv32F, 1.0f / 255.0f);
NDArray imgR = np.array(output.GetData() ,TF_DataType.TF_FLOAT);
//keras.backend.clear_session();
Tensor tensorr = tf.convert_to_tensor( imgR);
var img_final = tf.expand_dims(tensorr, 0);
//predict image
if (task == null) {
task = wizard.AddImageClassificationTask<TransferLearning>(new SciSharp.Models.TaskOptions{
ModelPath = @"image_classification_v1\saved_model.pb"
}
);}
//works well but only from the file
//var imgPath = Path.Join(PascImage);
//input = SciSharp.Models.ImageUtil.ReadImageFromFile(imgPath);
SciSharp.Models.ModelPredictResult result = task.Predict(img_final);
}
var tensorr = tf.constant(imgR)
to initialize a tensor?
@uzfm Are you saying theimg_final
is empty when second prediction? Yes.
I tried many options but nothing helped.
"var tensorr = tf.constant (imgR)" also doesn't work
@uzfm @vshakhlin Just upgrade to v0.3.1 https://www.nuget.org/packages/SciSharp.Models.ImageClassification/0.3.1, it will resolve the prediction issue.
Thank you very much!!! works great.
Is it possible to see the result of the prediction for all classes?