<?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: Daniel</title>
    <description>The latest articles on DEV Community by Daniel (@jerec).</description>
    <link>https://dev.to/jerec</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%2F915016%2Fc08284ed-0267-4a95-8008-385317a0aeeb.png</url>
      <title>DEV Community: Daniel</title>
      <link>https://dev.to/jerec</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jerec"/>
    <language>en</language>
    <item>
      <title>AWS DeepRacer Student League Guide</title>
      <dc:creator>Daniel</dc:creator>
      <pubDate>Wed, 07 Feb 2024 14:30:47 +0000</pubDate>
      <link>https://dev.to/jerec/aws-deepracer-student-league-guide-2l38</link>
      <guid>https://dev.to/jerec/aws-deepracer-student-league-guide-2l38</guid>
      <description>&lt;p&gt;I've already written a &lt;a href="https://dev.to/jerec/comprehensive-starter-guide-to-aws-deepracer-1o9b"&gt;starter guide&lt;/a&gt; for AWS DeepRacer, that can be used both for Regular League and Student League that outlines some valuable information for getting started, but in this guide I will outline in detail the default configuration for Student League. I recommended you read the starter guide to learn about DeepRacer for Cloud.&lt;/p&gt;

&lt;h3&gt;
  
  
  Who is it for?
&lt;/h3&gt;

&lt;p&gt;Any Student 16+ doesn't matter if high school, home school, or university. there are generally scholarship prizes and the season is typically paired with a Udacity Scholarship for various Nano Degrees. &lt;/p&gt;

&lt;h3&gt;
  
  
  Log Analysis
&lt;/h3&gt;

&lt;p&gt;Currently, there isn't a way for the student league to do any log analysis, the only package they can download from the console is the car package to load the model into the car. None of these files give valuable insight into the training performance.&lt;/p&gt;

&lt;h4&gt;
  
  
  Ways to Analyze the Performance
&lt;/h4&gt;

&lt;p&gt;Ideally, since you don't have log analysis and a limited number of hours to train on the Student League console. You can do some mock testing with sample data sets and pass the value to your reward function within Excel. The only feasible way to robustly test your reward function would be to use DeepRacer for Cloud on your hardware. This way you can save your 10 hours until you are ready to use them to get the best performance possible. I'll outline the default that applies to both AWS Console and DRfC&lt;/p&gt;

&lt;h3&gt;
  
  
  Action Space
&lt;/h3&gt;

&lt;p&gt;Student League has no control over the action space within the console. They are strictly defined as a Continuous action space, With a min and max speed of 0.5 to 1, and a steering angle of -30 to 30.  &lt;/p&gt;

&lt;p&gt;In DRfC(see &lt;a href="https://dev.to/jerec/comprehensive-starter-guide-to-aws-deepracer-1o9b"&gt;starter guide&lt;/a&gt;) this is defined as a JSON document like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;action_space&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;speed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;high&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;low&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;steering_angle&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;high&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;low&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;}},&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;sensor&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;FRONT_FACING_CAMERA&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;neural_network&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;DEEP_CONVOLUTIONAL_NETWORK_SHALLOW&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;training_algorithm&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;clipped_ppo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;action_space_type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;continuous&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;version&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;5&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💡it is important to note that the speed that gets passed to the reward function will never exceed your max speed in the action space. a lot of people get confused by this partly because the video has an error output of speed. I believe this is caused by Python's Global Interpreter Lock due to the nature of how the data is called causing timing issues. while the math behind it is sound there is something fundamentally throwing off the output. Which I believe it to be caused by GIL&lt;/p&gt;

&lt;h3&gt;
  
  
  Hyperparameters
&lt;/h3&gt;

&lt;p&gt;Again, this is another item Student League has no control over, because of this no control it adds another layer of difficulty due to the discount factor being 0.999 meaning the reinforcement learning is looking at the whole lap to calculate the future reward to make a decision and not just a little bit ahead. this is also defined by a JSON document within DRfC. These are the default student league is stuck with while training.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;batch_size&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;beta_entropy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.01&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;discount_factor&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.999&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;e_greedy_value&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.05&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;epsilon_steps&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;exploration_type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;categorical&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;loss_type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;huber&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;lr&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.0003&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;num_episodes_between_training&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;num_epochs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stack_size&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;term_cond_avg_score&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;350.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;term_cond_max_episodes&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;sac_alpha&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Reward Function
&lt;/h3&gt;

&lt;p&gt;as I said in my starter guide, there are many different parameters you can pick from and some are for object avoidance. Which isn't needed for the time trial races. Again See my &lt;a href="https://dev.to/jerec/comprehensive-starter-guide-to-aws-deepracer-1o9b"&gt;starter guide&lt;/a&gt; for additional Details on your reward function. Instead Going to outline some issues I've seen from other Racers.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Min and Max Reward Cannot exceed 10k. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If it does this will either cause a validation error or cause training to stop.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Import reporting module not available&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;DeepRacer doesn't use the latest Numpy so this generally reports as a syntax error. if you attempt to import/use a module that doesn't exist in that version of numpy. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;logic errors + syntax errors &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;the validator only passes in a small sample set of data. Your carefully crafted reward function might not throw a validation error, but later cause your training to stop. this is generally because the sample set never fully triggered your reward function. Logic errors could also cause unexpected behavior. Always test your reward function with sample parameters to see if you get the expected reward.&lt;/p&gt;

&lt;p&gt;Additionally, to avoid some of these errors it is best practice to initialize your variables before you get to any logic statements. this will avoid edge cases where you call a variable without any assignment.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;expecting speed to exceed max speed of action space&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I've said it above, and I'll say it again because I've had to explain this several times to some people before it finally clicks. Speed will never exceed the maximum speed you have set in your action space.&lt;/p&gt;

&lt;h3&gt;
  
  
  Udacity Scholarship
&lt;/h3&gt;

&lt;p&gt;Generally, there are a few steps to do for the Udacity Scholarship, one is completing a lap under X number of minutes. you'll be submitting to the virtual circuit track to achieve this requirement. Which should be found on the left-hand side of the navigation panel. This step can be difficult to achieve depending on the length of the track.&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>deepracer</category>
      <category>learning</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Comprehensive starter guide to AWS DeepRacer</title>
      <dc:creator>Daniel</dc:creator>
      <pubDate>Thu, 01 Feb 2024 19:13:50 +0000</pubDate>
      <link>https://dev.to/jerec/comprehensive-starter-guide-to-aws-deepracer-1o9b</link>
      <guid>https://dev.to/jerec/comprehensive-starter-guide-to-aws-deepracer-1o9b</guid>
      <description>&lt;h1&gt;
  
  
  Comprehensive starter guide to AWS DeepRacer
&lt;/h1&gt;

&lt;h3&gt;
  
  
  What is AWS DeepRacer?
&lt;/h3&gt;

&lt;p&gt;AWS DeepRacer is the fastest way to get started with machine learning and understanding the basics of coding. It doesn’t matter the current career path or age. The only thing that matters is your will to learn. What is AWS DeepRacer? AWS DeepRacer is a 1/18th scale RC autonomous racing league. These cars are 100% self-driving and use reinforcement learning to train themselves to get around the track. You are the developer who only provides minimal input. &lt;/p&gt;

&lt;p&gt;Normally machine learning is very complex and takes time to build, but AWS neatly packages the experience into a user-friendly experience. We’ll delve into the 3 sections a developer has control of here shortly which are Hyperparameters, Action space, and reward function parameters but as I said this is a comprehensive guide.&lt;/p&gt;

&lt;p&gt;I’ll be referring to AWS console and DeepRacer for Cloud for short I'll use DRfC.  AWS console refers to training directly on AWS-provided infrastructure, but since AWS DeepRacer is open source. a group of us decided to take what AWS provided and package it into a system known as DRfC, this not only unlocks some additional features but allows you to train on your own platform.&lt;/p&gt;

&lt;h3&gt;
  
  
  Physical Racing vs Virtual Racing
&lt;/h3&gt;

&lt;p&gt;Virtual and Physical are two completely different beasts and many racers struggle with the changes between the two. In Virtual Racing the track we train on is usually the same as the one we submit the model to. We can get away with high speeds in action space and overfitting&lt;/p&gt;

&lt;p&gt;Physical racing, however, is very sensitive to high speed and overfitting. High-speed results in having to put a higher throttle in the car which can be seen as the vehicle stalling out on the track, or just not wanting to move without some assistance. a well-generalized model performs better in the real world. &lt;/p&gt;

&lt;p&gt;Two misconceptions during actual racing are two things, the car is no longer learning. it is now exploiting the knowledge it has collected in the model. Second, the reward function has no role in the decision-making process. The only input the car relies on is from the camera, and using that with the sum of its experience to make a probability choice based on weights. a learning model has weights of a matrix embedded in a machine learning model. &lt;/p&gt;

&lt;h3&gt;
  
  
  DeepRacer League vs DeepRacer Student League
&lt;/h3&gt;

&lt;p&gt;The Student League is a reduced-down AWS console to allow a younger generation to learn machine learning at an early age. They usually pair the season with a chance of an AI Scholarship with Udacity plus the usual prizes. You can still use a model in Student League on a physical car and be competitive. This is reserved for people 16+. Since there are limitations within the Student League I will note if a feature isn’t available.&lt;/p&gt;

&lt;p&gt;DeepRacer League is the adult version without the training wheels. You have full control of all the features available to you, and prizes for performing well during the season. Which can end with a trip to AWS Reinvent. Restrictions are 18+&lt;/p&gt;

&lt;h3&gt;
  
  
  Policies
&lt;/h3&gt;

&lt;p&gt;I’m only going to talk about policies at a high level, but just like you don’t talk about fight club. We don’t talk about SAC. While SAC is an option available with policies it is very sensitive to hyperparameters, and this has caused no one in the DeepRacer league to be successful with it. (as far as we know).&lt;/p&gt;

&lt;p&gt;It is best to keep to PPO policy especially when starting your journey.&lt;/p&gt;

&lt;h3&gt;
  
  
  Convergence
&lt;/h3&gt;

&lt;p&gt;Convergence is the ultimate goal for any ML engineer to achieve while training their model. This is the point that the car is no longer exploring its environment but instead exploiting in knowledge to get around the environment. When looking at charts to see if you are converging this is usually when training lap completion and evaluation lap completion meet. If these aren’t meeting you might need to try adjusting your hyperparameters. Hyperparameters tend to cause one of two outcomes which are constantly fighting each other, learning stability vs convergence. If hyperparameters aren’t set right the model might not be learning enough to reach convergence or might take a long time to reach convergence. &lt;/p&gt;

&lt;p&gt;Another method for seeing if a car is converging, which is easier to see within DRfC is watching entropy. Entropy simply is how much uncertainty is left in the system. If the model is moving in the right direction this will decrease over time and if it isn’t you’ll see it increase. You can see this in the AWS console once you download the logs, but with DRfC we can watch it live. Entropy will be near 1 when the car starts doing laps and as low as 0.2-0.4 for a well-balanced function.&lt;/p&gt;

&lt;h3&gt;
  
  
  Log Analyze
&lt;/h3&gt;

&lt;p&gt;Before I get into Hyperparameters that affect convergence, let's talk about how to visibly see convergence within the environment.&lt;/p&gt;

&lt;p&gt;Log analysis is going to be key to being successful to understand how your model is performing where you can make improvements and if the reward function is favoring the ultimate goal. The ultimate goal is to get the most points possible. I’ll go into a little more detail on this later.&lt;/p&gt;

&lt;p&gt;AWS DeepRacer community provides several tools for you to analyze your model and all you need are the training logs. I’m not going into depth on how to do this but the repo for the main tool I use can be found here. &lt;a href="https://github.com/aws-deepracer-community/deepracer-analysis"&gt;https://github.com/aws-deepracer-community/deepracer-analysis&lt;/a&gt; there are several others available including the one made by JPMC known are log guru. I’ll be looking at writing a more in-depth guide to deepracer-analysis in the coming months. &lt;/p&gt;

&lt;p&gt;The student league can’t do log analysis because they can’t download the log. they could in theory analyze the reward in one of two ways, create a sample run and pass in the reward function to see the outcomes.&lt;/p&gt;

&lt;p&gt;Second, would be to set up DRfC to test the reward function before burning the 10 hours. due to speed differences in hardware, you’ll need to estimate the AWS console with DRfC by looking at the number of iterations and matching closely to get the expected performance. &lt;/p&gt;

&lt;h3&gt;
  
  
  Hyperparameters
&lt;/h3&gt;

&lt;p&gt;💡Not Available in Student League&lt;/p&gt;

&lt;p&gt;Hyperparameters are settings that affect the training performance of the model.  Sometimes these items need to be tweaked to make what might seem like a bad reward function into a good one. Generally, starting you should leave these at default except for the discount factor I would suggest setting that to 0.99&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table id="e00dcdfe-1ffd-4c1f-b80c-e622460f780c"&gt;
&lt;thead&gt;&lt;tr id="4eb0b08e-1d0e-4d6e-a868-8c05ca6b16fd"&gt;
&lt;th id="=kX?"&gt;Hyperparameters&lt;/th&gt;
&lt;th id="D]?s"&gt;Description&lt;/th&gt;
&lt;th id="Xc@M"&gt;Platform Availability&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr id="d748a687-b82e-4a33-a31d-d2abd6f5b06f"&gt;
&lt;th id="=kX?"&gt;Batch Size&lt;/th&gt;
&lt;td id="D]?s"&gt;the number of experiences that will be sampled at random used to update the model&lt;br&gt;&lt;br&gt;reducing can promote a more stable policy&lt;br&gt;
&lt;/td&gt;
&lt;td id="Xc@M"&gt;both&lt;/td&gt;
&lt;/tr&gt;
&lt;tr id="dbdd8448-2d17-42a7-9d53-22d2e19cffdd"&gt;
&lt;th id="=kX?"&gt;Beta Entropy&lt;/th&gt;
&lt;td id="D]?s"&gt;it is a value of uncertainty that is added to the policy. The lower the number the less uncertain. Increasing this will promote exploration over exploitation at the cost of convergence.&lt;/td&gt;
&lt;td id="Xc@M"&gt;both&lt;/td&gt;
&lt;/tr&gt;
&lt;tr id="2237bf2f-5d8b-4ffa-8998-4527ff16ea08"&gt;
&lt;th id="=kX?"&gt;Epochs&lt;/th&gt;
&lt;td id="D]?s"&gt;The number of iterations through the training data to update the model. &lt;br&gt;&lt;br&gt;this can also affect learning, the trade-off is lower value higher stability at the cost of convergence&lt;br&gt;
&lt;/td&gt;
&lt;td id="Xc@M"&gt;both&lt;/td&gt;
&lt;/tr&gt;
&lt;tr id="ba8b2a99-85b6-43e1-bccb-50ba0c528f60"&gt;
&lt;th id="=kX?"&gt;Learning Rate&lt;/th&gt;
&lt;td id="D]?s"&gt;Control how much Gradient descent updates the weights.&lt;br&gt;&lt;br&gt;decreasing can increase stability but at the cost of time.&lt;br&gt;
&lt;/td&gt;
&lt;td id="Xc@M"&gt;both&lt;/td&gt;
&lt;/tr&gt;
&lt;tr id="1f3653cf-e917-4477-9937-51512f251404"&gt;
&lt;th id="=kX?"&gt;Discount factor&lt;/th&gt;
&lt;td id="D]?s"&gt;How far in the future the car looks ahead to calculate the possible rewards it collects. &lt;br&gt;&lt;br&gt;If the environment is noisy decreasing this will help stability to focus on more short-term reward. More later&lt;br&gt;
&lt;/td&gt;
&lt;td id="Xc@M"&gt;Both&lt;/td&gt;
&lt;/tr&gt;
&lt;tr id="99f50977-f641-4f72-81ef-fbd2831e18c8"&gt;
&lt;th id="=kX?"&gt;Exploration Type&lt;/th&gt;
&lt;td id="D]?s"&gt;Two choices Categorical which is default, and e-greedy. &lt;br&gt;&lt;br&gt;With epsilon-greedy, you choose a value for ε (epsilon), typically between 0 and 1. The agent will explore (choose a random action) with probability ε and exploit (choose the best-known action) with probability (1 - ε). DRfC only&lt;br&gt;&lt;br&gt;In categorical exploration, you model the exploration as a probability distribution over actions. Instead of having a single ε value, you define a probability distribution over actions, where each action has a probability associated with it. This distribution can be learned and updated as the agent interacts with the environment. AWS Console and DRfC&lt;br&gt;
&lt;/td&gt;
&lt;td id="Xc@M"&gt;DRfC&lt;/td&gt;
&lt;/tr&gt;
&lt;tr id="6acabed2-0118-4d73-aa34-cddec12b3d51"&gt;
&lt;th id="=kX?"&gt;e greedy&lt;/th&gt;
&lt;td id="D]?s"&gt;Promotes the difference between exploration and exploration when using e-greedy exploration type&lt;/td&gt;
&lt;td id="Xc@M"&gt;DRfC&lt;/td&gt;
&lt;/tr&gt;
&lt;tr id="3a8029ee-b1af-48d9-9a5d-311da369c55a"&gt;
&lt;th id="=kX?"&gt;&lt;strong&gt;epsilon steps&lt;/strong&gt;&lt;/th&gt;
&lt;td id="D]?s"&gt;(Unconfirmed) I believe this is part of the PPO Clipping that controls how much a policy can deviate once a certain number of steps is hit during training. Higher promotes more exploration&lt;/td&gt;
&lt;td id="Xc@M"&gt;DRfC&lt;/td&gt;
&lt;/tr&gt;
&lt;tr id="0b7ee5ff-759a-4bfc-b5a4-41915545f230"&gt;
&lt;th id="=kX?"&gt;Loss type&lt;/th&gt;
&lt;td id="D]?s"&gt;the objective function used to update the network’s weights. &lt;br&gt;&lt;br&gt;values Huber, and Mean squared error&lt;br&gt;
&lt;/td&gt;
&lt;td id="Xc@M"&gt;Both&lt;/td&gt;
&lt;/tr&gt;
&lt;tr id="66397ffc-98fb-4ea5-ad8b-8aefd805289e"&gt;
&lt;th id="=kX?"&gt;Number of Episodes&lt;/th&gt;
&lt;td id="D]?s"&gt;The number of sessions used to collect data before the policy update.&lt;br&gt;&lt;br&gt;For more complex problems increasing can lead to a stable model&lt;br&gt;
&lt;/td&gt;
&lt;td id="Xc@M"&gt;Both&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Action Space
&lt;/h3&gt;

&lt;p&gt;💡Not Available in Student League. Student League is fixed at a continuous action space between 0.5 to 1 speed, -30 to 30 steering&lt;/p&gt;

&lt;p&gt;As a Developer, you will think about how you want your vehicle to behave crafting a reward function to achieve the desired results. Similar to how you would train an animal if you wanted it to perform a trick by giving it treats every time it performs a desired action or actions. Currently, there are two different choices available. &lt;/p&gt;

&lt;p&gt;Discrete is a list of consistent speeds paired with a steering angle, and DeepRacer will select from this list.  How it selects from this list is affected by the exploration type. Which can only be changed in DRfC&lt;/p&gt;

&lt;p&gt;Continuous you only set your min and max steering angle and speed. The car will select a random float between those values so during training the car may never select the same value twice.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reward Function Parameters
&lt;/h3&gt;

&lt;p&gt;Parameters are all the different values that get passed into the reward function during training, this happens every 1/15th of a second, and actions picked during that time are passed to the reward function to calculate the reward. There is a wide range of parameters, and some are only used if you are doing object avoidance. You’ll need to think carefully about which values suit your end goals to weave into your reward function. incidentally that 1/15th a second is always what is called a step in the parameters.&lt;/p&gt;

&lt;p&gt;🏎️ Note: speed is a hard value based on the action space. it is best to think of speed as throttle and not the actual velocity of the car’s current state.&lt;/p&gt;

&lt;p&gt;A comprehensive list can be found here: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/deepracer/latest/developerguide/deepracer-reward-function-input.html"&gt;Input parameters of the AWS DeepRacer reward function - AWS DeepRacer&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Reward Function
&lt;/h3&gt;

&lt;p&gt;Crafting a reward function can get pretty overwhelming with all the parameters you have available. Typically, people take one of two approaches when they first get started they either do reward = speed in hopes to generate a fast model, or they make the reward function overly complex. Complexity is fine if it uses only a few parameters. Some of my best models have used up to 2 parameters at most.&lt;/p&gt;

&lt;p&gt;Use reward shaping where you can in your reward function. What is reward shaping? it where you still give a reward even if it is small if the action is off what you desire. For Example below is the AWS-provided Center line function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;reward_function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="dl"&gt;'''&lt;/span&gt;&lt;span class="s1"&gt;
    Example of rewarding the agent to follow center line
    &lt;/span&gt;&lt;span class="dl"&gt;'''&lt;/span&gt;

    &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;Read&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="nx"&gt;parameters&lt;/span&gt;
    &lt;span class="nx"&gt;track_width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;track_width&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="nx"&gt;distance_from_center&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;distance_from_center&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;Calculate&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="nx"&gt;markers&lt;/span&gt; &lt;span class="nx"&gt;that&lt;/span&gt; &lt;span class="nx"&gt;are&lt;/span&gt; &lt;span class="nx"&gt;increasingly&lt;/span&gt; &lt;span class="nx"&gt;further&lt;/span&gt; &lt;span class="nx"&gt;away&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;center&lt;/span&gt; &lt;span class="nx"&gt;line&lt;/span&gt;
    &lt;span class="nx"&gt;marker_1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;track_width&lt;/span&gt;
    &lt;span class="nx"&gt;marker_2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.25&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;track_width&lt;/span&gt;
    &lt;span class="nx"&gt;marker_3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;track_width&lt;/span&gt;

    &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;Give&lt;/span&gt; &lt;span class="nx"&gt;higher&lt;/span&gt; &lt;span class="nx"&gt;reward&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;car&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;closer&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;center&lt;/span&gt; &lt;span class="nx"&gt;line&lt;/span&gt; &lt;span class="nx"&gt;and&lt;/span&gt; &lt;span class="nx"&gt;vice&lt;/span&gt; &lt;span class="nx"&gt;versa&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nx"&gt;distance_from_center&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;marker_1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nx"&gt;reward&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="nx"&gt;elif&lt;/span&gt; &lt;span class="nx"&gt;distance_from_center&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;marker_2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nx"&gt;reward&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;
    &lt;span class="nx"&gt;elif&lt;/span&gt; &lt;span class="nx"&gt;distance_from_center&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;marker_3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nx"&gt;reward&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.1&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nx"&gt;reward&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;  &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;likely&lt;/span&gt; &lt;span class="nx"&gt;crashed&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;close&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;off&lt;/span&gt; &lt;span class="nx"&gt;track&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;reward&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This reward shaping in mind this center line function can be simplified to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;reward_function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="dl"&gt;'''&lt;/span&gt;&lt;span class="s1"&gt;
    Example of rewarding the agent to follow center line
    &lt;/span&gt;&lt;span class="dl"&gt;'''&lt;/span&gt;

    &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;Read&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="nx"&gt;parameters&lt;/span&gt;
    &lt;span class="nx"&gt;distance_from_center&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;distance_from_center&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="nx"&gt;reward&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;distance_from_center&lt;/span&gt;



    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;reward&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with this simplification, the car has some freedom to deviate from the center line and still receive a decent reward, but the further away it gets the lower the reward.&lt;/p&gt;

&lt;p&gt;Now, we talked about simplifying and reward shaping. So let's talk about the elephant in the room using reward = speed or even reward = speed + other parameters is just plain bad for you.&lt;/p&gt;

&lt;p&gt;Earlier I said 1 step is 1/15th of a second this value is key for the concept I’m about to show you. Firstly, you need to understand the car’s ultimate goal is to get the highest value reward possible. Meaning if don’t do log analysis on your reward function it might learn bad behavior due to this ultimate goal. Let's take a car that has two speed values of 0.5 m/s and 1 m/s on a 30-meter track.&lt;/p&gt;

&lt;p&gt;💡 This is an oversimplification of the whole process but this allows you to understand why things can happen when you do not expect&lt;/p&gt;

&lt;p&gt;We’ll assume constant speed for these two scenarios&lt;/p&gt;

&lt;p&gt;30 meters * 1 m/s = 30 seconds&lt;/p&gt;

&lt;p&gt;30 meters * 0.5 m/s = 60 seconds&lt;/p&gt;

&lt;p&gt;Now we know the time it would take for each speed to get around the track, but now we need to account for the number of steps in one second which is 15.&lt;/p&gt;

&lt;p&gt;30 second * 15 = 450 steps&lt;/p&gt;

&lt;p&gt;60 seconds * 15 = 900 steps&lt;/p&gt;

&lt;p&gt;Now we need to times the value by speed because that was what the reward was reward = speed.&lt;/p&gt;

&lt;p&gt;450 steps * 1 reward = 450 points&lt;/p&gt;

&lt;p&gt;900 steps * 0.5 reward = 450 points&lt;/p&gt;

&lt;p&gt;So now you see if you just use the speed parameter you end up with the same number of points, which in a real scenario might end up with a car speeding up or slowing down, or just settling on a slow speed if you pair it with another parameter. For example, speed + distance from the center line if the value of the distance from the center line is always 1, you just made the new formula steps * speed reward + steps * distance reward. You’ve quickly just ruined your speed. &lt;/p&gt;

&lt;p&gt;There is also another issue that can occur during training which is snaking, or zig-zagging.  this is typically because the car has learned it can get a higher reward for maximizing its time. If you aren’t in the student league you can generally fix some of these issues by adjusting the discount factor. discount factor can make a seemingly bad reward a better one by limiting the number of steps it looks at in the future to make the decisions.&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>deepracer</category>
      <category>learning</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Build your own AI Image Generation</title>
      <dc:creator>Daniel</dc:creator>
      <pubDate>Thu, 25 Aug 2022 16:16:00 +0000</pubDate>
      <link>https://dev.to/jerec/build-your-own-ai-image-generation-54a</link>
      <guid>https://dev.to/jerec/build-your-own-ai-image-generation-54a</guid>
      <description>&lt;h2&gt;
  
  
  Impact
&lt;/h2&gt;

&lt;p&gt;The latest trend on the internet is easy access to Image generators like midjourney, Dall-e 2 or stable diffusion. We a few of these behind paywalls. I'll show you with a few lines of code you can get started on using your own on in AWS Sagemaker Notebook instance!&lt;/p&gt;

&lt;p&gt;Thanks to public release by stable diffusion, you can download and run the ai model generating the images and sometimes the results can be horrifying, and other times just elegant. The examples provided below where simply "realistic pikachu", and "old man with a hat". Results will be different each time the prompt is ran!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F98nf8sxz7x8grju8k6h3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F98nf8sxz7x8grju8k6h3.png" alt="AI Generated Image with prompt realistic Pikachu"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi7fedxlrrqdmqy322or7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi7fedxlrrqdmqy322or7.png" alt="AI Generated Image with old man with a hat"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;it is hard to believe this person isn't real. However, do these image generations have other practical application other than art work? Of course, they'll have an impact to come in design industry with a few simple prompts someone can get a new inspiring design such a piece of furniture! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fao352dw1vfru9iweqtnl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fao352dw1vfru9iweqtnl.png" alt="Generated with prompt modern desk"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  prerequisite
&lt;/h2&gt;

&lt;p&gt;1.Sign up for an account on &lt;a href="https://huggingface.co/CompVis/stable-diffusion-v1-4" rel="noopener noreferrer"&gt;Huggingface&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Accept Terms of Services.&lt;/li&gt;
&lt;li&gt; Generate &lt;a href="https://huggingface.co/settings/tokens" rel="noopener noreferrer"&gt;token&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Launching the notebook
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;WARNING&lt;/strong&gt;: Sagemaker Notebook costs money to run! Make sure you clean up the instance as soon as you are done in order to avoid costs! Proceed at your own risk!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Login to AWS Console.&lt;/li&gt;
&lt;li&gt;Search for Amazon Sagemaker, and select it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo5kmp97ggc8jyqifo877.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo5kmp97ggc8jyqifo877.PNG" alt="Amazon Sagemaker"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click on Notebook Instance from left hand menu&lt;/li&gt;
&lt;li&gt;Click Create Instance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr8pknj3bohu7jdt8jr7e.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr8pknj3bohu7jdt8jr7e.PNG" alt="Create Instance"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select a Name from the Instance. Instant type MUSt be Accelerated computing instance! Select ml.p2.xlarge or better&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhoudc9g0v9xn8sfw2p0r.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhoudc9g0v9xn8sfw2p0r.PNG" alt="Instance settings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Permissions and encryption leave default&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open Up network settings. Set it into the default VPC. it will need internet access. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faj4bggf688xf1y33zdzh.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faj4bggf688xf1y33zdzh.PNG" alt="Network Settings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select Launch Instance!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Configuring the notebook
&lt;/h2&gt;

&lt;p&gt;If you've followed along so far, it will take a bit for the instance to get prepared. However, we need to do some changes to the instance and add some packages. We'll modify an existing environment variable.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Once instance is ready. Select Open Jupyter Lab.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw6xcyumeq3kcbrm4uck6.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw6xcyumeq3kcbrm4uck6.PNG" alt="Open Jupyter lab"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Select Terminal&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Activate the Conda Environment&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source /home/ec2-user/anaconda3/etc/profile.d/conda.sh
conda activate pytorch_38
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Install required packages for this to work.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install diffusers==0.2.3 transformers scipy
pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Configure huggingface-cli login
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;huggingface-cli login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this will prompt you for the &lt;a href="https://huggingface.co/settings/tokens" rel="noopener noreferrer"&gt;token&lt;/a&gt; from earlier&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output if successful&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Login successful&lt;br&gt;
Your token has been saved to /home/ec2-user/.huggingface/token&lt;br&gt;
Authenticated through git-credential store but this isn't the helper defined on your machine.&lt;br&gt;
You might have to re-authenticate when pushing to the Hugging Face Hub. Run the following command in your terminal in case you want to set this credential helper as the default&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Code!
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We're done with the configuration! Select File -&amp;gt; New -&amp;gt; New Notebook.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Copy paste the following code into the cell&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from torch import autocast
from diffusers import StableDiffusionPipeline, LMSDiscreteScheduler


lms = LMSDiscreteScheduler(
    beta_start=0.00085, 
    beta_end=0.012, 
    beta_schedule="scaled_linear"
)

# this will substitute the default PNDM scheduler for K-LMS  
pipe = StableDiffusionPipeline.from_pretrained(
    "CompVis/stable-diffusion-v1-4", 
    scheduler=lms,
    use_auth_token=True
).to("cuda")

prompt = "a photo of an astronaut riding a horse on mars"
with autocast("cuda"):
    image = pipe(prompt)["sample"][0]  

image.save("astronaut_rides_horse.png")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Click Run! &lt;strong&gt;NOTE:&lt;/strong&gt; first run will take a bit as it downloads the AI model. Final output should be a beautiful photo and should look different than mine! &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foq6c1gxu9204j433frms.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foq6c1gxu9204j433frms.PNG" alt="Final Results"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  conclusion
&lt;/h2&gt;

&lt;p&gt;You can use this to generate many different type of images by editing the prompt and file name. the results will almost never be the same. this is just basic framework and much more complex system could be created to generate images based on a web request. Easily launched on an EC2 instance with a GPU attached to generate images and push to S3. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WARNING&lt;/strong&gt; DO NOT FORGET TO TERMINATE NOTEBOOK TO STOP CHARGES&lt;/p&gt;

&lt;h2&gt;
  
  
  Source:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/huggingface/diffusers/releases/tag/v0.2.3" rel="noopener noreferrer"&gt;HuggingFace&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>python</category>
      <category>machinelearning</category>
      <category>aws</category>
    </item>
  </channel>
</rss>
