From dde266a520b03a991e49cac94509b58e7b10e7f2 Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Mon, 2 Mar 2020 14:06:59 +0530 Subject: Publish deploy 2020-03-02 14:06 --- .../index 2.html | 23 ++++++++++++++++++++++ .../index 5.html | 23 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 posts/2019-12-10-TensorFlow-Model-Prediction/index 2.html create mode 100644 posts/2019-12-10-TensorFlow-Model-Prediction/index 5.html (limited to 'posts/2019-12-10-TensorFlow-Model-Prediction') diff --git a/posts/2019-12-10-TensorFlow-Model-Prediction/index 2.html b/posts/2019-12-10-TensorFlow-Model-Prediction/index 2.html new file mode 100644 index 0000000..ebd6f4a --- /dev/null +++ b/posts/2019-12-10-TensorFlow-Model-Prediction/index 2.html @@ -0,0 +1,23 @@ +Making Predictions using Image Classifier (TensorFlow) | Navan Chauhan
1 minute readCreated on December 10, 2019Last modified on January 18, 2020

Making Predictions using Image Classifier (TensorFlow)

This was tested on TF 2.x and works as of 2019-12-10

If you want to understand how to make your own custom image classifier, please refer to my previous post.

If you followed my last post, then you created a model which took an image of dimensions 50x50 as an input.

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

import cv2 +import os +
+ +

Then we read the file using OpenCV.

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') +
+ +

Then we resize the image

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) +
+ +

We then convert this uint8 datatype to a float32 datatype

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

Finally we make the prediction

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

Infected

Tagged with:
\ No newline at end of file diff --git a/posts/2019-12-10-TensorFlow-Model-Prediction/index 5.html b/posts/2019-12-10-TensorFlow-Model-Prediction/index 5.html new file mode 100644 index 0000000..ebd6f4a --- /dev/null +++ b/posts/2019-12-10-TensorFlow-Model-Prediction/index 5.html @@ -0,0 +1,23 @@ +Making Predictions using Image Classifier (TensorFlow) | Navan Chauhan
1 minute readCreated on December 10, 2019Last modified on January 18, 2020

Making Predictions using Image Classifier (TensorFlow)

This was tested on TF 2.x and works as of 2019-12-10

If you want to understand how to make your own custom image classifier, please refer to my previous post.

If you followed my last post, then you created a model which took an image of dimensions 50x50 as an input.

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

import cv2 +import os +
+ +

Then we read the file using OpenCV.

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') +
+ +

Then we resize the image

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) +
+ +

We then convert this uint8 datatype to a float32 datatype

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

Finally we make the prediction

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

Infected

Tagged with:
\ No newline at end of file -- cgit v1.2.3