summaryrefslogtreecommitdiff
path: root/posts/2019-12-10-TensorFlow-Model-Prediction/index.html
diff options
context:
space:
mode:
authorNavan Chauhan <navanchauhan@gmail.com>2020-01-14 23:03:43 +0530
committerNavan Chauhan <navanchauhan@gmail.com>2020-01-14 23:03:43 +0530
commit81ae1cfaf44f9f188e35936a660e82a4e9af238e (patch)
tree81e272000149357b93b8f0e7af809375979642af /posts/2019-12-10-TensorFlow-Model-Prediction/index.html
parent562c929cd8b75d08d8ca368e0400c70188cd35a4 (diff)
Publish deploy 2020-01-14 23:03
Diffstat (limited to 'posts/2019-12-10-TensorFlow-Model-Prediction/index.html')
-rw-r--r--posts/2019-12-10-TensorFlow-Model-Prediction/index.html9
1 files changed, 9 insertions, 0 deletions
diff --git a/posts/2019-12-10-TensorFlow-Model-Prediction/index.html b/posts/2019-12-10-TensorFlow-Model-Prediction/index.html
new file mode 100644
index 0000000..daab780
--- /dev/null
+++ b/posts/2019-12-10-TensorFlow-Model-Prediction/index.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"/><meta name="og:site_name" content="Navan Chauhan"/><link rel="canonical" href="https://navanchauhan.github.io/posts/2019-12-10-TensorFlow-Model-Prediction"/><meta name="twitter:url" content="https://navanchauhan.github.io/posts/2019-12-10-TensorFlow-Model-Prediction"/><meta name="og:url" content="https://navanchauhan.github.io/posts/2019-12-10-TensorFlow-Model-Prediction"/><title>Making Predictions using Image Classifier (TensorFlow) | Navan Chauhan</title><meta name="twitter:title" content="Making Predictions using Image Classifier (TensorFlow) | Navan Chauhan"/><meta name="og:title" content="Making Predictions using Image Classifier (TensorFlow) | Navan Chauhan"/><meta name="description" content="Making predictions for image classification models built using TensorFlow"/><meta name="twitter:description" content="Making predictions for image classification models built using TensorFlow"/><meta name="og:description" content="Making predictions for image classification models built using TensorFlow"/><meta name="twitter:card" content="summary"/><link rel="stylesheet" href="/styles.css" type="text/css"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><link rel="shortcut icon" href="/images/favicon.png" type="image/png"/><link rel="alternate" href="/feed.rss" type="application/rss+xml" title="Subscribe to Navan Chauhan"/><meta name="twitter:image" content="https://navanchauhan.github.io/images/logo.png"/><meta name="og:image" content="https://navanchauhan.github.io/images/logo.png"/></head><body class="item-page"><header><div class="wrapper"><a class="site-name" href="/">Navan Chauhan</a><nav><ul><li><a class="selected" href="/posts">Posts</a></li><li><a href="/publications">Publications</a></li><li><a href="/about">About Me</a></li><li><a href="https://navanchauhan.github.io/repo">Repo</a></li></ul></nav></div></header><div class="wrapper"><article><div class="content"><span class="reading-time">🕑 1 minute read.</span><h1>Making Predictions using Image Classifier (TensorFlow)</h1><p><em>This was tested on TF 2.x and works as of 2019-12-10</em></p><p>If you want to understand how to make your own custom image classifier, please refer to my previous post.</p><p>If you followed my last post, then you created a model which took an image of dimensions 50x50 as an input.</p><p>First we import the following if we have not imported these before</p><pre><code>import cv2
+import os
+</code></pre><p>Then we read the file using OpenCV.</p><pre><code>image=cv2.imread(imagePath)
+</code></pre><p>The cv2. imread() function returns a NumPy array representing the image. Therefore, we need to convert it before we can use it.</p><pre><code>image_from_array = Image.fromarray(image, 'RGB')
+</code></pre><p>Then we resize the image</p><pre><code>size_image = image_from_array.resize((50,50))
+</code></pre><p>After this we create a batch consisting of only one image</p><pre><code>p = np.expand_dims(size_image, 0)
+</code></pre><p>We then convert this uint8 datatype to a float32 datatype</p><pre><code>img = tf.cast(p, tf.float32)
+</code></pre><p>Finally we make the prediction</p><pre><code>print(['Infected','Uninfected'][np.argmax(model.predict(img))])
+</code></pre><p><code>Infected</code></p></div><span>Tagged with: </span><ul class="tag-list"><li><a href="/tags/tutorial">tutorial</a></li><li><a href="/tags/tensorflow">tensorflow</a></li><li><a href="/tags/codesnippet">code-snippet</a></li></ul></article></div><footer><p>Made with ❤️ using <a href="https://github.com/johnsundell/publish">Publish</a></p><p><a href="/feed.rss">RSS feed</a></p></footer></body></html> \ No newline at end of file