From d75527f7eecc4e2fcdd18ab157412506717c8adb Mon Sep 17 00:00:00 2001 From: navanchauhan Date: Mon, 7 Nov 2022 23:36:11 -0700 Subject: add blog post --- .../2019-12-10-TensorFlow-Model-Prediction.html | 42 ++++++++++++++-------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'docs/posts/2019-12-10-TensorFlow-Model-Prediction.html') diff --git a/docs/posts/2019-12-10-TensorFlow-Model-Prediction.html b/docs/posts/2019-12-10-TensorFlow-Model-Prediction.html index 7187fe8..97ad373 100644 --- a/docs/posts/2019-12-10-TensorFlow-Model-Prediction.html +++ b/docs/posts/2019-12-10-TensorFlow-Model-Prediction.html @@ -51,39 +51,53 @@

First we import the following if we have not imported these before

-
import cv2
+
+
import cv2
 import os
-
+
+

Then we read the file using OpenCV.

-
image=cv2.imread(imagePath)
-
+
+
image=cv2.imread(imagePath)
+
+

The cv2. imread() function returns a NumPy array representing the image. Therefore, we need to convert it before we can use it.

-
image_from_array = Image.fromarray(image, 'RGB')
-
+
+
image_from_array = Image.fromarray(image, 'RGB')
+
+

Then we resize the image

-
size_image = image_from_array.resize((50,50))
-
+
+
size_image = image_from_array.resize((50,50))
+
+

After this we create a batch consisting of only one image

-
p = np.expand_dims(size_image, 0)
-
+
+
p = np.expand_dims(size_image, 0)
+
+

We then convert this uint8 datatype to a float32 datatype

-
img = tf.cast(p, tf.float32)
-
+
+
img = tf.cast(p, tf.float32)
+
+

Finally we make the prediction

-
print(['Infected','Uninfected'][np.argmax(model.predict(img))])
-
+
+
print(['Infected','Uninfected'][np.argmax(model.predict(img))])
+
+

Infected

-- cgit v1.2.3