<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kiturmark on Medium]]></title>
        <description><![CDATA[Stories by Kiturmark on Medium]]></description>
        <link>https://medium.com/@kiturmark?source=rss-72eaf9ecefe1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*FPdP58x9Thhj29fH</url>
            <title>Stories by Kiturmark on Medium</title>
            <link>https://medium.com/@kiturmark?source=rss-72eaf9ecefe1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 18:13:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kiturmark/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Object Detection Preprocessing: Scaling Smart, Padding Right]]></title>
            <link>https://medium.com/@kiturmark/object-detection-preprocessing-scaling-smart-padding-right-80acb845fe08?source=rss-72eaf9ecefe1------2</link>
            <guid isPermaLink="false">https://medium.com/p/80acb845fe08</guid>
            <dc:creator><![CDATA[Kiturmark]]></dc:creator>
            <pubDate>Sun, 22 Jun 2025 18:44:29 GMT</pubDate>
            <atom:updated>2025-06-22T18:44:29.054Z</atom:updated>
            <content:encoded><![CDATA[<p>Padding Images for Object Detection: Why It Matters and How to Do It Right</p><p><strong>Final result</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BizZoc1ZoisMKPP8f9K31Q.png" /><figcaption>final prediction</figcaption></figure><p>🔗 <a href="https://github.com/Mark-Kitur/fruits_bbox"><strong>Link to Full Code on GitHub</strong></a></p><p>In computer vision tasks like <strong>object detection</strong>, one of the biggest hurdles is dealing with images of varying sizes and aspect ratios. If you’ve ever trained a model with bounding box labels, you know that consistency in input dimensions is crucial. But simply resizing images can distort objects — and that’s where <strong>padding</strong> comes in.</p><p>In this blog, I’ll walk you through a simple and practical method to preprocess your dataset using <strong>aspect ratio–preserving padding</strong>, inspired by a fruit classification dataset.</p><h3>The Problem: Inconsistent Image Sizes</h3><p>Let’s say you’re working with a dataset of fruit images, each annotated with bounding boxes in an XML format. The dataset looks great, but the images come in all shapes and sizes:</p><ul><li>One image is 349×349</li><li>Another is 1500×1500</li><li>Yet another is 652×436</li></ul><p>You can’t feed these directly into a convolutional neural network (CNN). Most CNNs require fixed input dimensions (e.g., <strong>480×480</strong>). Resizing images to a fixed shape might stretch or squash the fruit — <strong>destroying the geometric accuracy of the bounding boxes</strong>.</p><p><strong>The Solution: Letterbox Padding</strong></p><p>Instead of stretching the image, we use <strong>letterbox padding</strong>, which works in two steps:</p><ol><li><strong>Scale the image</strong> so that the longer side fits within the target dimension (480 pixels).</li><li><strong>Pad the shorter side</strong> with equal margins on both ends to make the image square.</li></ol><p>This technique:</p><ul><li>Preserves the image’s aspect ratio</li><li>Prevents distortion</li><li>Makes it easier to train object detectors like YOLO, SSD, or Faster R-CNN</li></ul><h3>Implementation in Python (Pandas + XML Annotations)</h3><p>Let’s assume we’ve parsed the XML annotations into a Pandas DataFrame df, with each row containing:</p><ul><li>Image dimensions: width, height</li><li>Bounding box coordinates: xtl, ytl, xbr, ybr</li></ul><p>We set our target size to 480×480:</p><pre>const = 480  # final image height and width</pre><pre>pad_x = []<br>pad_y = []<br>scaling_ = []</pre><pre>for idx, row in df.iterrows():<br>    scaling_factor = min(const / row[&#39;width&#39;], const / row[&#39;height&#39;])<br>    scaling_.append(scaling_factor)</pre><pre>    scaled_width = row[&#39;width&#39;] * scaling_factor<br>    scaled_height = row[&#39;height&#39;] * scaling_factor</pre><pre>    pad_x.append((const - scaled_width) / 2)<br>    pad_y.append((const - scaled_height) / 2)</pre><pre>df[&#39;pad_x&#39;] = pad_x<br>df[&#39;pad_y&#39;] = pad_y<br>df[&#39;scaling&#39;] = scaling_</pre><p>Each image is scaled such that its longer dimension becomes 480 pixels, and the shorter one is padded <strong>evenly</strong> on both sides.</p><h3>Updating the Bounding Boxes</h3><p>After padding, we also need to <strong>update the bounding box coordinates</strong> so they match the transformed image space.</p><pre>for idx, row in df.iterrows():<br>    xtl_new = (row[&#39;xtl&#39;] * row[&#39;scaling&#39;]) + row[&#39;pad_x&#39;]<br>    ytl_new = (row[&#39;ytl&#39;] * row[&#39;scaling&#39;]) + row[&#39;pad_y&#39;]<br>    xbr_new = (row[&#39;xbr&#39;] * row[&#39;scaling&#39;]) + row[&#39;pad_x&#39;]<br>    ybr_new = (row[&#39;ybr&#39;] * row[&#39;scaling&#39;]) + row[&#39;pad_y&#39;]</pre><pre>    boxing = [<br>        round(xtl_new / const, 3),<br>        round(ytl_new / const, 3),<br>        round(xbr_new / const, 3),<br>        round(ybr_new / const, 3)<br>    ]<br>    boxes.append(boxing)</pre><pre>df[&#39;bbox&#39;] = boxes</pre><p>These new bounding boxes are also <strong>normalized</strong> to the [0, 1] range by dividing by the final image size (const = 480), which is ideal for most object detection models.</p><h3>Why This Padding Technique Works</h3><ul><li><strong>No distortion</strong> — your objects retain their true shape and structure.</li><li><strong>Uniform input size</strong> — every image is now a consistent 480×480.</li><li><strong>Accurate bounding boxes</strong> — which is essential for training reliable object detectors.</li></ul><h3>Conclusion</h3><p>Padding with aspect ratio preservation is a <strong>powerful preprocessing trick</strong> — subtle, but absolutely essential. It ensures your neural network sees consistent input sizes without sacrificing the geometric integrity of objects.</p><p>Whether you’re building a YOLO model, training a CNN from scratch, or prepping data for deployment, remember:</p><p>🔗 <a href="https://github.com/Mark-Kitur/fruits_bbox"><strong>View Full Code and Notebook on GitHub</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80acb845fe08" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Deep Learning for Object Localization with TensorFlow and Keras]]></title>
            <link>https://medium.com/@kiturmark/deep-learning-for-object-localization-with-tensorflow-and-keras-2d0aaf0e4a85?source=rss-72eaf9ecefe1------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d0aaf0e4a85</guid>
            <dc:creator><![CDATA[Kiturmark]]></dc:creator>
            <pubDate>Wed, 09 Apr 2025 19:48:00 GMT</pubDate>
            <atom:updated>2025-04-09T19:48:00.476Z</atom:updated>
            <content:encoded><![CDATA[<p>Real-Time Blood Cell Detection with Low Latency Inference</p><h3>🔍 Introduction</h3><p>In this project, I implemented a custom object detection model for <strong>blood cell classification and localization</strong> using TensorFlow and Keras. My goal was to build a lightweight, fast, and accurate model capable of classifying blood cell types and predicting their bounding boxes within an image — all without relying on heavyweight models like YOLO.</p><p>🔗 <strong>GitHub Repository:</strong><br> 👉 <a href="https://github.com/Mark-Kitur/blood_cells_classification_with_bounding_boxes">https://github.com/Mark-Kitur/blood_cells_classification_with_bounding_boxes</a></p><h3>⚙️ Why Not YOLO?</h3><p>While YOLO is powerful, it can be too large or slow for embedded systems or real-time edge devices. This project proves that with the right architecture and preprocessing, <strong>you can build an efficient and interpretable model from scratch</strong> — and even optimize it for different deployment sizes.</p><h3>🩸 Dataset</h3><p>I used a publicly available blood cell dataset formatted in <strong>COCO style</strong>, which includes:</p><ul><li>Image paths</li><li>Class labels (WBC, RBC, Platelets, etc.)</li><li>Bounding boxes: [x, y, width, height]</li></ul><p>All images were resized to <strong>416x416</strong> to maintain consistency.</p><h3>🧰 Model Architecture</h3><p>Built using <strong>Keras Functional API</strong>:</p><ul><li>Backbone: Custom Conv2D + MaxPooling layers</li><li>Dual Output:</li><li><strong>Classification</strong> (Softmax for multiple classes)</li><li><strong>Bounding Box Regression</strong> (4 values per object)</li></ul><p>from tensorflow.keras.layers import Conv2D, MaxPooling2D, Dense, Flatten, GlobalAveragePooling2D, Input<br>from tensorflow.keras.models import Model</p><p>inputs = Input(shape=(416, 416, 3))<br>x = Conv2D(32, 3, activation=’relu’)(inputs)<br>x = MaxPooling2D()(x)<br>x = Conv2D(64, 3, activation=’relu’)(x)<br>x = MaxPooling2D()(x)<br>x = Conv2D(128, 3, activation=’relu’)(x)<br>x = GlobalAveragePooling2D()(x)</p><p>class_output = Dense(3, activation=’softmax’, name=”class_output”)(x)<br>bbox_output = Dense(4, name=”bbox_output”)(x)</p><p>model = Model(inputs=inputs, outputs=[class_output, bbox_output])</p><h3>⚖️ Loss Functions &amp; Training</h3><p>The model uses a <strong>multi-task learning</strong> approach:</p><ul><li>SparseCategoricalCrossentropy for class output</li><li>Mean Squared Error (MSE) for bounding box output</li></ul><p>model.compile(<br> loss=[“sparse_categorical_crossentropy”, “mse”],<br> loss_weights=[0.8, 0.2],<br> optimizer=”adam”,<br> metrics=[“accuracy”]<br>)</p><h3>🧪 Results</h3><p>✅ <strong>Accuracy (Classification):</strong> 85.9%<br> 📦 <strong>Bounding Box MAE (Validation):</strong> 0.1527<br> ⚡ <strong>Inference Time:</strong> 2.33485 milliseconds</p><h3>📌 Key Takeaways</h3><ul><li>Bounding boxes should be <strong>normalized</strong> before training (i.e., divide by image width and height).</li><li>Multi-output models are a powerful alternative to pre-built detectors.</li><li>Properly scaled data and clean architecture can yield <strong>very low-latency models</strong>.</li><li>The project demonstrates that <strong>custom deep learning models can match YOLO for specific tasks with more flexibility</strong>.</li></ul><h3>📂 Next Steps</h3><ul><li>Quantize the model for edge devices.</li><li>Deploy on a microcontroller using TFLite.</li><li>Try data augmentation or hard negative mining to boost bbox accuracy.</li></ul><h3>🎉 Final Words</h3><p>This project was an amazing learning experience in building efficient, real-time object detection models without relying on bulky architectures. It’s a step forward toward lightweight AI solutions in <strong>medical imaging and embedded systems</strong>.</p><p>👉 Feel free to check out the full code and contribute:</p><p><a href="https://github.com/Mark-Kitur/blood_cells_classification_with_bounding_boxes">https://github.com/Mark-Kitur/blood_cells_classification_with_bounding_boxes</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d0aaf0e4a85" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>