So far we've used CNNs for a single task: looking at an image and assigning it a label. But classification is just the entry door. With the very same feature-extraction engine you already command — conv+pooling blocks building the edges→textures→parts→objects hierarchy — much richer tasks get solved: saying where each object is, cutting out its exact silhouette, reading text in a photo, or finding visually similar products. In this lesson we'll draw the complete map of computer vision tasks, each applied to a real TecnoMarket need, see what the pipeline of a production recognition system looks like, and ground it with two runnable examples: a Keras classifier making predictions on images, and a similarity search demo using embeddings and cosine similarity.
Contents
- The task map: from classifying to segmenting
- Object detection: YOLO and SSD from a bird's-eye view
- Segmentation: semantic and instance
- OCR: reading text in images
- Visual similarity search: embeddings
- The pipeline of a real system
- Example 1: classify and predict with Keras
- Example 2: cosine similarity between embeddings
The task map: from classifying to segmenting
Recognition tasks line up by the richness of their answer to the same photo:
| Task | Question it answers | Output | TecnoMarket case |
|---|---|---|---|
| Classification | What is in the image? | One label (+ probabilities) | Categorizing the photo a seller uploads: "coffee maker" |
| Classification + localization | What is there, and where? | Label + one rectangle (bounding box) | Checking the product is centered and fills the photo |
| Object detection | Which objects are there, and where is each one? | List of (label, box, confidence) | Finding every product in a catalog or shelf photo |
| Semantic segmentation | Which class does each pixel belong to? | A label map the size of the image | Separating product/background to remove the background automatically |
| Instance segmentation | Which pixels belong to each object? | One mask per object | Cutting out each of the 3 monitors in a batch photo |
Two clarifications about the table:
- Localization adds a regression to classification: besides the softmax probabilities, the network produces the rectangle's 4 numbers (x, y, width, height). Same convolutional extractor, one more output "head" — trained with a combined loss (the classification CCE from 02-04 plus an MSE over the coordinates).
- Detection generalizes to N objects, and that's where the difficulty lies: you don't know in advance how many there are.
Concrete TecnoMarket use cases, which we'll connect to each technique:
- Moderating seller photos (our flagship project): classifying the product's category and rejecting photos that don't belong (a blurry photo, a prohibited object, an image with no product).
- Detecting products in catalog images: a supplier sends a photo with 12 items on a table; the system localizes and crops each one.
- Visual "similar products" search: a customer photographs a lamp they saw at a friend's place and the app finds the most similar ones in the catalog.
- Label reading: extracting the serial number or model from the photo of an appliance's back label.
Object detection: YOLO and SSD from a bird's-eye view
How does a network find a variable number of objects? The naive idea — sliding a classifier over thousands of windows of every possible size — works but is painfully slow. The modern families solve it in a single pass:
- YOLO (You Only Look Once): divides the image into a grid (e.g. 13×13). Each cell predicts, in one go, a few candidate boxes with their confidence and their class. Since everything comes out of a single pass through the CNN, it's fast enough to process video in real time.
- SSD (Single Shot Detector): same single-pass philosophy, but it predicts boxes from several levels of the convolutional hierarchy: the large maps of the early layers (high resolution) detect small objects, and the small, deep maps detect large objects — a direct use of the hierarchy of features from 03-01.
Common pieces worth knowing by name:
- Confidence: each box carries a probability of "there's an object here"; boxes below a threshold are discarded.
- Non-maximum suppression (NMS): several cells tend to propose nearly identical boxes over the same object; NMS keeps the highest-confidence one and removes the overlapping ones.
For the supplier photo with 12 items, a detector returns something like [("monitor", box1, 0.97), ("keyboard", box2, 0.91), ...], and with those boxes the system automatically crops each product to register it in the catalog. Training a detector requires datasets annotated with boxes and specialized losses — that's beyond this course; what matters here is knowing what to ask of these tools and recognizing their pieces.
Segmentation: semantic and instance
When the rectangle isn't enough — removing the background of a product photo requires knowing exactly which pixels are product — we move to segmentation:
- Semantic: each pixel gets a class ("product", "background", "seller's hand"). Two coffee makers side by side form a single "coffee maker" blob.
- Instance: it additionally separates individual objects: coffee maker no. 1 and coffee maker no. 2 get different masks (it's the combination of detection + a mask per object).
The reference conceptual architecture for segmentation is the U-Net: it's U-shaped because the usual convolutional stage that shrinks the image while extracting features (the encoder, everything you learned in 03-02) is followed by a symmetric stage that expands it back to the original size (the decoder), producing a per-pixel prediction. The skip connections between symmetric levels of the U (close cousins of ResNet's, but concatenating instead of adding) reinject the fine detail of the early layers so the contours come out sharp.
flowchart LR
A["Image"] --> B["Encoder<br/>conv+pool<br/>(shrinks)"]
B --> C["Abstract<br/>features"]
C --> D["Decoder<br/>upsampling<br/>(expands)"]
D --> E["Per-pixel<br/>mask"]
B -.->|"skip connections<br/>(fine detail)"| D
Use at TecnoMarket: automatic background removal so all catalog photos have a uniform white background — semantic product/background segmentation and replacement of the background pixels.
OCR: reading text in images
OCR (Optical Character Recognition) converts images containing text into digital text. A modern system chains two stages, both powered by CNNs:
- Text detection: locating the regions of the image that contain text (a detection problem like the previous section's, with "text" as the class).
- Recognition: reading each region. A CNN extracts features from the image strip and a sequential component transcribes them character by character — text is a sequence, and to model sequences we'll use the recurrent networks of module 4; here we stay at the concept level.
At TecnoMarket, OCR automates label reading: the seller photographs the appliance's back label and the system extracts model, serial number, and energy class, filling in the product sheet without typing. In practice you rarely train your own OCR: existing engines are used (Tesseract, cloud services) except for very specific needs.
Visual similarity search: embeddings
The most elegant application of the feature extractor: using the CNN without the classification layer. Recall the anatomy from 03-01: after the convolutional stage (and the global average pooling from 03-03), the image ends up summarized in a vector of, say, 128 numbers that condense its visual features. That vector is called an embedding.
The key property: visually similar images produce nearby embeddings. Two lamps of similar design land at close points in that 128-dimensional space even though their pixels differ in everything (background, angle, lighting); a lamp and an air fryer land far apart.
How "near" is measured: with cosine similarity, the cosine of the angle between the two vectors:
It equals 1 if they point in the same direction (very similar), 0 if they're perpendicular (nothing in common), and −1 if they're opposite. It's preferred over Euclidean distance because it ignores the vector's magnitude (how much the image activates overall) and compares only the pattern of features.
TecnoMarket's "similar products" system ends up like this:
- Indexing (once): run every catalog photo through the CNN and store its embedding in a database.
- Query (live): the customer uploads their photo → embedding → cosine similarity against the index → return the K nearest products.
This pattern (encoding anything as a vector and searching by proximity) is universal today: you'll meet it again with text in module 4 and with the autoencoders of 05-02.
The pipeline of a real system
None of these networks works alone. TecnoMarket's photo moderation system, from the seller's upload to the published product sheet, chains:
flowchart LR
A["Seller's photo<br/>(3000x2000, JPG)"] --> B["Preprocessing<br/>resize to 224x224<br/>normalize values"]
B --> C["CNN inference<br/>classification"]
C --> D{"Confidence<br/>> threshold?"}
D -->|"yes"| E["Auto-label<br/>and publish"]
D -->|"no"| F["Human review<br/>queue"]
- Preprocessing: photos arrive in arbitrary sizes and formats; they are resized to the network's input size and the pixels are normalized (for example from [0, 255] to [0, 1], as we did with MNIST in 02-05). Iron rule: the inference image must be preprocessed exactly like the training ones.
- Training is separate: during training (not inference), data augmentation is additionally applied — rotating, cropping, changing brightness — to multiply variety; it's a regularization technique and we'll develop it in 05-04.
- Inference: one forward pass (02-03) of the already-trained model. No backprop, no gradients: milliseconds per image.
- Threshold-based decision: a production system never blindly trusts the softmax. If the maximum probability doesn't clear a threshold (e.g. 0.85), the photo goes to human review. The threshold balances automating a lot against making few mistakes.
Example 1: classify and predict with Keras
The course's methodology: prototype on a public dataset before touching TecnoMarket's data. We use CIFAR-10 (60,000 32×32 color photos, 10 classes: airplane, automobile, bird...), which stands in for our product photos. We train a small CNN briefly and focus on the new part: predicting on images and reading the predictions. (The full guided project, with more training, fine-grained evaluation, and iterative improvement, is the one in lesson 07-01.)
import numpy as np
from tensorflow import keras
from tensorflow.keras import layers
# 1) Data: CIFAR-10, normalized to [0, 1] as in 02-05
(x_train, y_train), (x_test, y_test) = keras.datasets.cifar10.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
class_names = ["airplane", "automobile", "bird", "cat", "deer",
"dog", "frog", "horse", "ship", "truck"]
# 2) A compact CNN with the mini-VGG pattern from 03-03
model = keras.Sequential([
keras.Input(shape=(32, 32, 3)),
layers.Conv2D(32, (3, 3), padding="same", activation="relu"),
layers.MaxPooling2D((2, 2)),
layers.Conv2D(64, (3, 3), padding="same", activation="relu"),
layers.MaxPooling2D((2, 2)),
layers.GlobalAveragePooling2D(),
layers.Dense(10, activation="softmax"),
])
model.compile(optimizer="adam", # Adam, as in 02-04
loss="sparse_categorical_crossentropy",
metrics=["accuracy"])
# 3) Short training run (enough for the example)
model.fit(x_train, y_train, epochs=5, batch_size=64,
validation_split=0.1, verbose=2)
# 4) The new part: predicting on images and reading the output
probabilities = model.predict(x_test[:4]) # 4 images -> 4x10 matrix
for i, probs in enumerate(probabilities):
top = np.argsort(probs)[::-1][:3] # indices of the 3 most likely classes
actual = class_names[int(y_test[i])]
print(f"Image {i} (actual: {actual})")
for k in top:
print(f" {class_names[k]:10s} {probs[k]:6.1%}")Typical output (it will vary with the random initialization):
Image 0 (actual: cat) cat 54.2% dog 21.7% deer 8.3% Image 1 (actual: ship) ship 88.9% airplane 6.1% truck 2.4% ...
How to read it with production-system eyes:
model.predictreturns the full softmax distribution (10 probabilities per image), not a label. The label is our decision:np.argmax(probs).- The "ship" at 88.9% would clear a 0.85 threshold and get auto-labeled; the "cat" at 54.2% would go to human review. Showing the top-3 helps the reviewer: if the first two options are "cat" and "dog", the doubt is reasonable; if they are "cat" and "truck", something odd is going on with the photo.
- For a new TecnoMarket photo the flow would be identical: load the JPG, resize to 32×32 (or the model's input size), normalize by dividing by 255, add the batch dimension (
np.expand_dims(img, 0)), and callpredict.
Example 2: cosine similarity between embeddings
Now the visual search. Teaching trick: instead of training a specialized embedding network, we reuse the previous CNN cut off before the softmax layer — the output of the GlobalAveragePooling2D (64 numbers) is our embedding.
# 1) Embedding model: the same network, without the classification layer
extractor = keras.Model(
inputs=model.inputs,
outputs=model.layers[-2].output # output of the GlobalAveragePooling2D (64 values)
)
# 2) "Catalog": embeddings of 1000 test images
catalog = extractor.predict(x_test[:1000]) # 1000x64 matrix
def cosine_similarity(a, b):
return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))
# 3) Query: the "customer" uploads image 1500 (outside the catalog)
query = extractor.predict(x_test[1500:1501])[0] # vector of 64
similarities = np.array([cosine_similarity(query, e) for e in catalog])
top5 = np.argsort(similarities)[::-1][:5] # the 5 most similar
print(f"Query: {class_names[int(y_test[1500])]}")
for idx in top5:
print(f" match: {class_names[int(y_test[idx])]:10s} "
f"similarity = {similarities[idx]:.3f}")Typical output:
Query: horse match: horse similarity = 0.983 match: horse similarity = 0.971 match: deer similarity = 0.968 match: horse similarity = 0.962 match: dog similarity = 0.955
Observations:
keras.Model(inputs=..., outputs=intermediate_layer.output)creates a "view" of the network that ends wherever we say: this is how embeddings are extracted (and how intermediate feature maps are visualized, as we noted in 03-02).- The nearest neighbors share the class or are visually related classes (horse/deer): the embedding space organizes images by visual resemblance, not by pixels. And nobody trained the network "to search": it's a side effect of learning to classify.
- TecnoMarket's real system would follow this scheme with two upgrades: a much more powerful extractor (a pretrained network — transfer learning, 05-03) and a vector database to search among millions of embeddings without scanning them one by one.
Common Mistakes and Tips
- Choosing a more expensive task than necessary. If knowing what product it is suffices, don't set up detection; if the box suffices, don't set up segmentation. Each jump in output richness multiplies the cost of annotating data and computing. Start with the minimal task that solves the problem.
- Preprocessing differently in training and inference. If you trained with pixels in [0, 1] and production feeds in [0, 255], the model will see garbage and fail without raising an error. Encapsulate the preprocessing in a single function used in both places.
- Treating the softmax as certainty. A 99% softmax is no guarantee; faced with a truly bizarre image (a product that didn't exist at training time) the network will spread probabilities across what it knows. Hence the thresholds and the human review queue.
- Forgetting the batch dimension when predicting a single image.
predictexpects shape(N, height, width, channels); with a lone image of shape(32, 32, 3)it will fail. Solution:np.expand_dims(image, axis=0). - Comparing embeddings with Euclidean distance without normalizing. Two images with the same feature pattern but different activation "intensity" would end up far apart in Euclidean terms; cosine similarity (or normalizing the vectors first) compares directions and is the standard practice.
Exercises
Exercise 1: choosing the task
For each TecnoMarket need, name the appropriate vision task (classification, localization, detection, semantic segmentation, instance segmentation, OCR, or embedding search) and justify it in one sentence:
- Automatically rejecting photos where the product occupies less than 20% of the image.
- Generating the uniform white background for all catalog photos.
- Counting how many units appear in the photo of a batch of identical headphones and cropping each one.
- Suggesting "other customers viewed these similar products" from the product sheet's photo.
- Verifying that the serial number in the photo matches the one declared in the form.
Exercise 2: cosine similarity by hand
Three products have these simplified 3-dimensional embeddings: lamp A = (0.9, 0.1, 0.2), lamp B = (0.8, 0.2, 0.1), air fryer = (0.1, 0.9, 0.8). Compute the cosine similarity between lamp A and lamp B, and between lamp A and the air fryer. Do the numbers confirm the intuition?
Exercise 3: designing the threshold
TecnoMarket's photo classifier automates publication if the maximum probability exceeds the threshold T. With T = 0.5 it automates 95% of photos with 8% errors; with T = 0.9 it automates 60% with 1% errors. Which threshold would you choose if (a) category errors are cheap to fix afterwards, (b) a misclassified photo could publish a product into a category with legal requirements (e.g. gas appliances)? What third, middle-ground option does the pipeline from this lesson offer?
Solutions
Exercise 1:
- Classification + localization: a box around the product is enough to compute what fraction of the image it occupies.
- Semantic segmentation: you have to decide pixel by pixel what is product and what is background in order to replace the background.
- Instance segmentation (or detection, if the box is enough for cropping): the headphones are identical and must be separated unit by unit.
- Embedding search: it is exactly the case of visual similarity between catalog and query.
- OCR: locate and read the serial number's text to compare it against the form.
Exercise 2:
- A · B = 0.9·0.8 + 0.1·0.2 + 0.2·0.1 = 0.76. ‖A‖ = √(0.81+0.01+0.04) = √0.86 ≈ 0.927. ‖B‖ = √(0.64+0.04+0.01) = √0.69 ≈ 0.831. Similarity = 0.76 / (0.927 × 0.831) ≈ 0.987.
- A · F = 0.9·0.1 + 0.1·0.9 + 0.2·0.8 = 0.34. ‖F‖ = √(0.01+0.81+0.64) = √1.46 ≈ 1.208. Similarity = 0.34 / (0.927 × 1.208) ≈ 0.304.
- Yes: the two lamps are almost collinear (0.987, practically identical to the system) and the air fryer sits far away (0.304).
Exercise 3:
- (a) With cheap errors, T = 0.5: automating 95% saves an enormous amount of human work, and the 8% of errors gets fixed later at little cost.
- (b) With legal risk, T = 0.9 (or higher): 1% of errors may still be too much for that particular category; you could even force human review whenever the predicted class is a regulated category, regardless of confidence.
- The third option is the pipeline's: threshold + human review queue — photos below the threshold aren't rejected, they get reviewed. It can be tuned per category: a low threshold for phone cases, a very high one (or mandatory review) for sensitive categories.
Conclusion
This module started with a limitation (dense networks don't scale to images) and ends with a complete panorama of what CNNs make possible. In this lesson you've placed every task in its slot — classifying, localizing, detecting (YOLO/SSD in a single pass), segmenting (U-Net with its encoder-decoder), reading text, and searching by similarity — and mapped them to TecnoMarket's operations: photo moderation, automatic catalog registration, uniform white backgrounds, label reading, and "similar products". You've seen that a real system is a pipeline (identical preprocessing in training and inference, confidence thresholds, human review), you've made real predictions with Keras on CIFAR-10 reading the softmax with a production mindset, and you've built a similarity search engine by reusing your classifier as an embedding extractor — the definitive demonstration that the convolutional stage is a general-purpose feature extractor.
With this we close the CNN module: you know why they exist (03-01), how their layers are configured (03-02), which architectures paved the way (03-03), and everything that gets built with them (03-04). The full guided project on classifying product photos awaits you in 07-01, and the reuse of pretrained networks in 05-03. But first, a change of gears: CNNs dominate data with spatial structure; module 4 tackles data with temporal or sequential structure — the reviews TecnoMarket customers write, their purchase histories, week-by-week demand. For that we need networks with memory: recurrent neural networks (RNNs).
Deep Learning Course
Module 1: Introduction to Deep Learning
- What is Deep Learning?
- History and evolution of Deep Learning
- Applications of Deep Learning
- Basic concepts of neural networks
- Setting up the work environment
Module 2: Neural Network Fundamentals
- Perceptron and Multilayer Perceptron
- Activation functions
- Forward and backward propagation
- Optimization and loss functions
- Your first complete neural network
Module 3: Convolutional Neural Networks (CNN)
- Introduction to CNNs
- Convolutional and pooling layers
- Popular CNN architectures
- CNN applications in image recognition
Module 4: Recurrent Neural Networks (RNN)
- Introduction to RNNs
- LSTM and GRU
- RNN applications in natural language processing
- Sequences and time series
Module 5: Advanced Deep Learning Techniques
- Generative Adversarial Networks (GAN)
- Autoencoders
- Transfer Learning
- Regularization and improvement techniques
- Attention mechanisms and Transformers
Module 6: Tools and Frameworks
- Introduction to TensorFlow
- Introduction to PyTorch
- Framework comparison
- Development environments and additional resources
- Saving, loading and deploying models
Module 7: Hands-On Projects
- Image classification with CNNs
- Text generation with RNNs
- Anomaly detection with Autoencoders
- Building a GAN for image generation
- Fine-tuning a pretrained model
