Skip to content

Commit 0131de6

Browse files
Image Classifivation with TensorFLow/Keras (#501)
* images for webscraping blog Images that are use in Web Scraping blog. * Banner Image for WebScraping This is the banner image that you asked for to use on the blog. So here, I changed it for Web Scraping Introduction Blog. * image for chatbot content * flowchart image to build a chatbot with NLTK * Images of ChatBot with NLTK article * Image Classification with TensorFLow/Keras. * Image_Classification article's image * Image for ImageClassificationwithTensorFLow/Keras.
1 parent 2c39277 commit 0131de6

File tree

2 files changed

+307
-0
lines changed

2 files changed

+307
-0
lines changed
Lines changed: 307 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,307 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta
6+
name="viewport"
7+
content="width=device-width, initial-scale=1, shrink-to-fit=no" />
8+
<meta
9+
name="description"
10+
content="A deep learning model to classify images using TensorFlow and Keras. Use a pre-trained model or build your own convolutional neural network (CNN)." />
11+
<meta
12+
name="keywords"
13+
content="Image Classification, TensorFlow, Keras, Deep Learning, Convolutional Neural Networks (CNN), Data Augmentation, Transfer Learning, Model Evaluation, Pre-trained Models, On-device Machine Learning" />
14+
<title>
15+
Image Classification with TensorFlow/Keras
16+
</title>
17+
<meta name="vaishali-sharma" content="CSEdge" />
18+
<!-- Favicon-->
19+
<link
20+
rel="icon"
21+
type="image/x-icon"
22+
href="https://csedge.courses/Images/CSEDGE-LOGO32X32.png" />
23+
<!-- Core theme CSS (includes Bootstrap)-->
24+
<link href="../styles.css" rel="stylesheet" />
25+
</head>
26+
<body>
27+
28+
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
29+
<div class="container">
30+
<img
31+
height="32px"
32+
width="32px"
33+
src="https://csedge.courses/Images/CSEDGE-LOGO32X32.png"
34+
alt="logo" />
35+
<a class="navbar-brand" href="../.././index.html">CSEdge Learn</a>
36+
<button
37+
class="navbar-toggler"
38+
type="button"
39+
data-bs-toggle="collapse"
40+
data-bs-target="#navbarSupportedContent"
41+
aria-controls="navbarSupportedContent"
42+
aria-expanded="false"
43+
aria-label="Toggle navigation">
44+
<span class="navbar-toggler-icon"></span>
45+
</button>
46+
<div class="collapse navbar-collapse" id="navbarSupportedContent">
47+
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
48+
<li class="nav-item">
49+
<a class="nav-link" href="https://learn.csedge.courses">Home</a>
50+
</li>
51+
<li class="nav-item">
52+
<a class="nav-link" href="https://csedge.courses/about">About</a>
53+
</li>
54+
<li class="nav-item">
55+
<a class="nav-link" href="https://csedge.courses#contact"
56+
>Contact</a
57+
>
58+
</li>
59+
<li class="nav-item">
60+
<a
61+
class="nav-link active"
62+
aria-current="page"
63+
href="https://learn.csedge.courses">Blog</a>
64+
</li>
65+
</ul>
66+
</div>
67+
</div>
68+
</nav>
69+
<div class="container mb-4 mt-4">
70+
<div class="row">
71+
<!-- Blog entries-->
72+
<div class="col-lg-8">
73+
<h1>
74+
Image Classification with TensorFlow/Keras
75+
</h1>
76+
<!-- Featured blog post-->
77+
<div class="card mb-4">
78+
<img
79+
class="card-img-top"
80+
src="../images/Image_Classification.png"
81+
alt="Image Classification with TensorFlow" />
82+
<div class="card-body">
83+
<main class="container">
84+
<section>
85+
<p>Image classification is a fundamental task in computer vision, where the goal is to assign a label (class) to an input image. In this tutorial, we’ll explore how to build an image classification model using TensorFlow and Keras. You can either use a pre-trained model or create your own custom convolutional neural network (CNN).</p>
86+
<br>
87+
<h2>Pre-requisites</h2>
88+
<p>Before we dive into the implementation, make sure you have the following installed:</p>
89+
<ul>
90+
<li>Python (preferably Python 3.6 or later)</li>
91+
<li>TensorFlow (install using pip install tensorflow)</li>
92+
<li>Keras (included with TensorFlow)</li>
93+
</ul>
94+
<h2>Workflow Overview</h2>
95+
<ol>
96+
<h6><li>Data Preparation</li></h6>
97+
<ul>
98+
<li>Collect a labeled dataset of images. For example, you can use the <a href="https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz">Flower Photos dataset</a>.</li>
99+
<li>Organize the data into subdirectories, each representing a different class (e.g., roses, tulips, dandelions).</li>
100+
</ul>
101+
<h6><li>Load and Preprocess Data:</li></h6>
102+
<ul>
103+
<li>Use <code>tf.keras.utils.image_dataset_from_directory</code> to efficiently load images from disk.</li>
104+
<li>Resize images to a consistent size (e.g., 180x180 pixels).</li>
105+
<li>Normalize pixel values to the range [0, 1].</li>
106+
</ul>
107+
<h6><li>Model Building:</li></h6>
108+
<ul>
109+
<li>Choose between using a pre-trained model (transfer learning) or building your own CNN from scratch.</li>
110+
<li>For transfer learning, load a pre-trained model (e.g., MobileNetV2, ResNet50) and fine-tune it for your specific task.</li>
111+
<li>For custom CNN, design your architecture with convolutional layers, pooling layers, and fully connected layers.</li>
112+
</ul>
113+
<h6><li>Compile and Train the Model:</li></h6>
114+
<ul>
115+
<li>Compile the model with an appropriate optimizer, loss function, and evaluation metric.</li>
116+
<li>Train the model on your labeled dataset.</li>
117+
<li>Monitor training progress and adjust hyperparameters as needed.</li>
118+
</ul>
119+
<h6><li>Evaluate and Improve:</li></h6>
120+
<ul>
121+
<li>Evaluate the model’s performance on a validation set.</li>
122+
<li>Address overfitting by using techniques like data augmentation and dropout.</li>
123+
<li>Fine-tune the model based on evaluation results.</li>
124+
</ul>
125+
<h6><li>Prediction and Deployment:</li></h6>
126+
<ul>
127+
<li>Use the trained model to predict labels for new images.</li>
128+
<li>Convert the model to TensorFlow Lite format for deployment on mobile devices or embedded systems.</li>
129+
</ul>
130+
</ol>
131+
<h2>Example Code</h2>
132+
<p>Below is a simplified example of building an image classification model using a custom CNN:</p>
133+
<strong>Python:</strong><br>
134+
<pre>
135+
<code>
136+
import tensorflow as tf
137+
from tensorflow.keras import layers
138+
139+
# Load and preprocess data
140+
data_dir = "/path/to/flower_photos"
141+
batch_size = 32
142+
img_height, img_width = 180, 180
143+
144+
train_ds = tf.keras.utils.image_dataset_from_directory(
145+
data_dir,
146+
validation_split=0.2,
147+
subset="training",
148+
seed=42,
149+
image_size=(img_height, img_width),
150+
batch_size=batch_size,
151+
)
152+
153+
# Build a simple CNN
154+
model = tf.keras.Sequential([
155+
layers.Conv2D(32, (3, 3), activation="relu", input_shape=(img_height, img_width, 3)),
156+
layers.MaxPooling2D(),
157+
layers.Flatten(),
158+
layers.Dense(128, activation="relu"),
159+
layers.Dense(num_classes, activation="softmax"), # num_classes = number of flower classes
160+
])
161+
162+
# Compile the model
163+
model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"])
164+
165+
# Train the model
166+
model.fit(train_ds, epochs=10)
167+
168+
# Evaluate the model (on validation set)
169+
validation_ds = tf.keras.utils.image_dataset_from_directory(
170+
data_dir,
171+
validation_split=0.2,
172+
subset="validation",
173+
seed=42,
174+
image_size=(img_height, img_width),
175+
batch_size=batch_size,
176+
)
177+
model.evaluate(validation_ds)
178+
179+
</code>
180+
</pre>
181+
182+
<p>Remember to replace <code>/path/to/flower_photos</code> with the actual path to your dataset directory.</p>
183+
<h2>Conclusion</h2>
184+
<p>Image classification with TensorFlow and Keras is a powerful technique that can be applied to various domains, from recognizing objects in photos to medical diagnosis. Experiment with different architectures, hyperparameters, and datasets to improve your model’s accuracy!</p>
185+
</section>
186+
</main>
187+
</div>
188+
</div>
189+
</div>
190+
<!-- Side widgets-->
191+
<div class="col-lg-4">
192+
<!-- Search widget-->
193+
<div class="card mb-4">
194+
<div class="card-header">Search</div>
195+
<div class="card-body">
196+
<div class="input-group">
197+
<input
198+
class="form-control"
199+
type="text"
200+
id="searchInput"
201+
placeholder="Enter search term..."
202+
aria-label="Enter search term..."
203+
aria-describedby="button-search" />
204+
<button
205+
class="btn btn-primary"
206+
id="button-search"
207+
type="button"
208+
onclick="search()">
209+
Go!
210+
</button>
211+
</div>
212+
</div>
213+
<!-- Search Results -->
214+
<div id="searchResults"></div>
215+
</div>
216+
<!-- Categories widget-->
217+
<div class="card mb-4">
218+
<div class="card-header">Categories</div>
219+
<div class="card-body">
220+
<div class="row">
221+
<div class="col-sm-6">
222+
<ul class="list-unstyled mb-0">
223+
<li><a href="#!">Web Design</a></li>
224+
<li><a href="#!">HTML</a></li>
225+
<li><a href="#!">Freebies</a></li>
226+
</ul>
227+
</div>
228+
<div class="col-sm-6">
229+
<ul class="list-unstyled mb-0">
230+
<li><a href="#!">JavaScript</a></li>
231+
<li><a href="#!">CSS</a></li>
232+
<li><a href="#!">Tutorials</a></li>
233+
</ul>
234+
</div>
235+
</div>
236+
</div>
237+
</div>
238+
<!-- Side widget-->
239+
<div class="card mb-4">
240+
<div class="card-header">Recent Posts</div>
241+
<div class="card-body">
242+
<p>Coming Soon..!</p>
243+
</div>
244+
</div>
245+
<div class="card mb-4">
246+
<div class="card-body">
247+
<script
248+
async
249+
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8930077947690409"
250+
crossorigin="anonymous"></script>
251+
<ins
252+
class="adsbygoogle"
253+
style="display: block"
254+
data-ad-format="fluid"
255+
data-ad-layout-key="-fb+5w+4e-db+86"
256+
data-ad-client="ca-pub-8930077947690409"
257+
data-ad-slot="9866674087"></ins>
258+
<script>
259+
(adsbygoogle = window.adsbygoogle || []).push({});
260+
</script>
261+
<script
262+
async
263+
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8930077947690409"
264+
crossorigin="anonymous"></script>
265+
<ins
266+
class="adsbygoogle"
267+
style="display: block"
268+
data-ad-format="fluid"
269+
data-ad-layout-key="-fb+5w+4e-db+86"
270+
data-ad-client="ca-pub-8930077947690409"
271+
data-ad-slot="9866674087"></ins>
272+
<script>
273+
(adsbygoogle = window.adsbygoogle || []).push({});
274+
</script>
275+
<script
276+
async
277+
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8930077947690409"
278+
crossorigin="anonymous"></script>
279+
<ins
280+
class="adsbygoogle"
281+
style="display: block"
282+
data-ad-format="fluid"
283+
data-ad-layout-key="-fb+5w+4e-db+86"
284+
data-ad-client="ca-pub-8930077947690409"
285+
data-ad-slot="9866674087"></ins>
286+
<script>
287+
(adsbygoogle = window.adsbygoogle || []).push({});
288+
</script>
289+
</div>
290+
</div>
291+
</div>
292+
</div>
293+
</div>
294+
<!-- Footer-->
295+
<footer class="py-5 bg-dark">
296+
<div class="container">
297+
<p class="m-0 text-center text-white">
298+
Copyright &copy CSEdge Learn 2024
299+
</p>
300+
</div>
301+
</footer>
302+
<!-- Bootstrap core JS-->
303+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
304+
<!-- Core theme JS-->
305+
<script src="../script.js"></script>
306+
</body>
307+
</html>

posts/images/Image_Classification.png

273 KB
Loading

0 commit comments

Comments
 (0)