<?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 Rick on Medium]]></title>
        <description><![CDATA[Stories by Rick on Medium]]></description>
        <link>https://medium.com/@riccmezz?source=rss-4d0064503450------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*72PG04XEOXpIMrWCzWgVIg.png</url>
            <title>Stories by Rick on Medium</title>
            <link>https://medium.com/@riccmezz?source=rss-4d0064503450------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 05:37:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@riccmezz/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[My Current Work]]></title>
            <link>https://riccmezz.medium.com/my-current-work-8a0346990899?source=rss-4d0064503450------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a0346990899</guid>
            <category><![CDATA[point-cloud]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Rick]]></dc:creator>
            <pubDate>Wed, 14 May 2025 13:31:01 GMT</pubDate>
            <atom:updated>2025-05-14T13:31:01.907Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve done a lot</p><p>I’ve been really busy for the past couple of years, and have neglected to keep updating this blog about the improvements on my thesis work.</p><p>So here’s a quick update</p><p>First step was to replicate the functionality of this paper. A Wearable Device for Indoor Imminent Danger Detection and Avoidance With Region-Based Ground Segmentation, you search in previous blogs or search the paper if you want an in depth explanation.</p><p>Today the paper is replicated at 95% i’d say, with the only problem that I can’t make the code work in real time. I’m still working with a pre-recorded .bag file to process the information and make all of the calculations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/0*-oXpWzUUdSy_kA0R" /></figure><p>However after a couple of hours of research i found out, from al old GitHub <a href="https://github.com/IntelRealSense/librealsense/issues/12476">forum </a>that in order to be able to receive IMU data from the sensor i needed an Ubuntu 20.04.1 OS installed on my raspberry, which, if i had done from the beginning, we wouldn’t be in this mess, in any case i have to move on, i can say that i was fortunate enough to find this <a href="https://ramith.fyi/setting-up-raspberry-pi-4-with-ubuntu-20-04-ros-intel-realsense/">article </a>explaining easily how to install all the necessary tool to work with the librealsense for raspberry pi.</p><p>Now one might think that I’d be better off using a Jetson nano or something else, and to be honest you might be right, however, I’d like the solution to be as accessible and as simple as I can keep it. I’ll try to hunt down a paper that opened my perspective on this idea about Moore’s law. We know that the amount of transistors per unit area grows exponentially with time, unlike our designs, models and architectures. While it is very helpful to have powerful computers, being able to make efficient designs we can make the most out of these computers. In a way these power hungry processors can become crutches, and we find ourselves sacrificing efficiency for the sake of functionality. It’s true some issues may naturally need complex solutions and powerful computers, but nevertheless we should try and do our best to design solutions that are simple yet effective. Work with what you have to force yourself to be creative with your solutions.</p><p>As a final note, I’d like to announce that I have an intention to start making educational videos about this and several other topics, I don’t have any platforms set up but please consider following me here so i can get more motivated to share my findings with you. Thank you for your attention :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a0346990899" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Step 3: Object detection]]></title>
            <link>https://riccmezz.medium.com/step-3-object-detection-de999cabc14a?source=rss-4d0064503450------2</link>
            <guid isPermaLink="false">https://medium.com/p/de999cabc14a</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[electrical-engineering]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[digital-image-processing]]></category>
            <dc:creator><![CDATA[Rick]]></dc:creator>
            <pubDate>Wed, 01 May 2024 03:01:34 GMT</pubDate>
            <atom:updated>2024-05-01T03:01:34.640Z</atom:updated>
            <content:encoded><![CDATA[<p>using Mobile-Net V2</p><p>The next step on trying to replicate some of the work presented by Li. M, et al. 2020 [1]. Is to implement object detection with Mobile-Net V2.</p><h4>Options on how to use the model</h4><p>There are a few open source options to use this model. The authors of [1], don’t make a definitive statement on which programing language tjeir using. However, they do mention the libraries for 3D plotting and rendering, as well as the audio manipulation (which is not my focus) and some other libraries.</p><p><a href="https://pcl.readthedocs.io/projects/tutorials/en/master/index.html"><strong>Point Cloud Library</strong></a><strong> to handle the 3D functions and views.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*-83qxHGU0MqodHeK" /></figure><p><a href="https://www.openmp.org/specifications/"><strong>Open Multi-Processing (OpenMP)</strong></a><strong> to manage multithread processing</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/0*cvpFE4ejaifxcUlA.png" /></figure><p><a href="https://github.com/suzhenghang/MobileNetv2?tab=readme-ov-file"><strong>Also there are C++ implementations of the model</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cuOHbUfFXhnRaM1tPMMnxw.png" /></figure><p>Since this paper focuses on a wearable embedded system as their solution it makes sense that they use C/C++, I consulted this with my advisor, and since the focus of my research is to present a new AI model or more accurately a new framework for fall prevention and detection, I will continue to work with implementations in Python using PyTorch. That being said, I still would like in the future to mess around with RUST, as it’s been shown to be a very fast language. And I hope an even invite you, the reader, to bully me and hold me accountable to actually do this. For now, let’s continue with python implementations.</p><h4>Media Pipe</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*5YwmLk8tcpZ6qgDo" /></figure><p>To avoid any delays or any additional work, I first want to compare if there’s any prebuilt comparable implementations. I tried out some of the code done by Google’s MediaPipe solutions. Here’s some testing code</p><p>First I read 4 sample images</p><pre>import imageio.v3 as iio<br>from PIL import Image<br>import matplotlib<br>import matplotlib.pyplot as plt<br>import numpy as np<br><br>d1 = iio.imread(&#39;./fall-01-cam0-rgb-001.png&#39;)<br>d2 = iio.imread(&#39;./fall-01-cam0-rgb-002.png&#39;)<br>d3 = iio.imread(&#39;./fall-01-cam0-rgb-003.png&#39;)<br>d4 = iio.imread(&#39;./fall-01-cam0-rgb-004.png&#39;)<br><br>raw_images = [d1, d2, d3, d4]<br><br>fig = plt.figure(figsize= (4, 4))<br>temp = 0<br><br>for i in range (0, 4):<br>  ax = fig.add_subplot(2, 2, temp+1)<br>  temp +=1<br>  ax.imshow(raw_images[i])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*UWucAgEZKy--gnW_XDpEGg.png" /></figure><p>Then we use the function to make annotations from the detections, this is from the guide of MediaPipe</p><pre>import cv2<br>MARGIN = 10  # pixels<br>ROW_SIZE = 10  # pixels<br>FONT_SIZE = 1<br>FONT_THICKNESS = 1<br>TEXT_COLOR = (255, 0, 0)  # red<br><br>def visualize(<br>    image,<br>    detection_result<br>) -&gt; np.ndarray:<br>  &quot;&quot;&quot;Draws bounding boxes on the input image and return it.<br>  Args:<br>    image: The input RGB image.<br>    detection_result: The list of all &quot;Detection&quot; entities to be visualize.<br>  Returns:<br>    Image with bounding boxes.<br>  &quot;&quot;&quot;<br>  for detection in detection_result.detections:<br>    # Draw bounding_box<br>    bbox = detection.bounding_box<br>    start_point = bbox.origin_x, bbox.origin_y<br>    end_point = bbox.origin_x + bbox.width, bbox.origin_y + bbox.height<br>    cv2.rectangle(image, start_point, end_point, TEXT_COLOR, 3)<br><br>    # Draw label and score<br>    category = detection.categories[0]<br>    category_name = category.category_name<br>    probability = round(category.score, 2)<br>    result_text = category_name + &#39; (&#39; + str(probability) + &#39;)&#39;<br>    text_location = (MARGIN + bbox.origin_x,<br>                     MARGIN + ROW_SIZE + bbox.origin_y)<br>    cv2.putText(image, result_text, text_location, cv2.FONT_HERSHEY_PLAIN,<br>                FONT_SIZE, TEXT_COLOR, FONT_THICKNESS)<br><br>  return image</pre><p>Now we run the code for every one of the sample images</p><pre># STEP 1: Import the necessary modules.<br>import numpy as np<br>import mediapipe as mp<br>from mediapipe.tasks import python<br>from mediapipe.tasks.python import vision<br><br># STEP 2: Create an ObjectDetector object.<br>base_options = python.BaseOptions(model_asset_path=&#39;ssd_mobilenet_v2_32f.tflite&#39;)<br>options = vision.ObjectDetectorOptions(base_options=base_options,<br>                                       score_threshold=0.48)<br>detector = vision.ObjectDetector.create_from_options(options)<br><br>i = 1<br>annoted_images = []<br>for image in raw_images:<br>    IMAGE_FILE = f&#39;fall-01-cam0-rgb-00{i}.png&#39;<br>    # STEP 3: Load the input image.<br>    image = mp.Image.create_from_file(IMAGE_FILE)<br>    # STEP 4: Detect objects in the input image.<br>    detection_result = detector.detect(image)<br>    # STEP 5: Process the detection result. In this case, visualize it.<br>    image_copy = np.copy(image.numpy_view())<br>    annotated_image = visualize(image_copy, detection_result)<br>    annoted_images.append(annotated_image)<br>    i += 1 <br><br><br>fig = plt.figure(figsize= (4, 4))<br>temp = 0<br><br>for i in range (0, 4):<br>  ax = fig.add_subplot(2, 2, temp+1)<br>  temp +=1<br>  ax.imshow(annoted_images[i])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*ev_9HzeKCtFr4tdJjO9uAA.png" /></figure><p>Now we can see that it doesn’t detect every object of interest. These annotations work with 0.5 confidence that are mentioned by the authors. By slightly tunning down the confidence to 0.48 it’s capable of detection more object. However, It’s not a good thing to lower the confidence just because.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*qRM3_A2VV8avsi3fpBJlYA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*ev_9HzeKCtFr4tdJjO9uAA.png" /><figcaption>Left. confidence set to 0.48. Right confidence set to 0.5</figcaption></figure><p>We can see now that in addition to the person, the model can detect now 2 out 3 chairs instead of only 1. Just to keep advancing I’ll for now only use the MediaPipe solution at 0.5 confidence for now. Some things I am planning to do in other to enhance the performance of the model is to train it from scratch using PyTorch, or using some image processing methods to illuminate the image or minimize shadows, allowing the model to work with more clear information. However doing this is secondary since what I’d like to do next is to get a 3D projection of the detected object as it is shown by the authors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*HMwDfNAjjro2a_dXs7msPA.png" /></figure><h4>references</h4><p>[1]. Z. Li, F. Song, B. C. Clark, D. R. Grooms, and C. Liu, “A Wearable Device for Indoor Imminent Danger Detection and Avoidance With Region-Based Ground Segmentation,” <em>IEEE Access</em>, vol. 8, pp. 184808–184821, 2020, doi: <a href="https://doi.org/10.1109/access.2020.3028527.">https://doi.org/10.1109/access.2020.3028527.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de999cabc14a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to install PWC-Net and Ubuntu on Windows 11]]></title>
            <link>https://riccmezz.medium.com/how-to-install-pwc-net-and-ubuntu-on-windows-11-c187378cbb08?source=rss-4d0064503450------2</link>
            <guid isPermaLink="false">https://medium.com/p/c187378cbb08</guid>
            <category><![CDATA[cuda-toolkit]]></category>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[cuda]]></category>
            <dc:creator><![CDATA[Rick]]></dc:creator>
            <pubDate>Tue, 30 Apr 2024 22:37:58 GMT</pubDate>
            <atom:updated>2024-04-30T22:37:58.532Z</atom:updated>
            <content:encoded><![CDATA[<h4>Where to start?</h4><p>It might be easier if you don’t have any other version of CUDA installed or any other Ubuntu subsystem. If you do, and the installations you currently have are essential to whatever work you need to do, start by installing the most problematic library in this case, which is <a href="https://cupy.dev/">CuPy</a>.</p><p>Before getting into anything else, let’s check out the version od PWC-Net I’ll use:</p><p><a href="https://github.com/sniklaus/pytorch-pwc/tree/master">GitHub - sniklaus/pytorch-pwc: a reimplementation of PWC-Net in PyTorch that matches the official Caffe version</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_DQw_vznYHCpeYus" /></figure><p>In my experience, the problematic library is CuPy. According to the requirements file you’ll need at least CuPy 5.0</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/355/1*CP5EhsQWlMjTw23midYmtg.png" /></figure><p>Looking at the minimum pytorch version which is 1.6.0, we need CUDA 10.1. However the CuPy page shows the min requirements for CUDA</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*UcA00iIZD9UAeiyeJFPfhw.png" /></figure><p>So 10.1 is a no go. Just because I’d like to not have to mess with uninstalling and installing again for a future project, I’m going to choose CUDA 11.8 and it’s corresponding pytorch version (2.2.2)</p><p>Now that we decided on the versions, let’s make sure no cuda is installed. Or check what CUDA version is compatible with the necesary CuPy version.</p><p>check cuda install</p><pre>~$ nvidia-smi </pre><p>If you are working in windows the same command will work to check if it exist. If it does, uninstall CUDA like you would any other program.</p><h4>Start installing</h4><p>if you have a “clean slate” start by installing ubuntu 18.04 or 22.04 from the microsoft store</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*oMbFO6CSdLVWhlgrZyXLYw.png" /></figure><p>Once you have, let’s install Anaconda to keep am organized environment. You can follow this Digital Ocean article on how to install it easily.</p><p><a href="https://www.digitalocean.com/community/tutorials/how-to-install-anaconda-on-ubuntu-18-04-quickstart">How To Install Anaconda on Ubuntu 18.04 [Quickstart] | DigitalOcean</a></p><p>Now we can create an environment with the following command:</p><pre>~$ conda create --name pwcnet</pre><p>and the following command to enter the environment:</p><pre>~$ conda activate pwcnet</pre><p>if you forgot the name of your installation</p><pre>~$ conda env list</pre><h4>Install CUDA 11.8</h4><p>I’m not gonna cover it for windows since it’s just clicking to the next stage. For ubuntu or any other Linux distribution you’d like, follow the steps presented on the official page for <a href="https://developer.nvidia.com/cuda-11-8-0-download-archive?target_os=Windows&amp;target_arch=x86_64&amp;target_version=11&amp;target_type=exe_local">CUDA 11.8</a></p><p>follow this video for reference</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F1HzYU2_t3yc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D1HzYU2_t3yc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F1HzYU2_t3yc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/35228a762edd3a72df9dd3db13f9bc13/href">https://medium.com/media/35228a762edd3a72df9dd3db13f9bc13/href</a></iframe><p>Check CUDA Install</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*sLOL1cPJ0oalRpegzrTiFg.png" /></figure><p>reboot and check installation</p><h4>Install CuPy</h4><pre>~$ pip3 install cupy</pre><h4>Install PyTorch and the rest of dependencies</h4><pre>~$ pip3 install torch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2 --index-url https://download.pytorch.org/whl/cu118<br>~$ pip3 install pillow</pre><h4>Clone github and test the code</h4><pre>~$ git clone https://github.com/sniklaus/pytorch-pwc.git<br>~$ cd pytorch-pwc</pre><p>once it’s done, run this command</p><pre>~$ python run.py --model default --one ./images/one.png --two ./images/two.png --out ./out.flo</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c187378cbb08" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Step 2.B : Adapting the RANSAC algorithm for Ground detection]]></title>
            <link>https://riccmezz.medium.com/step-2-b-adapting-the-ransac-algorithm-for-ground-detection-12487c85280b?source=rss-4d0064503450------2</link>
            <guid isPermaLink="false">https://medium.com/p/12487c85280b</guid>
            <category><![CDATA[math]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[electrical-engineering]]></category>
            <dc:creator><![CDATA[Rick]]></dc:creator>
            <pubDate>Sun, 28 Apr 2024 03:01:48 GMT</pubDate>
            <atom:updated>2024-04-28T03:01:48.383Z</atom:updated>
            <content:encoded><![CDATA[<h3><a href="https://medium.com/@riccmezz/step-2-a-calculating-angle-between-the-plane-normal-and-the-axis-0d639291ef4c?source=your_stories_page-------------------------------------">Step 2.B </a>: Adapting the RANSAC algorithm for Ground detection</h3><p>Now that we have the tools necessary from previous articles, we can proceed to modify a bit the RANSAC algorithm for floor detection.</p><ol><li><a href="https://medium.com/p/f5b5caa9c768"><strong>Step 1: Image filtering</strong></a></li><li><a href="https://medium.com/me/stats/post/57a4e4f84f0d"><strong>Step 2: Modified RANSAC algorithm for floor detection</strong></a></li><li><a href="https://medium.com/me/stats/post/0d639291ef4c"><strong>Step 2.A : Calculating angle between the plane normal and the axis</strong></a></li></ol><p>Following the pseudocode:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*7nj-TLrYtnfAibiDqWusmQ.png" /></figure><p>Where we know know how to randomly sample a plane, it’s coefficients and the normalized Normal vector, with this we can restrain the angle within an acceptable angle range with respect to the floor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*uw503irNrH3IfuUsvTVXKg.png" /></figure><p>Then we calculate the distance from each point to the plane and find the inliers which are the data points corresponding to the floor data points. also we calculate the standard deviation of this group of inliers. If these inliers are within the selected parameters the they are the best inliers so far.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*HSA3E1RsTzMc9quj2wwHew.png" /></figure><p>code in python:</p><pre>import matplotlib.pyplot as plt<br>from mpl_toolkits.mplot3d import Axes3D<br>import math<br>import numpy as np<br><br>def fit_plane_ransac(data, threshold=0.01, max_iterations=100):<br>    i = 0<br>    bestSupport = 0<br>    best_plane = [0,0,0,0]<br>    best_inliers = []<br>    BestStDeviation = 10e10<br>    while i  &lt; max_iterations:<br>        # Randomly sample three points<br>        sample_indices = np.random.choice(len(data), 3, replace=False)<br>        p1, p2, p3 = data[sample_indices]<br>        # Fit a plane to the sampled points<br>        normalVector, Currplane = calculate_plane_coefficients(p1,p2,p3)<br>        diff = angle_between_vectors(normalVector,(0,1,0))<br>        diff = np.degrees(diff)<br>        if(diff &lt; 4):<br>            d = -np.dot(normalVector, p1)<br>            Currplane = np.concatenate((normalVector, [d]))<br>            # Calculate distances from all points to the plane<br>            distances = np.abs(np.dot(data, normalVector) + d) / np.linalg.norm(normalVector)<br>            # Count inliers (points within the threshold distance from the plane)<br>            inliers = data[distances &lt; threshold]<br>            std = np.std(inliers)<br>            # Update best plane if the current one has more inliers<br>            if (len(inliers) &gt; bestSupport) or ((len(inliers) == bestSupport) and (std &lt; BestStDeviation)):<br>                bestSupport = len(inliers)<br>                best_plane = Currplane<br>                best_inliers = inliers<br>                BestStDeviation = std<br>            else:<br>                i = i + 1<br>                <br>            <br>    return best_plane, best_inliers<br><br>rs = np.random.seed(42)<br>np.random.seed(rs)<br><br><br># Fit a plane using RANSAC<br>best_plane, inliers = fit_plane_ransac(subsampled_points, threshold=75, max_iterations=200)<br><br>print(&quot;Best Plane Parameters:&quot;, best_plane)<br><br># Plot the data and the best-fit plane<br>import matplotlib.pyplot as plt<br>from mpl_toolkits.mplot3d import Axes3D<br><br>print(best_plane)<br><br>fig = plt.figure()<br>ax = fig.add_subplot(111, projection=&#39;3d&#39;)<br>ax.scatter(subsampled_points[:,0], subsampled_points[:,1], subsampled_points[:,2],alpha=0.15,  label=&#39;Noisy 3D Data&#39;, c = subsampled_points[:,2],cmap = &#39;viridis&#39;)<br>ax.scatter(inliers[:,0], inliers[:,1], inliers[:,2],alpha=0.95, color=&#39;red&#39;, label=&#39;Inliers&#39;)<br>ax.set_xlabel(&#39;X&#39;)<br>ax.set_ylabel(&#39;Y&#39;)<br>ax.set_zlabel(&#39;Z&#39;)<br>ax.legend()<br>plt.title(&#39;RANSAC Plane Fitting in 3D&#39;)<br>plt.show()<br><br></pre><p>finally we plot the image with the inliers which are in red. This code is a bit slow and the are some things that I do plan to enhance but for now in order to keep advancing I skip to the next objective of the paper which is object detection with Google’s <a href="https://developers.google.com/mediapipe">MediaPipe</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*1mrCDcIDhTnWnDGcjyBe5Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*we8rUxmFzqu8xPfty0aRDg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12487c85280b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Step 2.A : Calculating angle between the plane normal and the axis]]></title>
            <link>https://riccmezz.medium.com/step-2-a-calculating-angle-between-the-plane-normal-and-the-axis-0d639291ef4c?source=rss-4d0064503450------2</link>
            <guid isPermaLink="false">https://medium.com/p/0d639291ef4c</guid>
            <category><![CDATA[math]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[geometry]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Rick]]></dc:creator>
            <pubDate>Fri, 26 Apr 2024 04:08:27 GMT</pubDate>
            <atom:updated>2024-04-27T17:25:44.000Z</atom:updated>
            <content:encoded><![CDATA[<h3>Step 2.A : Calculating angle between the plane normal and the axis</h3><p>In the last Article, we saw a problem with the RANSAC algorithm because we need to ensure that the estimated plane is parallel to the ground. From the image below we can see the orientation of the point cloud. So now we can delimit our problem to the following. We need to ensure that the angle between the y-axis and the normal vector of the plane is either 0° or within an acceptable threshold which in fact the authors did detail in their research as a maximum of 5 ° [1]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*NBW3jvl51rFdXxayqMM5Og.png" /><figcaption>Fig 1. point cloud generation from a depth image</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*b0mZ9eQwmSGaLA5xHspzQg.png" /><figcaption>Fig 2. table of configurations for the modified algorithm</figcaption></figure><p>so for the whole RANSAC algorithm, we need to start with a couple of basic functions. First how to sample the random plane, how is it generated. Then we need to check that it’s within the threshold.</p><h4>Generating the plane</h4><p>This part is quite simple actually. We need to generate the coefficients of the plane and also we need the normal vector of said plane. Now if you recall your pre-calc classes or physics, we can use 3 points to form 2 vectors. Let’s observe fig 3, we can form two vectors LP and LM, with this all that is left to do is the cross product between these vectors to get a vector which is orthogonal to both vectors, giving us the normal vector to our plane.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9rjZL2R-jstMfz9UNjJJ2A.jpeg" /><figcaption>Fig 3. Estimating a plane from 3 random points</figcaption></figure><p>To understand better here’s an example</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FrL9UXzZYYo4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DrL9UXzZYYo4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FrL9UXzZYYo4%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4961d3f46d06808f41acab6f34a7a75/href">https://medium.com/media/c4961d3f46d06808f41acab6f34a7a75/href</a></iframe><p>Now the code to get the plane from 3 random points.</p><pre>import numpy as np<br><br>def calculate_plane_coefficients(point1, point2, point3):<br>    # Create vectors between the points<br>    vector1 = (np.array(point1) - np.array(point2)).astype(float)<br>    vector2 = (np.array(point3) - np.array(point2)).astype(float)<br>    # Calculate the normal vector to the plane using cross product<br>    normal_vector = np.cross(vector1, vector2)<br>    # Normalize the normal vector<br>    normal_vector /= np.linalg.norm(normal_vector)<br>    # # Calculate the constant term D in the plane equation Ax + By + Cz + D = 0<br>    D = -np.dot(normal_vector, point1)<br>    <br>    # Coefficients [A, B, C, D] of the plane equation<br>    plane_coefficients = np.concatenate((normal_vector, [D]))<br>    <br>    return normal_vector, plane_coefficients<br><br># Example usage<br>point1 = [4, -2, 7]<br>point2 = [2, 1, 4]<br>point3 = [5, 3, -2]<br><br>normal_vector, plane_coefficients = calculate_plane_coefficients(point1, point2, point3)<br>print(&quot;Normal Vector:&quot;, normal_vector)<br>print(&quot;Plane Coefficients:&quot;, plane_coefficients)</pre><p>Now to monitor our threshold of 5° we can simply calculate the angle between the normal vector of the plane and the y-axis (0,1,0). We can do this with the following equation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9H2YAQl2zXecFIiXyMhcaw.jpeg" /></figure><pre>def angle_between_vectors(vector1, vector2):<br>    dot_product = np.dot(vector1, vector2)<br>    magnitudes = np.linalg.norm(vector1) * np.linalg.norm(vector2)<br>    return np.arccos(dot_product / magnitudes)</pre><p>Understanding these two simple but important functions will be helpful to grasp the idea of the modified RANSAC algorithm. In the next article I will present the code that segments the floor by combining these last two steps.</p><h4>Reference</h4><p>[1] Z. Li, F. Song, B. C. Clark, D. R. Grooms, and C. Liu, “A Wearable Device for Indoor Imminent Danger Detection and Avoidance With Region-Based Ground Segmentation,” <em>IEEE Access</em>, vol. 8, pp. 184808–184821, 2020, doi: <a href="https://doi.org/10.1109/access.2020.3028527.">https://doi.org/10.1109/access.2020.3028527.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0d639291ef4c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Step 2: Modified RANSAC algorithm for floor detection]]></title>
            <link>https://riccmezz.medium.com/step-2-modified-ransac-algorithm-for-floor-detection-57a4e4f84f0d?source=rss-4d0064503450------2</link>
            <guid isPermaLink="false">https://medium.com/p/57a4e4f84f0d</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[math]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[image-processing]]></category>
            <dc:creator><![CDATA[Rick]]></dc:creator>
            <pubDate>Thu, 25 Apr 2024 03:01:57 GMT</pubDate>
            <atom:updated>2024-04-25T03:01:57.389Z</atom:updated>
            <content:encoded><![CDATA[<p>let’s divide an conquer</p><h4>Quick Intro</h4><p>If you already have a solid understanding of trigonometry, and vector calculus and the RANSAC algorithm, you may find this article a bit too easy. If you´re like me and barely understood the algorithm # 1 presented in <a href="https://ieeexplore.ieee.org/document/9211506/;">[1]</a>, stick around because we are going to tackle the problem step by step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*C7gxxc2bCNuOUNdsSigGow.png" /><figcaption>Fig 1. Modified RANSAC algorithm</figcaption></figure><h4>Asked chat GPT for help</h4><p>I asked our good friend to generate some code for a base RANSAC algorithm in 3D, here’s the result.</p><pre>import numpy as np<br><br>def fit_plane_ransac(data, threshold=0.1, max_iterations=100):<br>    best_plane = None<br>    best_inliers = []<br>    <br>    for _ in range(max_iterations):<br>        # Randomly sample three points<br>        sample_indices = np.random.choice(len(data), 3, replace=False)<br>        p1, p2, p3 = data[sample_indices]<br>        <br>        <br>        # Fit a plane to the sampled points<br>        normal = np.cross(p2 - p1, p3 - p1)<br>        normal /= np.linalg.norm(normal)<br>        d = -np.dot(normal, p1)<br>        plane = np.concatenate((normal, [d]))<br>        <br>        # Calculate distances from all points to the plane<br>        distances = np.abs(np.dot(data, normal) + d) / np.linalg.norm(normal)<br>        <br>        # Count inliers (points within the threshold distance from the plane)<br>        inliers = data[distances &lt; threshold]<br>        <br>        # Update best plane if the current one has more inliers<br>        if len(inliers) &gt; len(best_inliers):<br>            best_plane = plane<br>            best_inliers = inliers<br>            <br>    return best_plane, best_inliers<br><br># Example usage<br># Generate random 3D noisy data points around a plane<br>np.random.seed(42)<br>plane_normal = np.array([1, 1, 1])<br>plane_point = np.array([0, 0, 0])<br>noise_level = 0.1<br>num_points = 200<br>data = plane_point + np.random.randn(num_points, 3) * noise_level<br><br><br># Add a few outliers<br>outliers = np.random.randn(10, 3) * 5<br>data = np.concatenate((data, outliers))<br><br># Fit a plane using RANSAC<br>best_plane, inliers = fit_plane_ransac(data, threshold=0.5, max_iterations=100)<br><br>print(&quot;Best Plane Parameters:&quot;, best_plane)<br><br># Plot the data and the best-fit plane<br>import matplotlib.pyplot as plt<br>from mpl_toolkits.mplot3d import Axes3D<br><br>fig = plt.figure()<br>ax = fig.add_subplot(111, projection=&#39;3d&#39;)<br>ax.scatter(data[:,0], data[:,1], data[:,2], label=&#39;Noisy 3D Data&#39;)<br>ax.scatter(inliers[:,0], inliers[:,1], inliers[:,2], color=&#39;red&#39;, label=&#39;Inliers&#39;)<br>xx, yy = np.meshgrid(range(-5, 6), range(-5, 6))<br>zz = (-best_plane[0] * xx - best_plane[1] * yy - best_plane[3]) * 1. / best_plane[2]<br>ax.plot_surface(xx, yy, zz, alpha=0.5, color=&#39;green&#39;, label=&#39;Best-fit Plane&#39;)<br>ax.set_xlabel(&#39;X&#39;)<br>ax.set_ylabel(&#39;Y&#39;)<br>ax.set_zlabel(&#39;Z&#39;)<br>ax.legend()<br>plt.title(&#39;RANSAC Plane Fitting in 3D&#39;)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*bORFPGg2g7iahHJlsbWPzA.png" /><figcaption>Fig 2. RANSAC algorithm in 3D</figcaption></figure><p>Now after seeing this and slowly reading the presented algorithm 1 as well as actually see the point cloud generated from the depth camera images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*NBW3jvl51rFdXxayqMM5Og.png" /><figcaption>Fig 3. point cloud generation from a depth image</figcaption></figure><p>now I have a better understanding of what the modified algorithm. I apologize if my approach is a bit disorganized, but I’m showing you how I got to understand the algorithm, now that I have an basic idea let’s start from the beginning. What is the RANSAC algorithm anyway?</p><h4>RANSAC</h4><p>The acronym stands for Random sample consensus, basically we start with a random estimation line on a data cloud and we calculate how many inliers or data point are the closest to that line, considering a threshold T. The line that is closest to more datapoints is considered the best approximation given a max number of iterations (<a href="https://www.youtube.com/watch?v=9D5rrtCC_E0">here’s a video if that wasn’t clear</a>). One of the uses is to differentiate real data of sensor from noise in the system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*b-_fmrL3p0wGI-yfnfXKfw.png" /><figcaption>Fig 4. RANSAC algorithm in 2D</figcaption></figure><p>How does this relate to the paper? well for starters, as I showed the RANSAC algorithm can be modeled with a plane instead of a line. Second, our inliers can be points from the 3D point cloud, things are slowly falling into place. let’s take figure 3 (the point cloud) as an example, how would we know what is the floor. We can use a plane, imagine we use this plane like scanner from top to bottom, where do you think the plane will be close to a large number of data points? Near the floor! There’s a problem though, The way the algorithm is constructed It will estimate a plane randomly each time and we couldn’t know for sure even if we are going to find a plane that is parallel to the floor. This is why the authors introduced the modified algorithm. Since this article is running a bit long, and I only planned to introduce the idea, in the next one I’ll show more of the code.</p><h4>References</h4><p>[1] Z. Li, F. Song, B. C. Clark, D. R. Grooms, and C. Liu, “A Wearable Device for Indoor Imminent Danger Detection and Avoidance With Region-Based Ground Segmentation,” <em>IEEE Access</em>, vol. 8, pp. 184808–184821, 2020, doi: <a href="https://doi.org/10.1109/access.2020.3028527.">https://doi.org/10.1109/access.2020.3028527.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57a4e4f84f0d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Step 1: Image filtering]]></title>
            <link>https://riccmezz.medium.com/step-1-image-filtering-f5b5caa9c768?source=rss-4d0064503450------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5b5caa9c768</guid>
            <category><![CDATA[electrical-engineering]]></category>
            <category><![CDATA[math]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[intel]]></category>
            <category><![CDATA[digital-image-processing]]></category>
            <dc:creator><![CDATA[Rick]]></dc:creator>
            <pubDate>Wed, 24 Apr 2024 03:02:00 GMT</pubDate>
            <atom:updated>2024-04-24T03:02:00.787Z</atom:updated>
            <content:encoded><![CDATA[<p>I might change a few things in the future</p><p>In the last article I made an oversimplification of the methodology of the paper done by [1]. In this article I’ll go over the filtering stage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/393/0*Z6hkwlwGzvtYE_sM" /></figure><h4>The three filters</h4><p>In section III.A the authors make mention of the methods for filtering depth images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*AW2InmbUwAhxJEOmg5-qgA.png" /></figure><p>These three stages are not necessarily an invention of theirs, for their solution they use the Intel® RealSense™ Depth Camera D435i, and the manufacturer has presented a full <a href="https://dev.intelrealsense.com/docs/depth-post-processing">article</a> with the methods and how to use the integrated library of the depth camera. These stages include first a Non-Zero subsampling, a spatial filter to preserve edges and a time filter to ensure hole free image.</p><p>The authors also give an explanation of the methods and parameters used in table 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*yFjG5hwvW5RxC0TVxnn6zw.png" /></figure><p>However all of this is done considering an Intel® RealSense™ Depth Camera, In my case (at least to start), I need to use the data from the URFD and the Fall detection dataset, and they both use a Kinect camera from x-box. In any case I’ll begin with how the authors have followed these instructions and later on I’ll see if any other filters or methods better suit my application, however I’ll maintain the three stages which are the smart subsampling, spatial filtering to maintain edges and temporal filtering to get rid of missing data.</p><h4>Non Zero subsampling</h4><p>subsampling is a well known method and usually does not merit an in depth explanation, however, the intel manufacturers recommend doing a smart version of subsampling .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/0*W4cegk2LVmTogrQr.jpg" /><figcaption>usual subsampling example</figcaption></figure><p>The manufacturers explain that a smarter approach should be done, which consist of not only taking every nth pixel but actually taking the average of the 15 nearest neighbors excluding 0.</p><p>here’s the code i made in python for this</p><pre>def nonZeroDownsampling(input):<br>    average = 0<br>    n = 0<br>    for i in input:<br>        for j in i:<br>            if j &gt; 0:<br>                average += j<br>                n += 1<br>    if n == 0:<br>        n = 1<br>    return average/n <br><br>def subsampling_avg(matrix, subs = 4):<br>    [h,w] = (matrix.shape)<br>    result = np.zeros((int(h/subs),int(w/subs)),dtype=np.uint16)<br>    n = 0<br>    m = 0<br>    for i in range(0,h-subs,subs):<br>        m = 0<br>        for j in range(0,w-subs,subs):<br>            intensity = nonZeroDownsampling(matrix[i:i+subs,j:j+subs])<br>            result[n,m] = intensity<br>            m+=1<br>        n+=1<br>    return result</pre><p>I decided to use the first 4 frames of the fall-01 sequence on the URDF dataset. On the left we can see the raw frames with the measurement correction detailed on the URFD page. It’s clear that the image has a lot of missing values on the floor and the rest of the furniture. On the right side we have the Non-Zero subsampling result which has done a decent job at reducing an closing the gaps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*q3qV56UaSOw55OBHCOSK7A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/1*wJWd9EIqoiyfAhMYWIl3xg.png" /></figure><h4>Exponential Moving Average — EMA filtering</h4><p>This is a bit new to me, I have not used this function in the past. In the manufacturers article it is said that this filter is supposed to help with edge preservation. We scan the image on the x axis (row by row) and the apply the <a href="https://en.wikipedia.org/wiki/Moving_average">EMA</a> function as it were a 1D function. Then we apply the same but in the y axis (column by column)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*SR4V-igLHL_ZAi-Ko1czeQ.png" /></figure><p>Here’s the code</p><pre>def EMA1D(array, alpha, thresh):<br>    result = np.zeros(len(array))<br>    result[0] = array[0]<br>    last_value = 0<br>    for i in range(1,len(array)):<br>        if(abs(array[i]-array[i-1]) &lt; thresh):<br>            result[i] = alpha * array[i] + (1-alpha) * last_value<br>        if(abs(array[i]-array[i-1]) &gt; thresh):<br>            result[i] = array[i]<br>        last_value = result[i] <br>    return result<br><br>def EMA2D(img, alpha, thresh):p<br>    img = np.asarray(img)<br>    [x,y] = np.asarray(img).shape<br>    result = np.zeros((x,y), dtype=np.uint16)<br>    for i in range(x):           <br>        result[i][0:y] = EMA1D(img[i][0:y], alpha, thresh)<br>    for j in range(y):<br>        result[:,j] = EMA1D(img[:,j], alpha, thresh) <br>    return result</pre><p>Now, it does seem a little bit off to me , it may be because I don’t know how to accurately choose the right value for the threshold. In another article I’ll check why this is in more detail, but for now I’ll move on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*rAe_mbP6AKERKXDIgeTrRw.png" /></figure><h4>Time filter</h4><p>In this case it is quite simple, we use the values of previous frames to fill in the missing values. In our case we will use a maximum of 2 previous frames to fill our data</p><pre>def fillMissingValues(img0,img1,img2):<br>    [h,w] = np.asarray(img0).shape<br>    result = np.zeros((h,w), dtype=np.uint16)<br>    for i in range(h):<br>        for j in range(w):<br>            if(img0[i][j] == 0):<br>                if(img1[i][j] == 0 and img2[i][j] &gt; 0):<br>                    result[i][j] = img2[i][j]<br>                elif(img1[i][j] == 0 and img2[i][j] == 0):<br>                    result[i][j] =  img0[i][j]<br>                else:<br>                    result[i][j] = img1[i][j]<br>            else:<br>                result[i][j] =  img0[i][j]<br>    return result</pre><p>Here our result will only be 2 images since frame three needs info from 2 and 3, and 4 needs info from 3 and 2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*xqaDE4122HxGnKAVmyF2DQ.png" /></figure><h4>Next steps</h4><p>My next job might be a two or even a three parter since I’m tempted to find new filters that are better suited for images generated with the x-box Kinect, in addition I will be tackling the RANSAC algorithm for ground segmentation, and this will require a bit of trigonometry.</p><h4>References</h4><p>[1]. Z. Li, F. Song, B. C. Clark, D. R. Grooms, and C. Liu, “A Wearable Device for Indoor Imminent Danger Detection and Avoidance With Region-Based Ground Segmentation,” <em>IEEE Access</em>, vol. 8, pp. 184808–184821, 2020, doi: <a href="https://doi.org/10.1109/access.2020.3028527.">https://doi.org/10.1109/access.2020.3028527.</a></p><p>‌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5b5caa9c768" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Articles: A Wearable Device for Indoor Imminent Danger Detection and Avoidance With…]]></title>
            <link>https://riccmezz.medium.com/understanding-articles-a-wearable-device-for-indoor-imminent-danger-detection-and-avoidance-with-7d1d1c1149c7?source=rss-4d0064503450------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d1d1c1149c7</guid>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[disability]]></category>
            <category><![CDATA[gpt]]></category>
            <dc:creator><![CDATA[Rick]]></dc:creator>
            <pubDate>Tue, 23 Apr 2024 03:01:58 GMT</pubDate>
            <atom:updated>2024-04-23T03:01:58.169Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding Articles: <a href="https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=9211506">A Wearable Device for Indoor Imminent Danger Detection and Avoidance With Region-Based Ground Segmentation</a></h3><p>It may have promising applications for my research</p><h4>The summary</h4><p>A group of researchers have developed a wearable solution that helps the visually impaired to navigate unfamiliar and complex indoor rooms such as offices or even malls. They make use of a depth camera and and a small speaker that serves as an acoustic feedback to tell the user that there’s an object in a particular direction of their path</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/0*ZfJ5FJtA93NiPTx9" /></figure><h4>The general flow</h4><p>The flow diagram shows the steps that the hole solution follows, there’s 5 main stages from.</p><ol><li>Image and IMU data acquisition</li><li>Realtime orientation and Height estimation</li><li>Region based ground segmentation</li><li>Object detection</li><li>3D acoustic feedback</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/0*RuACbzXARYzfRxOn" /></figure><h4>What Can I use for my research</h4><p>If you’ve been following for some time, and also if you have good memory, because i did mention this like my first ever article. You might remember that I was inspired to make an AI model to detect anomalies such as fall detection for the elderly and disabled in indoor scenarios. Hopefully once I get fall detection right, I can share with you my journey with other signals such a heart rate. In any case I’d like to adapt this solution to not be a wearable and to be a stationary camera solely for fall detection, at least for now. So what is my idea?</p><p>Instead of using the depth camera as a wearable I will work with the assumption that the camera will be in a fixed place. Why? so I can test my fall detection and fall scenario solution with multiple datasets as well as my own constructed dataset.</p><p>What databases can use? the <a href="http://fenix.ur.edu.pl/~mkepski/ds/uf.html">URFD </a>which does have depth camera information, and the <a href="https://falldataset.com/">Fall detection dataset</a> which are datasets with a big impact paper.</p><p>In the next couple of articles I’ll go part by part of what was covered in the paper with my own code and with the help of Chat GPT, why? because I’m working and studying at the same time, and I don’t have money for an assistant. Ok, that’s it for now. Thanks for reading :)</p><p>References</p><p>[1] <a href="https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=9211506">https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=9211506</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d1d1c1149c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding AI:]]></title>
            <link>https://riccmezz.medium.com/understanding-ai-983be409775b?source=rss-4d0064503450------2</link>
            <guid isPermaLink="false">https://medium.com/p/983be409775b</guid>
            <category><![CDATA[llm-applications]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[science]]></category>
            <category><![CDATA[gpt]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Rick]]></dc:creator>
            <pubDate>Mon, 22 Apr 2024 03:02:06 GMT</pubDate>
            <atom:updated>2024-04-22T03:02:06.964Z</atom:updated>
            <content:encoded><![CDATA[<p>As part of my effort to build a fall detection system, I’ll share this week’s papers I’ve read</p><h3>Slot-VLM: SlowFast Slots for Video-Language Modeling</h3><p>available <a href="https://arxiv.org/abs/2402.13088">here</a></p><h4>Introduction</h4><p>Large Language Models, have gained a lot attention due to their tremendous advancements, in generating and understanding human text very accurately. These advancements have also introduced benefits, for captioning techniques [1].</p><p>MiniGPT-4 is an implementation that uses a Q-Former (Querying Transformer). The basic principle is that, as we know for transformers we dive an image into “tokens”. These tokens are generated by an image encoder or commonly known as the feature extraction section. The these tokens or queries are fed in to the LLM section of the model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*abwmnnNks5qQuK1tKowO6g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e_cOSMBCrvY79McNhsqePg.png" /></figure><p>See [2,3,4] for more information</p><p>What would happen if we need to generate a description for a video o livestream. In a 5 min video analyzing a t 1fps would be a task of 300 images total with 32 tokens 9600 token in total. Keep in mind this is at 1 fps. Some applications can be time critical and should maintain from 25 to 60 fps. At 25 fps we would need to check at 32 tokens per image: 240,000 tokens in total an increase of more than 99.8% and please keep in mind that we should be grossly uninterested in the amount of data we need to process. Having more computing power should not equate to not caring to optimize algorithms or models.</p><p>The work proposed in [1], compare some other video-oriented solutions that take try to optimize the tokens needed to analyze per image. However as shown in the image below, every token has an influence from nearby pixels or spatial information. The authors show an approach which oriented in object or events to feed into the LLM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*j3WutR5EXupXlhvrYpI5KQ.png" /></figure><p>To be able to only extract object-centric tokens or event centric tokens, they make use the slot-attention, a work done by [5]. Usually a different type of connecter is used, such as the Q-Former. In addition, the authors propose processing the frame in two branches, a branch that takes low frame rate high spatial resolution to gain information about the objects in a scene and a high frame rate, low spatial resolution to focus on the events of the video. After these tokens have been extracted with a visual encoder, these tokens now serve as an input to the slot attention to prepare them for the LLM input.</p><p>This new approach is indeed comparable to the state of the art with a focus on faster inference without sacrificing accuracy as their results show in the table below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QgOzTxYwICJmsvnUqfjeCw.png" /></figure><h4>Uses for my research</h4><p>If you’ve been following my thesis project and my past research, I’ve been trying to expand on the capability of a model to understand and identify what constitutes a possible fall scenario as well as a fallen person, the Slot-VLM is an interesting choice however it’s overkill for this task, I read this research because my advisor asked me too, since it seem like it had potential, however it requires a very large dataset and resources that make my application a bit less accessible when I try to make my research open source. In any case it was a fun and educational read and I hope you enjoyed it too.</p><p>References</p><p>[1] J. Xu, C. Lan, W. Xie, X. Chen, and Y. Lu, “Slot-VLM: SlowFast Slots for Video-Language Modeling,” <em>arXiv (Cornell University)</em>, Feb. 2024, doi: <a href="https://doi.org/10.48550/arxiv.2402.13088.">https://doi.org/10.48550/arxiv.2402.13088.</a></p><p>[2] A. Helwan, “Q-Former,” <em>Medium</em>, Dec. 22, 2023. <a href="https://abdulkaderhelwan.medium.com/q-former-1d83163975da">https://abdulkaderhelwan.medium.com/q-former-1d83163975da</a> (accessed Mar. 05, 2024).</p><p>[3] Li, D. Li, S. Savarese, and Steven, “BLIP-2: Bootstrapping Language-Image Pre-training with Frozen Image Encoders and Large Language Models,” Jan. 2023, doi: <a href="https://doi.org/10.48550/arxiv.2301.12597.">https://doi.org/10.48550/arxiv.2301.12597.</a></p><p>[4] D. Zhu, J. Chen, X. Shen, X. Li, and M. Elhoseiny, “MiniGPT-4: Enhancing Vision-Language Understanding with Advanced Large Language Models,” arXiv.org, Apr. 20, 2023. <a href="https://arxiv.org/abs/2304.10592">https://arxiv.org/abs/2304.10592</a></p><p>[5] F. Locatello <em>et al.</em>, “Object-Centric Learning with Slot Attention,” <em>arXiv (Cornell University)</em>, Jan. 2020, doi: <a href="https://doi.org/10.48550/arxiv.2006.15055.">https://doi.org/10.48550/arxiv.2006.15055.</a></p><p>‌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=983be409775b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Next Steps]]></title>
            <link>https://riccmezz.medium.com/next-steps-29fe246159ea?source=rss-4d0064503450------2</link>
            <guid isPermaLink="false">https://medium.com/p/29fe246159ea</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[yolov8]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Rick]]></dc:creator>
            <pubDate>Tue, 05 Mar 2024 22:01:36 GMT</pubDate>
            <atom:updated>2024-03-05T22:01:36.167Z</atom:updated>
            <content:encoded><![CDATA[<p>now that I passed my thesis project, my advisor was kind enough to help me turn my thesis into a publishable work.</p><h4>What’s the Plan</h4><p>By the time I’m writing this, I’ve already spent a considerable amount of time revising state of the art solutions for fall detection. Specifically, there’s a IEEE Survey article that help a lot with summarizing various approaches. <a href="https://ieeexplore.ieee.org/abstract/document/10225507">Advances in Skeleton-Based Fall Detection in RGB Videos: From Handcrafted to Deep Learning Approaches</a>. You can read it for more information. In any case, my advisor suggested we take a different approach since there a numerous papers that already get to 100% accuracy in various databases. Now, the approach is to analyze the context of a given situation to predict one of two scenarios. Number one is to give a probability that a fall is going to occur, and second, after detecting the fall, we need to describe how severe the fall was, nothing too fancy but certainly a level up from just detecting whether someone fell or not.</p><h4>My progress</h4><p>So far I’ve been a bit stuck. I started using pytorch, since I already have experience with it, the problem is that using it in Google Colab, training any CNN based architecture with images of a resolution of even 256x256 will most definitely kill my session before the accuracy has reached 30%. So i decided to train YOLO models, in combination with the sdk that Roboflow offers for the latest versions it helped a lot. I made a simple database from existing images in the Roboflow universe, and I have some promising results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P3ugh0lab0rbXiFkw7iyHA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*2nygs_EH6223QhY1Bb67sg.png" /></figure><p>The images above are a result from the same YOLOv8 model trained on the same dataset, obviously there’s room for improvement but before I continue babbling about what I can improve or what I plan to do, let me explain what the system is supposed to do. I talked about identifying two different scenarios, first we need to identify trip hazards or “dangerous” items/object/behaviors that can result in a fall. I tested this idea in chatpgt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*XO_vhHPDWpctit2BUvkr2w.png" /></figure><p>Basically the system has two parts. The item/object/behavior detection and the second model will describe or give a probability that a fall is possible or even imminent. The idea is simple and it works, however I do expect to encounter problems and to evolve this idea. I don’t know what problems I’ll encounter, I’m engineer and like any good one you should always expect a problem in a near future. Anyway, What gave me the idea of this system is a paper I saw on <a href="https://ieeexplore.ieee.org/document/7891049">Satellite surveillance</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*5LKQoEANIhOD_GMT0zhTWg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*k1FEceIoRM2_zD6bi-QLUA.png" /></figure><p>Using Roboflow is great, but I need to figure out how to customize the model if I want to make any other progress. Another issue is that while the <a href="https://ieeexplore.ieee.org/document/7891049">Satellite surveillance</a> paper works, it’s intended use is for still images, not videos. So my next challenge is as follows:</p><ul><li>Investigate research about caption generation and object tracking based on videos</li><li>Keep playing with roboflow to boost my research.</li></ul><p>I was actually planning on writing this article about a paper I need to read for my next session, but this article is plenty long. I’ll write about it another blog this week.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29fe246159ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>