Jekyll2023-02-10T17:05:35+00:00https://sachinkmohan.github.io//feed.xmlSacmon CodesI have worked on a Deep Learning projects, Web Development-VueJS, App Development-React Native and currently working on implementing Deep Learning on Jetson Xavier AGX.Recent Learnings in Web Development2023-02-03T14:00:00+00:002023-02-10T13:00:00+00:00https://sachinkmohan.github.io//learning-in-web-dev<h1 id="jest">Jest</h1>
<ul class="task-list">
<li class="task-list-item">
<p><input type="checkbox" class="task-list-item-checkbox" disabled="disabled" />Learn 10 Jest Commands
<img src="https://geps.dev/progress/10" alt="" /></p>
</li>
<li class="task-list-item">
<p>toBeTruthy()</p>
</li>
</ul>
<h1 id="vim">Vim</h1>
<ul class="task-list">
<li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox" disabled="disabled" />Learn 20 Vim Commands
<img src="https://geps.dev/progress/5" alt="" /></li>
</ul>
<h3 id="compiled-from-these-blogs-1-2">Compiled from these blogs <a href="https://scaron.info/blog/vim-keyboard-shortcuts.html">1</a> <a href="https://stevelosh.com/blog/2010/09/coming-home-to-vim/">2</a></h3>
<ul>
<li>b B w W -> moves by words or token. Faster than using arrow keys.</li>
<li>gi -> for landing to the last edited position</li>
</ul>Jest Learn 10 Jest CommandsWeb and Mobile Apps I built so far2022-07-08T08:00:00+00:002022-07-08T09:00:00+00:00https://sachinkmohan.github.io//apps-i-built-so-far<p>[Deutsch]
Unten sind die Liste der Apps, die ich bisher erstellt habe.</p>
<h3 id="web-entwicklung">Web Entwicklung</h3>
<p>Einfache Malayalam-Bildungswebsite, die mit Vuepress in <strong>VueJS</strong>- Backbone erstellt wurde - <a href="https://easymalayalam.fun/">Website</a>
Veganer oder pflanzlicher Ernährungsblog, der in <strong>ReactJS</strong> erstellt wurde - <a href="https://enchanting-pika-6dfd29.netlify.app/">Website</a></p>
<h3 id="app-entwicklung">App-Entwicklung</h3>
<p>Einfache Malayalam-Bildungssprach-App, die in <strong>React-Native</strong> -> <a href="https://www.dropbox.com/s/9i54fdl0ak9e0bh/EM_App_so_far_17th_May_22.mp4?dl=0">Dropbox Video link</a></p>
<hr />
<p>[English]
Below are the list of apps that I built so far.</p>
<h3 id="web-development">Web Development</h3>
<ul>
<li>Easy Malayalam educational website built in Vuepress with <strong>VueJS</strong> backbone - <a href="https://easymalayalam.fun/">Website</a></li>
<li>Vegan or plant based diet blog built in <strong>ReactJS</strong> -<a href="https://enchanting-pika-6dfd29.netlify.app/">Website</a></li>
</ul>
<h3 id="app-development">App Development</h3>
<ul>
<li>Easy Malayalam educational language app built in <strong>React-Native</strong> -> <a href="https://www.dropbox.com/s/9i54fdl0ak9e0bh/EM_App_so_far_17th_May_22.mp4?dl=0">Dropbox Video link</a></li>
</ul>[Deutsch] Unten sind die Liste der Apps, die ich bisher erstellt habe.Python essentials2022-05-15T07:00:00+00:002022-05-15T07:15:00+00:00https://sachinkmohan.github.io//python_essentials<ol>
<li>Best practices for writing python main()</li>
</ol>
<p><img src="/assets/images_for_the_posts/2022-05-15-python_essentials-python_best_practices.png" alt="Imgur" height="600px" width="600px" />.
<br />
<a href="https://www.youtube.com/watch?v=lOeIDvyRUQs">Reference</a></p>Best practices for writing python main()Opencv cheat sheet2022-03-17T07:00:00+00:002022-03-17T07:15:00+00:00https://sachinkmohan.github.io//opencv-cheat-sheet<p><strong>1. Reading files from a folder</strong></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>import os
import cv2
rootdir = "directory path"
for subdir, dirs, files in os.walk(rootdir):
for file in files:
frame = cv2.imread(os.path.join(subdir, file))
</code></pre></div></div>
<p><strong>2. Installing opencv in pip</strong></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>pip uninstall opencv-python-headless -y
pip install opencv-python --upgrade
</code></pre></div></div>
<p><strong>3. Printing an image</strong></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>while(True):
cv2.imshow('im', seg_img)
if cv2.waitKey(1) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
</code></pre></div></div>1. Reading files from a folder import os import cv2 rootdir = "directory path" for subdir, dirs, files in os.walk(rootdir): for file in files: frame = cv2.imread(os.path.join(subdir, file))Deep learning cheat sheet2022-03-01T14:00:00+00:002022-03-01T14:00:00+00:00https://sachinkmohan.github.io//deep-essentials<p><strong>1. How to compare 2 numpy arrays online</strong></p>
<p>There are no reliable online tools. 2 options. One is in python, other is in pycharm. I wanna explain about the latter.
Load the numpy array using <code class="language-plaintext highlighter-rouge">np.load</code> and then hit the debug mode in pycharm. View the variable you loaded as array in pycharm and then export it to csv files.
Then use any online csv compare tool to compare the arrays</p>
<p><strong>2. View the inputs and outputs of a frozen_graph</strong></p>
<ul>
<li>Replace <code class="language-plaintext highlighter-rouge">graph_inputs</code> by <code class="language-plaintext highlighter-rouge">graph_outputs</code> to print the outputs</li>
</ul>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>import graphsurgeon as gs
graph = gs.DynamicGraph('./mask_rcnn_inception_v2_coco_2018_01_28/frozen_inference_graph.pb')
print(graph.graph_inputs)
</code></pre></div></div>
<p>Make sure to install <code class="language-plaintext highlighter-rouge">pip install graphsurgeon</code></p>
<p><strong>3. Freeze all the packages in your pip environment to the requirements.txt</strong> ➡️
<code class="language-plaintext highlighter-rouge">pip3 freeze > requirements.txt</code></p>
<p><strong>4. Adding frame rate or fps to the opencv frames</strong></p>
<ul>
<li>https://learnopencv.com/how-to-find-frame-rate-or-frames-per-second-fps-in-opencv-python-cpp/</li>
</ul>
<p><strong>5. If CUDA goes out of memory while running on pycharm</strong></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>import os
os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'
</code></pre></div></div>
<p><strong>6. To see if the GPU is available for training in tensorflow</strong> <br /></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
</code></pre></div></div>
<p><strong>7. Tensorboard basics</strong> <br /></p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">tensorboard</span> <span class="o">--</span><span class="n">logdir</span> <span class="n">logs</span><span class="o">/</span><span class="n">fit</span>
</code></pre></div></div>
<p>Tunnelling tensorboard</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">#from your local machine, run
</span>
<span class="n">ssh</span> <span class="o">-</span><span class="n">N</span> <span class="o">-</span><span class="n">f</span> <span class="o">-</span><span class="n">L</span> <span class="n">localhost</span><span class="p">:</span><span class="mi">16006</span><span class="p">:</span><span class="n">localhost</span><span class="p">:</span><span class="mi">6006</span> <span class="o"><</span><span class="n">user</span><span class="o">@</span><span class="n">remote</span><span class="o">></span>
<span class="c1">#on the remote machine, run:
</span>
<span class="n">tensorboard</span> <span class="o">--</span><span class="n">logdir</span> <span class="o"><</span><span class="n">path</span><span class="o">></span> <span class="o">--</span><span class="n">port</span> <span class="mi">6006</span>
</code></pre></div></div>1. How to compare 2 numpy arrays onlineInstall tensorflow for jetson jetpack 46 or 4.62022-01-28T11:00:00+00:002022-01-28T11:15:00+00:00https://sachinkmohan.github.io//install-tf-for-jetpack-46<p>The standard packages are not working as described in this <a href="https://docs.nvidia.com/deeplearning/frameworks/install-tf-jetson-platform-release-notes/tf-jetson-rel.html#tf-jetson-rel">link</a></p>
<p>You can use the below to install for Jetpack 4.6.</p>
<p><code class="language-plaintext highlighter-rouge">sudo pip3 install --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v461 tensorflow==1.15.5</code></p>
<p>Found this new directory under the given link, which was uploaded on 26th Jan 2022. They have 2 versions, one is for <code class="language-plaintext highlighter-rouge">1.15.5</code> and for the stable version <code class="language-plaintext highlighter-rouge">2.7.0</code></p>
<p>https://developer.download.nvidia.com/compute/redist/jp/v461/tensorflow/</p>The standard packages are not working as described in this linkBooting Jetson Xavier AGX from the SD Card2022-01-27T14:00:00+00:002022-01-27T15:00:00+00:00https://sachinkmohan.github.io//booting-from-external-sdcard-jetson<p>First of all, I would like to thank Jetson Hacks for creating a wonderful <a href="https://www.jetsonhacks.com/2017/01/26/run-jetson-tx1-sd-card/">tutorial</a></p>
<p>I just followed everything as described in his blog until the part where I had to edit the <code class="language-plaintext highlighter-rouge">extlinux.conf</code> file.</p>
<p>So below instructions is just an add-on to his blog on that part alone for Jetson AGX Xavier.</p>
<p><code class="language-plaintext highlighter-rouge">mount | head -n 1</code> -> Tells which partition your OS is booted from -> A command which is very hand in the end to check where the OS is booting from. So make
sure you enter this before and after making the changes on the Jetson board.</p>
<p>So I changed the original EMMC(i.e on the Jetson board itself without the SD card) <code class="language-plaintext highlighter-rouge">extlinux.conf(/boot/extlinux/extlinux.conf)</code>
My original <code class="language-plaintext highlighter-rouge">extlinux.conf</code> looks like below after the change. Make sure you take a backup as suggested by jetsonhacks in his blog and video. I changed the <code class="language-plaintext highlighter-rouge">mmbclk0p1</code> to <code class="language-plaintext highlighter-rouge">mmbclk1p1</code> and then things started working. My jetson board booted after that from the SD card. Yes, don’t be surprised, that’s the only change I did. But there is one problem. If you remove the SD, the device will not boot again. So if you wish to boot it again from the internal EMMC, make sure you reset it back to the original state. Yeah, it’s a pretty dirty hack. But it works!!</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>**************************************************************************************************************************************
TIMEOUT 30
DEFAULT primary
MENU TITLE L4T boot options
LABEL primary
MENU LABEL primary kernel
LINUX /boot/Image
INITRD /boot/initrd
APPEND ${cbootargs} quiet root=/dev/mmcblk1p1 rw rootwait rootfstype=ext4 console=ttyTCU0,115200n8 console=tty0 fbcon=map:0 net.ifnames=0 rootfstype=ext4
# When testing a custom kernel, it is recommended that you create a backup of
# the original kernel and add a new entry to this file so that the device can
# fallback to the original kernel. To do this:
#
# 1, Make a backup of the original kernel
# sudo cp /boot/Image /boot/Image.backup
#
# 2, Copy your custom kernel into /boot/Image
#
# 3, Uncomment below menu setting lines for the original kernel
#
# 4, Reboot
LABEL backup
MENU LABEL backup kernel
LINUX /boot/Image.backup
INITRD /boot/initrd
APPEND ${cbootargs}
**************************************************************************************************************************************
</code></pre></div></div>
<p>There are some changes in <code class="language-plaintext highlighter-rouge">/etc/fstab</code> and <code class="language-plaintext highlighter-rouge">/media/ubuntu/UUID/lib/init/fstab</code> that I read on the various forums.
You can ignore this. I didn’t do any changes.</p>
<p>I also edited the <code class="language-plaintext highlighter-rouge">/media/ubuntu/UUID/boot/extlinux/extlinux.conf</code> and those settings didn’t work as described in jetson hacks. Probably it was written in 2017
for old jetpack versions and different versions R32.</p>
<p>In summary, the problem was resolved when I edited the <code class="language-plaintext highlighter-rouge">/boot/extlinux/extlinux.conf</code> on the jetson board and not the one on the SD card. Probably Nvidia or Jetson team decided not to scan the SD card inserted, as it is supposed to be in the boot priority.</p>
<p><strong>Note</strong> - This gives us an advantage that next time if you mess up the SD card, just format the SD card and then copy the image from the eMMC to the SD card again as explained in the jethacks blog. Make sure that you change the settings to <code class="language-plaintext highlighter-rouge">root=/dev/mmcblk0p1</code> in the eMMC.</p>
<p><em>Ignore the below</em> <br />
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx<br />
Doesn’t matter, if fstab is created in <code class="language-plaintext highlighter-rouge">/lib/init</code> folder of the external SD card. Doesn’t matter that either on <code class="language-plaintext highlighter-rouge">/etc/fstab</code> on the EMMC.
What only matters is what you edit in the file extlinux.conf in the internal EMMC. <code class="language-plaintext highlighter-rouge">vim /boot/extlinux/extlinux.conf</code>, just change <code class="language-plaintext highlighter-rouge">mmcblk0p1</code> to <code class="language-plaintext highlighter-rouge">mmcblk1p1</code> <br />
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
<h4 id="updates---11th-mar-2022">Updates -> 11th Mar, 2022</h4>
<ul>
<li>Sometimes the SD card is not recognized, which fails to boot. Then it won’t boot from the emmc. I raised an <a href="https://forums.developer.nvidia.com/t/unable-to-boot-from-emmc-when-not-using-the-sd-card-on-jetpack-4-6/205604">issue</a> with Nvidia. However they don’t have a solution. However, my solutions are
<ul>
<li>Remove and insert the SD card again while turning it off. This should fix the problem most of the time.</li>
<li>If this doesn’t work, you need to flash by running the command <code class="language-plaintext highlighter-rouge">sudo ./flash.sh jetson-xavier mmcblk0p1</code>. This will reset the whole board by erasing all the data on the emmc. Now go back to the <code class="language-plaintext highlighter-rouge">extlinux.conf</code> to reset as described in the beginning of the blog to the SD card.</li>
</ul>
</li>
</ul>First of all, I would like to thank Jetson Hacks for creating a wonderful tutorialThe only github commands you ever need2022-01-25T11:00:00+00:002022-01-25T12:00:00+00:00https://sachinkmohan.github.io//the-only-github-commands<p>These are the github commands that I started with and I would like to share the same with you.</p>
<ul>
<li><code class="language-plaintext highlighter-rouge">git init</code> -> to initialize a github repository</li>
<li><code class="language-plaintext highlighter-rouge">git add .</code> -> adds all the files to be committed</li>
<li><code class="language-plaintext highlighter-rouge">git commit -m "the reason of the commit"</code> -commits the files ready to be pushed</li>
<li><code class="language-plaintext highlighter-rouge">git push -u origin branch_name</code> -> pushes the files to the repository</li>
</ul>
<h4 id="ignore-hidden-files">Ignore hidden files</h4>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>.*
!/.gitignore
</code></pre></div></div>
<p>[1]</p>
<h3 id="advanced-commands---dont-attempt-these-if-you-are-a-git-beginner">Advanced commands - Don’t attempt these, if you are a git beginner</h3>
<p><code class="language-plaintext highlighter-rouge">git rm -r --cached .</code> -> This removes the index but the files resides on the local disk. It is important when you add files in <code class="language-plaintext highlighter-rouge">.gitignore</code>
and is not updated. [2]</p>
<p><code class="language-plaintext highlighter-rouge">git clone -b <branchname> <remote-repo-url></code> -> to clone from a specific branch</p>
<h3 id="references">References</h3>
<p><a href="https://stackoverflow.com/questions/8021441/how-to-ignore-all-hidden-directories-files-recursively-in-a-git-repository">1</a>
<a href="https://stackoverflow.com/questions/5798930/git-rm-cached-x-vs-git-reset-head-x#:~:text=Whether%20git%20add%20was%20used,from%20the%20tree%20as%20well.">2</a></p>These are the github commands that I started with and I would like to share the same with you.Unable to use pyfakeWebcam with opencv2022-01-24T11:00:00+00:002022-01-24T11:00:00+00:00https://sachinkmohan.github.io//cannot-use-pyfakewebcam-with-opencv<p>If you are getting this error while using pyfakewebcam with opencv from this well explained <a href="https://memotut.com/en/696ffb48e154b65fb4d1/">blog</a></p>
<p><code class="language-plaintext highlighter-rouge">TypeError: Expected Ptr<cv::UMat> for argument '%s'</code></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>import cv2
import pyfakewebcam
import numpy as np
gray = pyfakewebcam.FakeWebcam('/dev/video0', 640, 480)
while(True):
# Capture frame-by-frame
print('Type of gray ->', type(gray))
gray = cv2.resize(gray, (500, 300))
cv2.imshow("Pyfakewebcam", gray)
key = cv2.waitKey(1)
if key == 27:
break
gray.release()
cv2.destroyAllWindows()
</code></pre></div></div>
<p><img src="https://user-images.githubusercontent.com/26414662/150806492-eddef48d-6c31-4e63-849a-c4522e1fc07d.png" alt="error_pyfakewebcam" /></p>
<p>If you look closely, I have printed the type of the image that we are getting from <code class="language-plaintext highlighter-rouge">pyfakewebcam</code>. It is not a <code class="language-plaintext highlighter-rouge">np.ndarray</code> as we get from opencv.
Hence we cannot use this pyfakewebcam for opencv operations.</p>If you are getting this error while using pyfakewebcam with opencv from this well explained blogHow to move your most recent file from Downloads to your current working directory2022-01-22T14:00:00+00:002022-01-22T13:00:00+00:00https://sachinkmohan.github.io//useful-script-for-moving-files<p>How many times did you have to navigate to the Downloads folder and move the file to your target directory.
Well, I am tired doing it, so automating it.</p>
<ol>
<li>Create a bash script, in my case I named it to <code class="language-plaintext highlighter-rouge">mvd</code>
<ul>
<li>paste the following [1]
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>#!/bin/sh
filename=$(find /home/mohan/Downloads -type f -printf "%T@ %p\n" | sort -n | cut -d' ' -f 2- | tail -n 1)
mv $filename .
</code></pre></div> </div>
</li>
</ul>
</li>
<li>Give execute permission to the file <code class="language-plaintext highlighter-rouge">chmod +x mvd</code></li>
<li>Add the location containing this script to the <code class="language-plaintext highlighter-rouge">.bashrc</code> file -> <code class="language-plaintext highlighter-rouge">export PATH=$PATH:/home/user/yourfoldername/</code> so that you can basically call it from anywhere.</li>
</ol>
<p>That’s it folks! Enjoy!</p>
<h4 id="ref">Ref</h4>
<hr />
<p><a href="https://stackoverflow.com/questions/1015678/get-most-recent-file-in-a-directory-on-linux">1</a></p>How many times did you have to navigate to the Downloads folder and move the file to your target directory. Well, I am tired doing it, so automating it.