<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rishi Raj</title>
    <description>The latest articles on DEV Community by Rishi Raj (@rishiraj824).</description>
    <link>https://dev.to/rishiraj824</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F20186%2Ffe4d162f-bd82-409f-8ec0-58d0108719ac.png</url>
      <title>DEV Community: Rishi Raj</title>
      <link>https://dev.to/rishiraj824</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rishiraj824"/>
    <language>en</language>
    <item>
      <title>Modal with a Functional Component</title>
      <dc:creator>Rishi Raj</dc:creator>
      <pubDate>Tue, 09 Feb 2021 17:32:21 +0000</pubDate>
      <link>https://dev.to/rishiraj824/modal-with-a-functional-component-2odl</link>
      <guid>https://dev.to/rishiraj824/modal-with-a-functional-component-2odl</guid>
      <description>&lt;p&gt;Yes! yet another modal tutorial but there's a catch! This one attaches an event listener on a div container rather than the document or window. Let's see how:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We first create the basic Modal Functional component
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useRef } from "react";

const Modal = ({ open, onClose, children }) =&amp;gt; {
  const modalRef = useRef(null);

  return (
    open &amp;amp;&amp;amp; (
      &amp;lt;div className="modal-overlay" ref={modalRef}&amp;gt;
        &amp;lt;div className="modal-content"&amp;gt;{children}&amp;lt;/div&amp;gt;
        &amp;lt;button className="close-btn" onClick={onClose}&amp;gt;
          Close
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
    )
  );
};

export default Modal;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;We then attach our event listeners not to the &lt;code&gt;document&lt;/code&gt;, or the &lt;code&gt;window&lt;/code&gt; but to the &lt;code&gt;div&lt;/code&gt; container for our Modal.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useCallback, useEffect, useRef } from "react";

const Modal = ({ open, onClose, children }) =&amp;gt; {
  const modalRef = useRef(null);

  const handleKeyPress = useCallback(
    ({ keyCode }) =&amp;gt; keyCode === 27 &amp;amp;&amp;amp; onClose(),
    [onClose]
  );

  useEffect(() =&amp;gt; {
    let target = modalRef &amp;amp;&amp;amp; modalRef.current;
    if (target) {
      target.addEventListener("click", onClose);
      target.addEventListener("keydown", handleKeyPress);
    }

    return () =&amp;gt; {
      if (target) {
        target.removeEventListener("click", onClose);
        target.removeEventListener("keydown", handleKeyPress);
      }
    };
  }, [modalRef, onClose, handleKeyPress]);

  return (
    open &amp;amp;&amp;amp; (
      &amp;lt;div className="modal-overlay" ref={modalRef}&amp;gt;
        &amp;lt;div className="modal-content"&amp;gt;{children}&amp;lt;/div&amp;gt;
        &amp;lt;button className="close-btn" onClick={onClose}&amp;gt;
          Close
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
    )
  );
};

export default Modal;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;We make sure to attach &lt;code&gt;tabIndex="0"&lt;/code&gt; property on the container and focus on it as we attach the listeners. These are the two important steps to make the Modal close by pressing &lt;code&gt;Èsc&lt;/code&gt; button.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useCallback, useEffect, useRef } from "react";

const Modal = ({ open, onClose, children }) =&amp;gt; {
  const modalRef = useRef(null);

  const handleKeyPress = useCallback(
    ({ keyCode }) =&amp;gt; keyCode === 27 &amp;amp;&amp;amp; onClose(),
    [onClose]
  );

  useEffect(() =&amp;gt; {
    let target = modalRef &amp;amp;&amp;amp; modalRef.current;
    if (target) {
      modalRef.current.focus(); // important
      target.addEventListener("click", onClose);
      target.addEventListener("keydown", handleKeyPress);
    }

    return () =&amp;gt; {
      if (target) {
        target.removeEventListener("click", onClose);
        target.removeEventListener("keydown", handleKeyPress);
      }
    };
  }, [modalRef, onClose, handleKeyPress]);

  // tabIndex on our div tag
  return (
    open &amp;amp;&amp;amp; (
      &amp;lt;div tabIndex="0" className="modal-overlay" ref={modalRef}&amp;gt;
        &amp;lt;div className="modal-content"&amp;gt;{children}&amp;lt;/div&amp;gt;
        &amp;lt;button className="close-btn" onClick={onClose}&amp;gt;
          Close
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
    )
  );
};

export default Modal;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://codesandbox.io/s/react-fc-modal-8qqbv"&gt;Click here to see the Full Demo&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>hooks</category>
      <category>modal</category>
    </item>
    <item>
      <title>Fine Tuning Resnet34 for a 2 class, classification</title>
      <dc:creator>Rishi Raj</dc:creator>
      <pubDate>Fri, 17 Apr 2020 08:34:37 +0000</pubDate>
      <link>https://dev.to/rishiraj824/finetuning-resnet34-for-a-2-class-classification-455i</link>
      <guid>https://dev.to/rishiraj824/finetuning-resnet34-for-a-2-class-classification-455i</guid>
      <description>&lt;p&gt;This python demo notebook shows how to fine-tune a 1000 class output network to a 2 class output network. The dataset I have consists of 60 data points, 30 for each class (dog and cat images), and 24 data points for validation dataset, 12 for each class.&lt;/p&gt;

&lt;p&gt;Python Notebook -&lt;br&gt;
&lt;a href="https://github.com/rishiraj824/MachineLearningAlgorithms/blob/master/resnet/resnet34-finetuning.ipynb"&gt;https://github.com/rishiraj824/MachineLearningAlgorithms/blob/master/resnet/resnet34-finetuning.ipynb&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dataset - &lt;br&gt;
&lt;a href="https://github.com/rishiraj824/MachineLearningAlgorithms/tree/master/resnet/data"&gt;https://github.com/rishiraj824/MachineLearningAlgorithms/tree/master/resnet/data&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Basic requirements for training a large network like &lt;code&gt;resnet&lt;/code&gt; is that you have to choose a valid loss function and an optimizer. For this example, I have chosen a Cross-Entropy Loss which is minimized by my model. This is useful as it already comes with a &lt;code&gt;Softmax layer&lt;/code&gt; in it, in the &lt;code&gt;pytorch&lt;/code&gt; library.&lt;/p&gt;

&lt;p&gt;I am using the &lt;code&gt;SGD (Stochastic Gradient Algorithm)&lt;/code&gt; to solve for the minimization and to optimize the model. And then at the end of the trained model, I add a Linear layer which changes the feature sets to 2 classes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;num_ftrs = model_conv.fc.in_features
model_conv.fc = nn.Linear(num_ftrs, 2)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Observations:
&lt;/h3&gt;

&lt;p&gt;Plotting the Training Loss and the Validation Loss with the iteration shows us how quickly it converged. This was bound to happen as this is a large network and the dataset we used was very small. But since our main objective was to fine-tune the network we were able to achieve that. This code would work for any number of data size. I hope this helped to get a brief idea of how fine-tuning works.&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>resnet</category>
      <category>classification</category>
    </item>
    <item>
      <title>Scheduling Algorithm</title>
      <dc:creator>Rishi Raj</dc:creator>
      <pubDate>Wed, 15 Apr 2020 01:22:05 +0000</pubDate>
      <link>https://dev.to/rishiraj824/scheduling-algorithm-4cnn</link>
      <guid>https://dev.to/rishiraj824/scheduling-algorithm-4cnn</guid>
      <description>&lt;p&gt;This Python Notebook (&lt;a href="https://github.com/rishiraj824/scheduling/blob/master/scheduling.ipynb"&gt;https://github.com/rishiraj824/scheduling/blob/master/scheduling.ipynb&lt;/a&gt;) demonstrates the scheduling algorithm for a list of activities provided through a CSV. It uses the dynamic programming approach to solve for the most compatible activities.&lt;/p&gt;

&lt;p&gt;The above solution works for any given activity board as it takes into account the maximum earnings from those activities.&lt;/p&gt;

&lt;p&gt;Step 1.&lt;br&gt;
We first sort all our activities based on their finish times and compare the activities one by one to find the next compatible activity because activities cannot overlap each other.&lt;/p&gt;

&lt;p&gt;Step 2.&lt;br&gt;
We use a binary search to find the most compatible activity. This takes us O(lg n) time.&lt;/p&gt;

&lt;p&gt;Step 3.&lt;br&gt;
We do this n times and while we do this we save the activity names to output all the possible activities in the end.&lt;/p&gt;

&lt;p&gt;Step 4.&lt;br&gt;
Keep adding the reward of all the compatible, highest rewards and display the sum in the end.&lt;/p&gt;

</description>
      <category>scheduling</category>
      <category>dynamic</category>
      <category>programming</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Getting my hands dirty on Machine Learning Algorithms</title>
      <dc:creator>Rishi Raj</dc:creator>
      <pubDate>Sun, 05 Apr 2020 17:22:23 +0000</pubDate>
      <link>https://dev.to/rishiraj824/getting-my-hands-dirty-on-machine-learning-algorithms-3n53</link>
      <guid>https://dev.to/rishiraj824/getting-my-hands-dirty-on-machine-learning-algorithms-3n53</guid>
      <description>&lt;p&gt;Today I'm sharing how I implemented Perceptron and the major reasons why it doesn't work for XOR type classification problems. Check out this notebook for details.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/rishiraj824/MachineLearningAlgorithms/blob/master/perceptron/perceptron.ipynb"&gt;https://github.com/rishiraj824/MachineLearningAlgorithms/blob/master/perceptron/perceptron.ipynb&lt;/a&gt;&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>perceptron</category>
      <category>classification</category>
    </item>
    <item>
      <title>It's okay to say "Yes"</title>
      <dc:creator>Rishi Raj</dc:creator>
      <pubDate>Sun, 05 Jan 2020 21:58:19 +0000</pubDate>
      <link>https://dev.to/rishiraj824/it-s-okay-to-say-yes-3336</link>
      <guid>https://dev.to/rishiraj824/it-s-okay-to-say-yes-3336</guid>
      <description>&lt;p&gt;I would never have come to believe it was true, but going forward I realized you do not need to know everything from before. Some things are just meant to be figured out and it's okay to say “Yes” even if you do not know everything about how it will be done.&lt;/p&gt;

&lt;p&gt;While I was in college I used to freelance a lot and do a lot of projects. Trust me, most of the projects I said yes to were something I never had heard of before. That has helped me in learning so much that I wouldn’t have, had I not said yes.  Sometimes it’s just about taking that extra step.&lt;/p&gt;

&lt;p&gt;In a hindsight, I came to believe and even now that there is a difference between what you can do and what you are not familiar with but can do it if you do your homework. &lt;/p&gt;

&lt;p&gt;As a developer, if you wait for an opportunity to adapt to your expectations, you will never test your boundaries.&lt;/p&gt;

&lt;p&gt;There might be a case you might not be able to deliver it completely but I’m sure that is better than not attempting it at first.&lt;/p&gt;

</description>
      <category>motivation</category>
      <category>risk</category>
      <category>development</category>
    </item>
  </channel>
</rss>
