<?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 Kai Brooks on Medium]]></title>
        <description><![CDATA[Stories by Kai Brooks on Medium]]></description>
        <link>https://medium.com/@kaibrooks?source=rss-ec5642db8e42------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*0a86xYvOBvzNH020iClVXA.jpeg</url>
            <title>Stories by Kai Brooks on Medium</title>
            <link>https://medium.com/@kaibrooks?source=rss-ec5642db8e42------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 17:44:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kaibrooks/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[How to write your engineering Requirements document (with 18 point template).]]></title>
            <link>https://kaibrooks.medium.com/how-to-write-your-engineering-requirements-document-with-18-point-template-91ff484eb38c?source=rss-ec5642db8e42------2</link>
            <guid isPermaLink="false">https://medium.com/p/91ff484eb38c</guid>
            <category><![CDATA[quality-assurance]]></category>
            <category><![CDATA[requirements-engineering]]></category>
            <category><![CDATA[engineering-mangement]]></category>
            <category><![CDATA[product-development]]></category>
            <dc:creator><![CDATA[Kai Brooks]]></dc:creator>
            <pubDate>Thu, 27 Jan 2022 21:54:16 GMT</pubDate>
            <atom:updated>2022-07-04T17:12:03.113Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6A7JV1s7GCELSRX9ziOWYQ.png" /><figcaption>Actual photo of the author searching for good requirements documents.</figcaption></figure><p>I’m an electrical engineer that has brought many products to market, serving as a design engineer, project manager, product owner, and “person on the stage with a big pitch deck behind them.” I think Excel holds back progress, and companies throw billions of dollars into the trash fire that is “someone making a worthless spreadsheet about a thing.” However, I still believe every serious project needs a requirements document.</p><p>If you’re just here for a template, it’s at the bottom, though I would be sure you understand the different sections before using it.</p><h3>Why are requirements documents even useful?</h3><p>First, a requirements document is simply “a detailed plan on what we want to build.” It’s the engineering equivalent of writing a business plan before throwing time and money into an idea.</p><ol><li>Everybody on the project has precisely the same vision before anyone starts working. You avoid meetings where a manager pipes in like, “wait, that’s not what I thought we agreed on building” a month into development.</li><li>Writing a structured requirements document makes you consider parts of the project that you wouldn’t have thought of otherwise (see the next point).</li><li>If your project has a critical fault, you will see it in the requirements so you can kill the project before you waste energy on a useless idea.</li><li>Requirements make your test plan dead simple to write.</li><li>You never have to remember some details that somebody said the project needed (Wait, did we actually decide on that, or were people just talking about it?). Just reference the requirements.</li></ol><p>I believe that requirements documents are “living” documents, such that they go through many iterations as a project advances. For example, you might specify a budget and then realize that it’s impossible to build as listed upon researching material for the project. Or, integration tests might reveal the need to change a communication protocol.</p><h4>What do you do if you don’t know if something is possible before you start prototyping?</h4><p>I run into this often. My method is to write a requirements document that considers, “What are the minimum viable elements of this project such that if we can’t meet them, we shouldn’t pursue the project?”</p><p>Here’s an example: When designing a (throttled) electric bicycle, how many miles does the vehicle need to travel on a single charge? Let’s say marketing and business research determines users need at least 20 miles — anything less, and users will hate it and the product doesn’t launch. Therefore, the requirement looks like this:</p><blockquote>“System shall travel a minimum of 20 miles on a single full charge when traveling on a flat road without user assistance.”</blockquote><p>We only addressed the <em>user need</em> (or business case) in this requirement. We didn’t talk about battery capacity, motor controllers, efficiency, power drain, or technical specifications. This language gives us the flexibility to develop a creative engineering solution.</p><p>Now that we have a target to aim for, we can determine various methods of accomplishing engineers’ requirements. Maybe we source a big battery, develop extra-efficient custom motor drivers, use tires with decreased rolling resistance, or other strategies. We could explore various options with the “20-mile range” to measure success.</p><h4>Why don’t we just specify technical criteria instead of user criteria?</h4><p>What if, instead of specifying user criteria, we established a technical criterion that was “effectively” the same, such as “The battery shall be 12Amp-hours”? While we may initially end up with the same 20-mile range, this limits us in many ways:</p><ol><li>We no longer have control over as many elements of the design process.</li><li>We might not reach a 20-mile range, which was the “actual” goal, depending on the other conditions.</li><li>As the project progresses, the battery capacity might not be as relevant in the future. If some future battery system was twice as efficient, we could use a smaller battery and have the same user experience.</li><li>We can lose sight of <em>why </em>we specified criteria in the first place. If we developed version 2.0 of this product five years later, would anyone remember why the battery was supposed to be 12 Amp-hours?</li></ol><h4>Requirements in conflict</h4><p>If two requirements are in conflict (suppose we <em>also</em> needed to make the product cost us less than $200 and we can’t source it), we simply come up with alternatives and present them to stakeholders (such as project managers or financiers). They either update the requirements with the newest information or decide that it’s no longer “business-feasible” to pursue the product and shelve it.</p><p>The requirements document is a “living document” and will go through many iterations as development continues.</p><h3>The three magic words</h3><p>All features or capabilities in your requirements use these three words, and these three words only: <strong>Shall</strong>, <strong>Should</strong>, and <strong>May</strong>. Add these definitions to your document.</p><p><strong>Shall — </strong>Denotes a <em>binding requirement</em>. In other words, a project is a success if it accomplishes all of its “shall” requirements. This term is the only one that’s an actual requirement; the others are all technically optional (though you might upset people if you ignore the rest of them). All “shall” requirements are <em>testable</em> with objective acceptance criteria.</p><p>Note: Don’t use “must” in technical requirements documents. Legal scholars and contract attorneys may disagree on terms, but “shall” is the standard binding term according to IEEE and ISO. “Shall” is also advantageous since most people don’t use it in daily speech, removing any accidental communication.</p><p><strong>Should — </strong>Denotes a <em>desired or preferential</em> outcome. Everyone on the project generally wants to accomplish all of the “should” requirements, but they aren’t technically necessary for success. Should is also used when you want a feature but can’t objectively test that feature.</p><p><strong>May </strong>— Denotes a <em>suggestion or allowance</em>. Use “may” when suggesting some guidance on possible options or explicitly noting a non-opinion. Anything listed as “may” is of no preference.</p><p>I use “System” to mean “the thing I’m making”, unless there’s a reason to specify another term. Capitalize it and use it consistently.</p><p>Use “is” or “will” to describe statements of fact. “System will connect to the existing network in the factory.”</p><h4>Examples of Shall/Should/May</h4><p>Good examples of “Shall”:</p><ul><li><strong>System shall output voltages between 3.0V and 6.0V DC.</strong> — Objective, testable, clearly defined. Adding the extra zero offers an increased digit of precision, which you may want if your system needs exact ranges.</li><li><strong>System’s longest dimension shall be between 30cm and 70cm in length</strong>. — Objective, testable, clearly defined.</li><li><strong>System shall be written in the Python programming language</strong> — Objective, testable. Note there’s no “version” requirement listed, so any Python version satisfies this requirement. Writing “Python 2.8” or “Python 3.0 or newer” would be possible.</li><li><strong>System shall cost less than $35 when built at a 10,000 unit scale.</strong> — Objective, testable.</li><li><strong>System shall survive a 1-meter drop onto concrete without Catastrophic Damage</strong> — Objective, testable, but with a caveat. We need to make sure “Catastrophic Damage” is defined in the document, and capitalizing it lets the user know the word has a specific meaning. It’s helpful to define terms like this if we want to reference them in multiple places. For example, we might want some water submersion requirement that also references “Catastrophic Damage.”</li></ul><p>Good examples of “Should”:</p><ul><li><strong>System should run well on phones from the past four years. </strong>— “Run well” isn’t a testable condition, so it is not a requirement. Nevertheless, it points out that people on the project need to try and target “good” performance, whatever that subjectively means.</li><li><strong>System screen should be readable in bright sunlight.</strong> — “Readable” is a subjective measure since there’s no indication of lumens, light angle, visual acuity, or anything you could precisely test. However, this could guide engineers into making sure the screen interface is readable through choices of colors, layout, size, etc.</li><li><strong>System code should be thoroughly commented.</strong> — This item gets the point across that the project team expects code comments throughout, even though there’s no specifically defined quality or quantity of comments.</li><li><strong>System should not restrict user movement. </strong>— For a wearable, all physical systems technically restrict movement in some capacity, but this statement means to use subjective judgment to determine what counts as a restriction.</li></ul><p>Good examples of “May”:</p><ul><li><strong>System may use a pre-made PCB, or a custom PCB.</strong> This allowance notes that the project doesn’t care if the final PCB is an “off-the-shelf” Arduino or completely custom SoM. While this isn’t a requirement or even a preference, it lets everyone know that there isn’t an expectation one way or the other. It explicitly states non-preference to remove any assumption of bias.</li></ul><blockquote>Items that are <em>requirements</em> use “Shall”; they have one item each, they’re unambiguous and testable.</blockquote><blockquote>Items that need subjective judgment to validate or describe a preference use “Should.”</blockquote><blockquote>Items you don’t have a preference for use “May.”</blockquote><p>General bad examples of requirements:</p><p><strong>System may use any programming language except Python</strong>. — “May” is not a requirement, so this statement has no meaning. If you did not want something in Python, make it a “shall.” If you <em>prefer</em> developers avoid Python, make it a “should.”</p><p><strong>System shall be painted green.</strong> — I have died on this hill in many meetings, but “green” is not an objectively testable condition. “System shall be painted PANTONE Green C,” or “System shall be painted with the green paint supplied by partner X” would be acceptable since anyone can precisely validate the requirement.</p><p><strong>System shall be 170cm in length </strong>— Not specific enough. Where’s the tolerance on this? 170.000 cm? Up to 170cm? A minimum of 170cm?</p><p><strong>System shall be easy to use. </strong>— How do you measure “easy”?</p><p><strong>It it required that the system allow ten users to connect simultaneously</strong> — Generally good, but “is it required that” needs to be “System shall.”</p><p><strong>System shall allow the user to be able to input a six-digit code</strong> — This entry is way too confusing. Is the system enabling the user to have some new “code-entering” capability, or is the system itself supposed to have code input?</p><p><strong>System shall be between 160.0 and 170cm in length and weigh less than 11.0lbs</strong> — These are all testable, but there are two requirements (length and weight) in one entry. Split this into two separate requirements.</p><h3>Requirements document format template</h3><p><em>Some of these items might not be relevant to a specific system but are general guidelines for an arbitrary system.</em></p><h4>1 System purpose</h4><ul><li>Why are you building this?</li></ul><h4>2 System scope</h4><ul><li>What are you making, by name?</li><li>What problem is the user having?</li><li>How does this solve the problem?</li><li>How is the system used?</li><li>What are the benefits to the user?</li></ul><h4>3 System overview</h4><h4>3.1 System context</h4><ul><li>What are the primary system elements?</li><li>How do the elements interact?</li><li>How does the user interact with them?</li></ul><p>Add diagrams or descriptions to clarify, especially if you expect the requirements to move beyond engineering and into the hands of business/marketing/etc.</p><h4>3.2 System functions</h4><ul><li>What are the major capabilities of the system?</li></ul><h4>3.3 User characteristics</h4><ul><li>Who are the different groups of users of the system? Don’t forget the maintainers, installers, etc.</li><li>How many users are there in each group?</li><li>How does each group interact with the system?</li><li>How much knowledge/capability does each group have? (This point is roughly similar to how software developers write “user stories” or business managers create “ideal customers”)</li></ul><h4>4 Functional requirements</h4><ul><li>What are the features or objectives of the system?</li></ul><p>This area is the “main” part of the requirements where you list all of “what the system does.” Remember shall/should/may language and specific, measurable conditions for “shall” requirements.</p><h4>5 Usability requirements</h4><ul><li>How will the users learn to use the system?</li><li>How is the system usable to differently-abled groups (e.g., color-blindness, dyslexia, wheelchair users, etc.)?</li><li>How does the system “safeguard” against incorrect use? (e.g., a plug that only fits one way to prevent reverse polarization).</li><li>How efficient should the system be, or how quickly should the user accomplish the system’s goals?</li></ul><h4>6 Performance requirements</h4><ul><li>How often do the users interact with the system?</li><li>What is the life expectancy of the system?</li><li>If there are different modes for the system, what are their requirements?</li></ul><p>Consider elements such as strength, stability, security, noise levels, and other conditions of use (e.g., does a system have a different requirement if it’s submerged in water?).</p><h4>7 System interface requirements</h4><ul><li>How does the system interface with other systems?</li><li>How do users interface with the system?</li><li>Does the system need to use any pre-defined communication protocols or standards?</li></ul><p>Include system interface diagrams here if needed, especially in systems with complex communication busses. Suppose the communication or external interfacing is complex (but necessary). In that case, it’s okay to reference an external document with details (e.g., “System shall interface with product <em>Omega</em> per document <em>Omega Link Unified Language</em>”). Remember to put any references in the appendix.</p><h4>8 System operations</h4><h4>8.1 Human system integration requirements</h4><ul><li>What type of constraints on personnel, operators, or other users does the system need? (e.g., does the system require special training, or do the users require ESD protection or similar?)</li><li>Where does the user interact with the system (e.g., a particular station or area)?</li></ul><h4>8.2 Maintainability requirements</h4><ul><li>Who will maintain the system? What type of training or skills do they need?</li><li>How often does the system need maintenance? How long does maintenance</li><li>Does the system need modifications to allow maintenance (e.g., an access panel)?</li><li>How much downtime is acceptable? Are there any considerations to redundant systems during downtime?</li></ul><h4>8.3 Reliability requirements</h4><ul><li>How long is the system designed to last?</li><li>How much unscheduled downtime is acceptable?</li><li>What happens to the system during a failure?</li></ul><p>This section might use statistics to specify requirements (e.g., 99% uptime, 80% capacity over ten years, etc.)</p><p>Failure Mode and Effects Analysis and a detailed quality plan often govern more in-depth reliability planning; reference them in the appendix if using them.</p><h4>8.4 Other quality requirements</h4><ul><li>How will the system be compatible with other systems?</li><li>What sort of governing quality standards or plans does the system use? Are there internal quality specifications (e.g., company policy) or external specifications (e.g., IPC, ISO, etc.) in use?</li></ul><h4>9 System modes and states</h4><p>If the system has multiple modes, use a flowchart, state diagram, or similar to describe the operations and how the user (or system) switches between these modes.</p><h4>10 Physical characteristics</h4><h4>10.1 Physical requirements</h4><ul><li>What size is the system?</li><li>What is the system’s mass, volume, or other dimension?</li><li>How large is the memory, storage space, or bandwidth (for software)?</li><li>What materials will the system use?</li><li>How is the system marked or labeled?</li><li>Does the system require standard “off-the-shelf” parts, or is it acceptable to use custom fabrication?</li></ul><p>Remember to use ranges or tolerances as necessary. Also, avoid over-specifying requirements if they aren’t the principal consideration. For example, a system might require a <em>specific</em> construction material or just require the system <em>to weigh</em> under a specific amount.</p><h4>10.2 Adaptability requirements</h4><ul><li>How does the system grow in the future or accommodate expanded use (e.g., more users, increased bandwidth, physical throughput, etc.)?</li><li>How does the system change when it reaches the limits of its use (e.g., adding more systems in parallel, expanding the existing system’s capabilities, etc.)?</li><li>How does the system change when utilized less than expected?</li></ul><h4>11 Environmental conditions</h4><ul><li>What types of environments does the system need to survive?</li><li>How is the system protected from the environment?</li><li>How does the system interact with its environment?</li></ul><p>General environmental considerations are temperature, water, dust, heat, physical shock, mold, salt, radiation, chemicals, pressure, wildlife, humans, etc. These elements will vary depending on the system’s environment. Environment also includes non-physical economic/social requirements. You can also specify a standard, such as IP testing, to govern a specific water/dust requirement.</p><h4>12 System security requirements</h4><ul><li>How do you secure the system, either physically or through software?</li><li>What sort of authentication does the user need to operate the system (e.g., keys, passwords, building access, etc.)?</li><li>What kind of protection does the system have against tampering/sabotage/accidental user error?</li><li>How does the system report any security violations (e.g., software logs, physical breaks when a panel opens, alarms, etc.)?</li><li>What are the methods of securing software code (e.g., Git methodology, CI/CD branch testing, pen-testing, disconnecting network access during system failure)?</li></ul><h4>13 Information management requirements</h4><ul><li>How does the system store information?</li><li>How is information storage secured?</li><li>How does the system back up data?</li><li>What is the storage method for information about the system (e.g., schematics, software code, industrial diagrams, market research information, etc.)?</li><li>Who has access to the various information?</li></ul><h4>14 Policy and regulation requirements</h4><ul><li>What health and safety regulations surround the system’s operation (e.g., OSHA Lockout/Tagout, internal company safety procedures, etc.)?</li><li>What multilingual support does the system use?</li></ul><h4>15 System life cycle sustainment requirements</h4><ul><li>How will you ensure the system operates satisfactorily?</li><li>How will you routinely check system operations?</li><li>Who will monitor and buy spare parts for the system? Where will you store spare parts or specific tools?</li><li>How will you train personnel on system use and maintenance?</li></ul><h4>16 Packaging, handling, shipping, and transportation requirements</h4><ul><li>How will you ship or transport the system?</li><li>Does shipment or transport require special certification(e.g., UN 38.3 for batteries)?</li><li>What type of materials should you use to package the system (e.g., ESD-safe plastic, JEDEC trays, wooden crates, waterproof containers, etc.)?</li><li>How will you store the system intermittently? Does storage require a particular environment (e.g., refrigeration)?</li></ul><h4>17 Verification</h4><p>The easiest way to write this section is to reference the specific test plan that governs the system (e.g., “System shall be considered successful when it passes all tests described in…”).</p><p>An easy way to write a test plan is to go back through the requirements, look for any “shall” requirements, and then quantify them in a test procedure. If you wrote the requirements document correctly, all requirement items have a singular testable condition with clearly-defined acceptance criteria.</p><p>For items that aren’t objectively testable but require judgment, specify a person, title, or position of whoever shall qualify that item.</p><p>Again, you can simply put all of this information in a separate test plan and then reference the test plan.</p><h4>18 Assumptions and dependencies</h4><ul><li>What axioms does the system rely on to continue operation?</li></ul><p>This section could be infinitely long (e.g., assuming measurement equipment is reliable, universal constants remain universal, P != NP, etc.), so only add items that you feel are relevant, plausible, or critical to the system’s operation.</p><p>If you don’t have control over an item, don’t include it. If you <em>could</em> have control over an external dependency and it’s critical to the system, consider adding a requirement to incorporate that dependency. For example, if the system relies on a crucial open-source library, forking the library and maintaining an internal fork might be an option instead of depending on the developers’ upkeep.</p><h3>A template with just the headers</h3><p>Front page</p><p>Version history</p><p>Definitions (don’t forget shall/should/may)</p><p>Acronyms and abbreviations</p><p>1 System purpose</p><p>2 System scope</p><p>3 System overview</p><p>3.1 System context</p><p>3.2 System functions</p><p>3.3 User characteristics</p><p>4 Functional requirements</p><p>5 Usability requirements</p><p>6 Performance requirements</p><p>7 System interface requirements</p><p>8 System operations</p><p>8.1 Human system integration requirements</p><p>8.2 Maintainability requirements</p><p>8.3 Reliability requirements</p><p>8.4 Other quality requirements</p><p>9 System modes and states</p><p>10 Physical characteristics</p><p>10.1 Physical requirements</p><p>10.2 Adaptability requirements</p><p>11 Environmental conditions</p><p>12 System security requirements</p><p>13 Information management requirements</p><p>14 Policy and regulation requirements</p><p>15 System life cycle sustainment requirements</p><p>16 Packaging, handling, shipping, and transportation requirements</p><p>17 Verification</p><p>18 Assumptions and dependencies</p><p>Appendix</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91ff484eb38c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The command to clear Terminal’s entire history]]></title>
            <link>https://kaibrooks.medium.com/the-command-to-clear-terminals-entire-history-557c4f1a2c01?source=rss-ec5642db8e42------2</link>
            <guid isPermaLink="false">https://medium.com/p/557c4f1a2c01</guid>
            <dc:creator><![CDATA[Kai Brooks]]></dc:creator>
            <pubDate>Tue, 15 Jun 2021 20:28:03 GMT</pubDate>
            <atom:updated>2021-06-15T20:28:03.895Z</atom:updated>
            <content:encoded><![CDATA[<p>That is all.</p><pre>echo &quot;&quot; &gt; ~/.zsh_history &amp; exec $SHELL -l</pre><p>And next time don’t put your password on the wrong line.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=557c4f1a2c01" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sonarr can’t find Anime? Try this]]></title>
            <link>https://kaibrooks.medium.com/sonarr-cant-find-anime-try-this-17937bc3d6ac?source=rss-ec5642db8e42------2</link>
            <guid isPermaLink="false">https://medium.com/p/17937bc3d6ac</guid>
            <category><![CDATA[usenet]]></category>
            <category><![CDATA[sonarr]]></category>
            <category><![CDATA[nzbhydra]]></category>
            <category><![CDATA[anime]]></category>
            <dc:creator><![CDATA[Kai Brooks]]></dc:creator>
            <pubDate>Thu, 07 Jan 2021 22:58:27 GMT</pubDate>
            <atom:updated>2022-01-03T02:29:01.539Z</atom:updated>
            <content:encoded><![CDATA[<h3>Sonarr can’t find Anime? This worked for me.</h3><p>I couldn’t find a solution that worked for me anywhere, but I eventually solved it. This method uses Usenet, NZBGet, and NZBHydra, technically on a NAS/Docker setup but should work for any system.</p><figure><img alt="Sonarr logo" src="https://cdn-images-1.medium.com/max/1024/1*7Hr3NclXVU0rjb-ua2lcGQ.png" /></figure><p>Anime shows on Usenet/Newznab have different category numbers than “standard” TV. This categorization creates an issue where NZBGet finds the names of releases when searching manually, but Sonarr can’t find anything, even though the rest of Sonarr works just fine. Here’s how to fix it.</p><h3>Check NZBHydra</h3><p>In NZBHydra, click <strong>Categories</strong>. NZBHydra should have the <strong>Newznab categories</strong> set to <strong>5070</strong>.<strong> </strong>If you don’t see this category, keep reading.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kpkilObPvXuItbChizajiA.png" /></figure><p>5070 is the TV/Anime category, according to the <a href="https://buildmedia.readthedocs.org/media/pdf/newznab/latest/newznab.pdf">Newznab documentation</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*3a12HytYUjefQHxPy-zxsA.png" /><figcaption>Why read documentation for 30 seconds when you can spend an hour scouring outdated links?</figcaption></figure><p>NZBHydra can automatically populate these categories for most indexers. Click <strong>Config</strong>, then <strong>Indexers</strong>, and the name of the specific indexer. Scroll to the bottom and click the <strong>Check Capabilities</strong> button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HpqXS87s1XJyGb5lAjA49w.png" /><figcaption>Check capabilities if you don’t see the Anime category in the image above.</figcaption></figure><p>After NZBHydra finishes checking the indexer’s capabilities, re-check the category in the first picture.</p><h3>Check Sonarr</h3><p>Indexers search from the selected categories. Click <strong>Settings</strong>, then <strong>Indexers, </strong>and<strong> </strong>select the <strong>Newznab</strong> indexer:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*fDQgz6MGJPN974QCjuDV3w.png" /><figcaption>Click this, or whatever you titled the Newznab indexer.</figcaption></figure><p>In the indexer, there’s a section for Categories, and also Anime Categories. In Anime Categories, make sure to select <strong>5070.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LhtprhYiZyAg6jOJWfN8pw.png" /><figcaption>Anime category 5070 in Newznab</figcaption></figure><p>Setting Anime Categories to 5070 ensures Sonarr searches for files under the TV/Anime category. You can check other categories to allow Sonarr, but if your indexer doesn’t label properly</p><h3>Check the series’ settings</h3><p>Click a series in your list, and click the <strong>edit</strong> button (up top in Sonarr v3). Set <strong>Series Type</strong> to <strong>Anime</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i--8dYm_5MpsooRGnR0l9A.png" /></figure><p>Changing this setting both alters the episode numbering scheme Sonarr uses, and also causes it to search the categories we just set in the Newznab settings above.</p><h3>In summary</h3><ol><li>Set anime category 5070 in NZBHydra</li><li>Check 5070 in Anime Categories in the Sonarr’s indexer settings</li><li>Set the Series Type to Anime of the series in Sonarr.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17937bc3d6ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Update Docker Containers on a Synology NAS (with pictures)]]></title>
            <link>https://kaibrooks.medium.com/how-to-update-docker-containers-on-a-synology-nas-with-pictures-33b82a4b251c?source=rss-ec5642db8e42------2</link>
            <guid isPermaLink="false">https://medium.com/p/33b82a4b251c</guid>
            <category><![CDATA[nas]]></category>
            <category><![CDATA[synology]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Kai Brooks]]></dc:creator>
            <pubDate>Wed, 06 Jan 2021 06:43:36 GMT</pubDate>
            <atom:updated>2021-01-06T06:43:36.691Z</atom:updated>
            <content:encoded><![CDATA[<p>Without losing your data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AvUmzBinMleh1SjG1NYi9g.png" /><figcaption>Gotta have that hero image</figcaption></figure><p>Instructions on how to update Docker containers with a Synology NAS. I’ve been using Partkeepr for inventory management in an SMT line, and deployed it through Docker on a Synology DS220+ NAS, (which also runs data collection for the rest of the factory). Here’s how to do it with any container.</p><h3>Just the Instructions</h3><ol><li>Download new image from registry</li><li>Stop the container</li><li>Clear the container</li><li>Start the container</li></ol><h3>The instructions again, but with pictures</h3><h4>Download the new image from the registry</h4><p>0. Open Docker by clicking the <strong>Main Menu</strong> in the corner and then clicking <strong>Docker</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EQSt5F5N0DemLAeN5T4fCw.png" /><figcaption>Step zero</figcaption></figure><ol><li>Click <strong>Registry</strong></li><li>Type in the name of the container to update and <strong>Search</strong></li><li>Click <strong>Download</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wpp2jZPUnG8krw_4z-Pk9g.png" /><figcaption>Steps 1, 2, 3</figcaption></figure><p>4. <strong>Select</strong> the Tag</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xZnSZGX7HBysdO6mHQJNBg.png" /><figcaption>Step 4</figcaption></figure><p>5. Wait for the system to finish the download, it will display a message in the corner, or in the notifications area.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*XAzjuUuWJy1R6B1hb8Xvbg.png" /><figcaption>Step 5</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*GAppNNp0DjmmO_V3oErCaw.png" /><figcaption>Also step 5, if the notification disappears when you’re not looking</figcaption></figure><p>This overwrites the old image with the new version. Now, to re-launch the same container with the new image.</p><h4>Clear and Restart the Container</h4><p>6. Click <strong>Container</strong></p><p>7. <strong>Stop</strong> the container with the switch on the right</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pQXSUoXSm5ydSMdR9V-0OA.png" /></figure><p>8. Once stopped, stopped, click <strong>Action</strong> and <strong>Clear</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-HU1o0H8CXxqfgKoEXWJEA.png" /></figure><p>9. <strong>Restart</strong> the container with the same switch on the right. Docker loads the updated image when restarting the container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6V7OVU7_R6Oe2BOwBJajpg.png" /></figure><p>Done. This method preserves any settings and data the container creates, and just updates the image the container runs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33b82a4b251c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easy Prolog installation on Windows, Linux, macOS]]></title>
            <link>https://kaibrooks.medium.com/easy-prolog-installation-on-windows-linux-macos-a5c5e4b3bc45?source=rss-ec5642db8e42------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5c5e4b3bc45</guid>
            <category><![CDATA[prolog]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Kai Brooks]]></dc:creator>
            <pubDate>Tue, 14 Jan 2020 17:14:19 GMT</pubDate>
            <atom:updated>2020-01-14T17:46:52.814Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZT-uARoKO0dd4Wq6tc3W2A.png" /></figure><p>Installing SWI Prolog with its web UI and running some test code. This system is functionally similar to how Jupyter Notebook runs, except with Prolog.</p><h3>Install Docker</h3><p>Install <a href="https://www.docker.com/products/docker-desktop">Docker</a> (requires a free account). This installation is a standalone on Windows and macOS, but requires the <a href="https://docs.docker.com/install/linux/docker-ce/ubuntu/">command line</a> on Linux:</p><h4>Pull the Prolog image</h4><pre>docker pull swipl/swish</pre><p>We only need to pull this once. This version includes the web interface!</p><h4>Run the image</h4><pre>docker run -it -p 3050:3050 --name prolog swipl/swish</pre><p>Anytime we want to work in Prolog, we run the above. We can then access the web GUI by pointing our browser to <a href="http://localhost:3050/">http://localhost:3050</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5zi_9hkyXf0kPeAhvSBVfw.png" /><figcaption>Prolog Web Interface</figcaption></figure><h3>A Sample Program</h3><p>Click on <em>Create a Program</em> here. The interface changes to a program on the left, and the query box on the right.</p><p>If we clicked on <em>Create a Notebook</em> here instead, the prolog interface would resemble Jupyter Notebook, and let us run cells of code individually (similar to Jupyter Notebook for Python).</p><p>In the left, program section, type:</p><pre>loves(vincent, mia).<br>loves(marcellus, mia).<br>loves(pumpkin, honey_bunny).<br>loves(honey_bunny, pumpkin).</pre><pre>jealous(X, Y) :-<br>loves(X, Z),<br>loves(Y, Z).</pre><p>This sets up the logic and axioms of our program. In the right, query section, type:</p><pre>loves(X, mia).</pre><p>and hit <em>Run</em>. This query asks, <em>who loves Mia?</em> From up top, we see that it’s Vincent and Marcellus. Our output follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m0iYrNojGObXhyIaGyLb6w.png" /><figcaption>Who loves Mia?</figcaption></figure><p>Here we only see Vincent. To see the rest, click the next button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0zxXul2ZKm83tC7yshOFtA.png" /><figcaption>Clicking next shows the rest of the output</figcaption></figure><p>For a different query, run:</p><pre>jealous(X,Y).</pre><p>Click through <em>next</em> (or the numbers) to reveal the entire output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RP3x5_ZmhymZOMPac9IGqQ.png" /><figcaption>A love dodecahedron</figcaption></figure><p>The final window looks like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J9Grok_qXpXMu3IwJC_VNw.png" /><figcaption>Output for both queries</figcaption></figure><p>Note that Prolog is case-sensitive, so if we define X with a capital, we need to use a capital in the query.</p><p>In addition, we can still run Prolog from the command line:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*iggKKQ1MklryImrFICv_Zg.png" /><figcaption>Prolog in the CLI</figcaption></figure><h3>Stopping the server</h3><p>The Prolog server stays open until we exit it with Control+C twice in the command line.</p><h4>List of errors and fixes</h4><blockquote>docker: Error response from daemon: driver failed programming external connectivity on endpoint …: Bind for 0.0.0.0:3050 failed: port is already allocated.</blockquote><p>Prolog is still running the server. You can access it at <a href="http://localhost:3050/">http://localhost:3050</a>.</p><p>If you want to stop Prolog but closed the window and can’t use the Control+C method, here’s some options:</p><p>This command will stop <em>all</em> Docker containers:</p><pre>docker rm -f $(docker ps -a -q)</pre><p>If you want to close a single container, use:</p><pre>docker container ls</pre><p>to display all running containers. Take note of the Container ID, then run</p><pre>docker stop <strong>CONTAINERID</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q_9PmVjSY2Ufxv0raZLavA.png" /><figcaption>Stopping a container. Note that we only need the first character(s) of the container ID</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5c5e4b3bc45" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Snoop Kovv — Snoop Dogg songs written by a Hidden Markov Model]]></title>
            <link>https://kaibrooks.medium.com/snoop-kovv-snoop-dogg-songs-written-by-a-hidden-markov-model-e1e9c6284886?source=rss-ec5642db8e42------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1e9c6284886</guid>
            <category><![CDATA[markov-chains]]></category>
            <category><![CDATA[matlab]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[lstm]]></category>
            <category><![CDATA[snoop-dogg]]></category>
            <dc:creator><![CDATA[Kai Brooks]]></dc:creator>
            <pubDate>Tue, 14 Jan 2020 01:57:18 GMT</pubDate>
            <atom:updated>2020-01-14T21:31:00.312Z</atom:updated>
            <content:encoded><![CDATA[<h3>Snoop Kovv — Snoop Dogg songs written by a Hidden Markov Model</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cW_gROw83zKb43kfTWPZ5g.jpeg" /></figure><blockquote>“Roll joints bigger than birds” — Snoop Dogg or Kovv or both</blockquote><p>Markov Models are great. We use them in reinforcement learning, speech recognition, random walk modeling, gesture recognition, and a host of other applications critical to countless industries. However, their most important (and sadly, least recognized) use is to write Snoop Dogg songs. Today, I will correct this oversight.</p><blockquote>Why can’t we use something like an LSTM to do this?</blockquote><p>Oh, we absolutely could, and I’ve done so. The upside is that an LSTM (a neural network architecture) employs better context-based language understanding, such as syntax, and recognizes slang phrasings (mother vs. mutha’) as grammatically similar.</p><p>The downside of the LSTM is that it takes a lot of time and a large corpus to train correctly, and the output isn’t all that different than using a hidden Markov model, which requires no training and runs in about 10 seconds.</p><blockquote>“This is the least professional use of MATLAB I have ever seen” — Anonymous Portland State University researcher</blockquote><h4>I just came here to download the code</h4><p>I got you: <a href="https://github.com/kaibrooks/snoop_kovv">github.com/kaibrooks/snoop_kovv</a></p><p>For fun, I wrote this one in MATLAB R2018a, but there’s nothing here that’s specific to MATLAB, and we could refactor this project into another language.</p><h3>Markov and Me</h3><p>Markov models are effectively probabilistic state machines. If we are in state A, there’s a probability of transitioning to state B, or C, or back to A, or to any number of other states.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_81ANOm4Bai5HO5eAtzUVw.png" /><figcaption>Markov Chain (discrete time)</figcaption></figure><p>In the above, if we are in state A, there’s a 70% chance of transitioning to state B, and a 30% chance of transitioning back to state A. If we are in state B, there’s a 40% chance of transitioning to state A and a 60% chance of transitioning back to state B.<br>With this Markov chain, we can begin in any state and use probability to move around to different states, creating a path as we go. So, in this chain, a path might look like A-B-B-B-A-B-A-A… and so on until we decide to stop.<br>Now, this is just a two-state Markov model, but it can have any number of states and transitions, and the Markov model doesn’t necessarily connect to all others.</p><h4>How does Snoop Kovv do this?</h4><p>Snoop Kovv starts with a block of text (or, <em>corpus</em>) — the top 10 Snoop Dogg songs. For each word, it looks at what words come after it, and how often they appear. Snoop Kovv then generates a gigantic, thousand-state Markov chain, with the transition probability of any state being ‘how often does this next word appear.’</p><p>As an example, look at the word “rolling”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zuyv1-xnaM61zAHWi_UL9w.png" /><figcaption>State diagram for “rolling”. These probabilities are all made up because the actual corpus has over 1000 states.</figcaption></figure><p>Suppose we’re in state ‘rolling’. There’s a 35% chance the next state is ‘up,’ 20% chance the next state is ‘down,’ 5% chance the next state is ‘you,’ and so on.</p><p>Each of the adjoining states also will have its states it connects to (which I didn’t draw here), forming a state machine ‘web.’</p><p>Now, we can start at a random state (random word), and move around to different states, recording the path we took. For instance, Rolling-Up-To-The… up until however long we want.</p><p>In theory, we can transition states forever, making a single, infinitely-long line of text, kind of like hitting the middle suggestion on a text message auto-complete. However, Snoop Kovv terminates lines after a given length and a given probability, based on how long the lines in the corpus are.</p><p>Snoop Kovv also terminates lines early when it hits a symbol like a period or exclamation point. Depending on how often these symbols end the line in the corpus, Snoop Kovv follows the same probability. This probability gives the machine-written text roughly the same flow as the original.</p><h4>What’s the difference between a memory and memoryless system?</h4><p>Snoop Kovv only looks at the current state (word) when determining the next state (next word). This is a <em>memoryless </em>system, as nothing in the past influences the next state.</p><p>We could add <em>memory</em> to this system, whereby the system looks not only at the current word but also the previous word to determine the next state. In this sense, each ‘state’ would be a chain of two states, and the probability of transition would be the probability of a word appearing after the chain of two words in a row.</p><p>This memory chain can be any length, not just two words. The larger the chain, the more coherent the output, but the less original.</p><h4>The Snoop Kovv state diagram</h4><p>This is the actual diagram for the corpus:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1i3MaOe6OoafpJfyjFy0lw.png" /><figcaption>Snoop Kovv state diagram or Seoul subway map?</figcaption></figure><p>Instead of numbers for each state transition line, we have a color-coded graph, with blue being a low transition probability, to red being a high transition probability.</p><p>Let’s zoom in on that pile in the middle:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zLq5VtIG2ayLpbzy2Se9QQ.png" /><figcaption>Like a close up of Snoop Lion’s dreads</figcaption></figure><p>It’s way too messy to make out anything useful, but we can see the individual nodes and the thousands of interconnecting lines. Also, we can vaguely make out where some of the more ‘popular’ words lie, based on the color density of the diagram. For instance, in the upper-left and upper-center, the words there have more connections, versus some of the words on the outskirts of the previous image, like ‘sixty-four’ up top.</p><h4>Data as a table</h4><p>We can also look at the output as a table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oOFy4z5JFw7Ah2KyV-MLFA.png" /></figure><p>In this view, the vertical (left) side is the state we’re in, and the horizontal (top) side is the state we’re transitioning. For example, if we’re in state 2, there’s a 100% chance of transitioning to state 10. If we’re in state 10, there’s a 0.27% chance of transitioning to state 4.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wk6Qju6pioaliM_mk6Xa1g.png" /><figcaption>State names</figcaption></figure><p>Here we see the associated state names. State 1 is <em>!</em>, state 23 is <em>act</em>, and so on.</p><h3>The output</h3><p>Let’s look at this thing in action:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7dW21gNqr_ch7OMHK0kfdA.png" /><figcaption>Roll joints bigger than birds</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VTSfJ55bXouK0mpC-fbpnw.png" /><figcaption>Snoop Dooop Doo</figcaption></figure><h3>Compare to LSTM</h3><p>For fun, I ran this same corpus through a LSTM (long short-term memory recursive neural network) I’ve been working on. It trained over 5000 epochs, and took about a day. Here’s some verses, including the original spelling:</p><blockquote>Move in oh! Oh yeah , there&#39;s something about you beautiful, <br>I just want you to know oh!</blockquote><blockquote>You&#39;re my favorite girl oh yeah , <br>There&#39;s something about you I got a toun&#39; on that <br>Back me throw it susull thing in the came woblding the doggs <br>Pow dogg you ganns and sloow in the droogs se way,</blockquote><blockquote>We doin&#39; what we do in back of the &#39;lac , <br>I&#39;m like I&#39;m up all for that and every night her body gets strapped</blockquote><blockquote>How &#39;bout that gangsta, gang, gangsta</blockquote><p>Now, this corpus is far too short for a solid LSTM use (and needs about ten times the training), but it also emphasizes the power of the Markov model. With a smaller corpus and less ‘training time,’ the Markov model produces similarly coherent results.</p><h3>Other applications</h3><p>Another application of this is combining the LSTM with the Markov model. The LSTM generates the text, and the Markov model serves as a ‘grammar check’, whenever words seem a bit off.</p><p>For instance, if the text string is “d-o-double-…,” the Markov chain should know that probabilistically speaking, this string of words should end in “g.” “Gin and … “ should end in “juice,” not just any word that follows any arbitrary “and”.</p><p>I end this with a quote from the man himself:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SZL5j528y4qwSMDtcy3HnA.png" /><figcaption>Probably a direct quote</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1e9c6284886" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a neural network from the ground up for classifying your own images in Keras/TensorFlow]]></title>
            <link>https://kaibrooks.medium.com/creating-a-neural-network-from-the-ground-up-for-classifying-your-own-images-in-keras-tensorflow-91e57d480c24?source=rss-ec5642db8e42------2</link>
            <guid isPermaLink="false">https://medium.com/p/91e57d480c24</guid>
            <category><![CDATA[keras]]></category>
            <category><![CDATA[machine-vision]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <dc:creator><![CDATA[Kai Brooks]]></dc:creator>
            <pubDate>Fri, 10 Jan 2020 07:24:40 GMT</pubDate>
            <atom:updated>2020-04-11T20:28:16.590Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating a neural network from the ground up for classifying your own images in Keras/TensorFlow, including all the super basic things people miss</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TtQk-tMKK8lT8cWhUPkuQg.jpeg" /><figcaption>Actual picture of the author cooking up this article</figcaption></figure><p>This article will go over training a neural network to classify images as either horses or humans. It’s also going to cover all the fundamental things that the data nerds scoff at and ignore when writing tutorials. We’ll set up your environment and note which commands to put in the command line. This project is also flexible enough that we could add any of our own images, and the network will train and classify them.</p><p>This article assumes the reader is an <em>absolute beginner</em> and includes some basic things (like setting up an environment) that others ignore, as well as simplifying a few complicated concepts and omitting some others.</p><p>Formalities before we begin:</p><h4>I just came here to download the code</h4><p>I got you: <a href="http://github.com/kaibrooks/demo-horsemans">github.com/kaibrooks/demo-horsemans</a></p><h4>I just want to follow some commands and not read this whole thing</h4><p>Run the <a href="https://www.docker.com/products/docker-desktop">Docker</a> container:</p><pre>docker run -it -p 8888:8888 kaibrooks/demo-horsemans:latest</pre><p>Go to the URL that displays at the end. Done.</p><h4>Why <em>another</em> Keras/TensorFlow tutorial?</h4><p>This tutorial assumes zero initial knowledge, and it covers the <em>entire process</em> to a greater extent than I’ve seen in one place, including:</p><ol><li>All the absolute beginner information, such as how to set up and environment for the first time.</li><li>Creating augmented data from your own images to train on</li><li>Training the network</li><li>Testing the trained network</li><li>Importing and exporting the trained .h5 file both as a weights file and a compiled .h5 file</li><li>Using callbacks to remember and save the best networks</li><li>Using network optimizations to fix some issues with training</li><li>Fancy plots of network performance</li></ol><p>I’m going to keep the math light because for me, it was more useful to know how to create a general-purpose neural network, and then learn the mathematical nuances later.</p><h4>Why should I read this from you?</h4><p>I wrote this because I couldn’t find a decent tutorial that assumed <em>no</em> knowledge on the part of the reader, started from the ground-up and incorporated all of the above points. A tutorial for starting with nothing and ending with a fully functional network. Most ‘tutorials’ use completely arbitrary examples that narrowly work only inside the code as listed, making it impossible for the beginner to turn those examples into something usable for them.</p><p>Secondly, I’ve taught this to people who have zero experience in machine learning and can barely manage the command line, so I mean for this to cover everything from the standpoint of the average person, not someone well-versed in computer science or machine learning.</p><p>For the PhD-endowed data scientists and the tenured professors who started their coding career in Pascal who have stumbled on this article, note that I’m simplifying many ideas here to make it easier for beginners to understand. Sometimes we forget how complicated new ideas are when our experience distances us from learning them for the first time.</p><h4>What we’re going to do</h4><p>This process overall has a few parts:</p><ol><li>Create an augmented training set.</li><li>Split the images into a training/validation/test group.</li><li>Train the network on the augmented images.</li><li>Test the network against new images.</li></ol><h4>What do I need to know that you aren’t going to explain here?</h4><ol><li>How to use Git to clone a repo, or how to download a repo from Github</li><li>Basic command line things, like navigating to a folder</li><li>You don’t actually need to know Python, but it will help</li><li>If you’re not sure what a library is, mentally replace “library” with “software”, except its not a separate program</li></ol><h4>What’s TensorFlow / Keras / Docker / whatever else we’re using?</h4><p><em>TensorFlow</em> is a library that we will use for creating and training our network. It has no interface, so it’s not a program that you just open and click some buttons. Because of this, we need to write some Python scripts which invoke TensorFlow to get it to run as we want. It’s also probably the biggest player in the machine learning space, and it’s from Google, so it’s got some backing.</p><p><em>Keras</em> is a library that runs on top of TensorFlow, which makes TensorFlow simpler to use and faster to set up training. Think of Keras as just adding some extra commands to TensorFlow which let us use short, simple code, instead of long, obnoxious code. It’s kind of like making fire by rubbing sticks vs. using matches. The result is still the same, but the latter method is considerably easier to get there.</p><p><em>Docker </em>is a virtualization software that makes an environment for Keras/Tensorflow to run in. Think of it like a virtual machine that only runs in the command line (so, no interface). Docker isn’t strictly necessary for running Keras/Tensorflow; it just makes it a lot less headache to set up and run. With one command, you can download and install every single file this entire project needs, instead of downloading everything individually.</p><p><em>Jupyter Notebook</em> a Python environment that runs in your browser. Instead of opening some separate program to write code and then running some compile command in the command line, you just open your browser, and Jupyter Notebook lets you write and run the code quickly.</p><p>To recap:<br><strong>Tensorflow</strong> — the library that’s going to create the neural network and train it<br><strong>Keras</strong> — the library that’s going to make it easy to use TensorFlow<br><strong>Docker</strong> — the software that makes it easy to install and run everything<br><strong>Jupyter Notebook</strong> — where we’re going to do the coding and running and looking at what the neural network is doing</p><h3>Set up to get everything up and running</h3><p><a href="https://github.com/kaibrooks/demo-horsemans">Github</a> houses the code for this project. I also containerized the project through Docker and uploaded it to the <a href="https://hub.docker.com/r/kaibrooks/demo-horsemans">Docker Hub</a>, so it’s easy to begin. A few lines here and there might be different from what’s in Github since I’m continually developing it, so don’t sweat it if it’s a little different.</p><h4>How do I download and install this project?</h4><ol><li><a href="https://www.docker.com/products/docker-desktop">Install Docker from here</a>. You need a free account. If you’re running Windows, after installing Docker, click the little icon in the taskbar and go into the settings. There’s an option for which drives that you want Docker to have access. Check the drive where you put your own files!</li><li>Run the following:</li></ol><pre>docker pull kaibrooks/demo-horsemans:latest</pre><p>This command tells Docker to download the container, which has all the demos, code, and other files in it. The download and decompressing might take about 10 minutes, but it’ll install everything automatically, and you only need to do this once.</p><h3>Running Docker</h3><p>Run the image with the command below. By default, <strong>Docker cannot access any files on your computer</strong> unless you give it access to the folder when you use the docker run command!</p><p>In the commands below, replace the<em> MYSWEETFOLDER </em>part<em> </em>with whatever folder you want to give Docker access. Don’t change the <em>:/tf/notebooks</em> part! This command tells Docker to make the contents of your own folder available to Jupyter Notebook inside the folder ‘notebooks.’</p><p>For mounting a folder on macOS / Linux:</p><pre>docker run -it -v ~/MYSWEETFOLDER/:/tf/notebooks -p 8888:8888 kaibrooks/demo-horsemans:latest</pre><p>For mounting a folder on Windows:</p><pre>docker run -it -v C:/MYSWEETFOLDER/:/tf/notebooks -p 8888:8888 kaibrooks/demo-horsemans:latest</pre><p>Note that the <em>:/tf/notebooks</em> part doesn’t change!</p><p>If you don’t want to use your own files, you can cut out the -v command:</p><pre>docker run -it -p 8888:8888 kaibrooks/demo-horsemans:latest</pre><h3>Let’s begin</h3><p>After using a docker run command, the command line will output an address like 127.0.0.1:8888/WHATEVER. Copy this entire address and paste it into your browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aUyixwyhd-SVy0y-AMUqHw.png" /><figcaption>Copy one of these lines, easiest is probably the bottom one. The number at the end changes each run.</figcaption></figure><p>The container runs a Jupyter Notebook server at that address. Open your browser and paste in that address to open it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l0U64d3GJE34XZmfUOabyw.png" /><figcaption>Jupyter Notebook up and running</figcaption></figure><p>Jupyter Notebook is where all the training/testing/coding/running/everything else will take place.</p><p>Inside the <em>notebooks</em> folder is the contents of the folder we specified with the docker run command (see the <em>MYSWEETFOLDER</em> example above).</p><p>If the <em>notebooks</em> folder isn’t there, it’s because you’re using the command that doesn’t include local folder access. You can still run the demo projects and save the outputs, but you can’t import your own data.</p><p>In addition to your <em>notebooks</em> folder, there’s the demo-horsemans folder, which contains all the code we’re going to work with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pUI3LcSR0dTHah_BXK_e7g.png" /><figcaption>The demo folder and its contents</figcaption></figure><h3>demo-horsemans: Is it a Horse or a Human?</h3><p>This project trains a neural network to learn the differences between <strong>horse</strong>s and hu<strong>mans</strong> from <a href="http://www.laurencemoroney.com/horses-or-humans-dataset/">this dataset</a>.</p><figure><img alt="Bad 3d renderings of horses and humans" src="https://cdn-images-1.medium.com/max/937/1*NjF7LNGGyMiRf9Tx2_5htQ.png" /><figcaption>Horses and humans created from what I can only assume to be the Playstation 2</figcaption></figure><p>Above we see some example images from the Horse or Human image set. There are about 1000 images in total, but we can make more images for better training with some <strong>data augmentation.</strong></p><h4>imageGenerator: Augmenting the data</h4><p>Data augmentation is a way to increase the diversity of the data the network sees. Sure, we could train a network on those 1000 images alone, but what if we intentionally messed with the images to make the network work harder to learn what it’s supposed to be classifying? We’ll randomly rotate images, zoom them, or maybe adjust the contrast or throw some Instagram filters on them.</p><p>By feeding the network augmented data, training forces it to learn what it’s classifying in a more general sense since it can’t rely on cheap learning shortcuts. For example, without data augmentation, the network might learn that ‘humans’ are always in the shape of thin, tall lines going straight up and down, and will spectacularly fail when trying to classify an image of a human in any other orientation.</p><blockquote>By feeding the network augmented data, it’s forced to learn what it’s classifying in a more general sense.</blockquote><p>imageGenerator.ipynb is a file that takes each of the raw images and makes some permutations of it, such as rotating it, stretching it out, cropping it, or other adjustments. The reason we do this is twofold:</p><ol><li>Augmenting the data gives us many more images on which we can train. We can quickly turn 1,000 images into 100,000.</li><li>Training the neural network with augmented data helps prevents <strong>overfitting</strong>, the bane of every application. More on that later.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oabamKjzN_W4g-vAjYHL_w.png" /><figcaption>Raw images and their augmented images</figcaption></figure><p>When we run imageGenerator, it creates a few augmented images for each image in the <em>raw</em> folder and saves the augmented images in the <em>train</em> folder. Your images might look different than mine, or someone else’s since the augmenter randomizes which transformations to use on each image!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aV4e1K-1vHDZBwlKvSKCnQ.png" /><figcaption>Horse training folder with augmented images.</figcaption></figure><p>Because the augmenter randomizes the transforms for each image, it also means we can generate a different data set by rerunning imageGenerator, or giving it a different batch size for more or fewer images with to train.</p><h4>Splitting training, validation, and testing sets</h4><p>The network needs a few different sets of images to work with:</p><p><strong>Training set </strong>— the set of images that the network will analyze to understand what makes something a horse or a human. This folder is where our augmented images go.</p><p><strong>Validation set</strong> — the set of images that the network uses to check how well it’s learning during training. These should be raw images, not augmented ones! We want the network to compare itself against actual pictures, not warped ones.</p><p><strong>Testing set</strong> — the set of images the network has never seen before. This part is the actual evaluation of how well the network classifies, which we run after the network finishes training.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QDFcLHpudZ3FZCT0In8ozA.png" /><figcaption>Test images. Note they have no background and look different than what the network trained on.</figcaption></figure><p>In this case, the test set images have no background, only the class (horse or human). We do this because if the network learned to classify incorrectly (like it was looking at the background instead), it won’t ‘accidentally’ come up with the right answer, which gives us a better idea of how the network performs. The test set doesn’t necessarily need to be on a white background like this, just so long as they’re images the network has never seen.</p><p>We need to split these images up and put them in their appropriate folders. The <em>test</em> folder has the white-backgrounded images, the <em>validation </em>folder should have the raw images, and the <em>train</em> folder should have all the augmented images. There’s also a <em>raw</em> folder, which keeps the original images, so it’s easy to generate new augmented data sets. However, the program doesn’t use the images in it for any training/validation/testing.</p><p>If the imageGenerator file doesn’t put them in the right folders, you might need to do it by hand. Remember to keep things in <em>horse</em> or <em>human</em> subfolders, since this is how the network knows which is which for training! If we were using a different dataset, the subfolders would have that datasets labels on them instead (e.g., cats, bicycles, cheese).</p><p>Note that this folder ordering is entirely arbitrary, and TensorFlow/Keras can manage different folder names or layouts. This structuring is just what I picked since it works for me, and all the code looks for images in those folders.</p><h4>horsemansTraining: training the network</h4><p>Preparation over, it’s time to train.</p><p>We can just ‘Run All’ in horsemansTraining and the program will grab the images from the folders, train the network, test the network, and save the .h5 output files. However, let’s go over a few sections of the program.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*ftvjCrbjPI9TYOhfj_aX-g.png" /></figure><blockquote>We can just ‘Run All’ in horsemansTraining and the program will grab the images from the folders, train the network, test the network, and save the .h5 output files.</blockquote><h4>The network model</h4><p>This block of code defines the structure of the neural network, with the network compiling command at the end.</p><pre>## set up model<br>model = Sequential()</pre><pre># input layer<br>model.add(Conv2D(32, (3, 3), padding=&#39;same&#39;, input_shape=train_images.shape[1:])) # filters, kernel size<br>model.add(Activation(&#39;relu&#39;))</pre><pre># hidden layers<br>model.add(Conv2D(32, (3, 3))) # 2d convolutional layer<br>model.add(Activation(&#39;relu&#39;)) # rectified linear unit activation<br>model.add(MaxPooling2D(pool_size=(2, 2)))<br>model.add(Dropout(0.5))</pre><pre>model.add(Conv2D(64, (3, 3), padding=&#39;same&#39;))<br>model.add(Activation(&#39;relu&#39;))<br>model.add(Dropout(0.5))</pre><pre>model.add(Conv2D(64, (3, 3)))<br>model.add(Activation(&#39;relu&#39;))<br>model.add(MaxPooling2D(pool_size=(2, 2)))<br>model.add(Dropout(0.5))</pre><pre>model.add(Flatten())<br>model.add(Dense(512))<br>model.add(Activation(&#39;relu&#39;))<br>model.add(Dropout(0.5))</pre><pre># output (convergence) layer<br>model.add(Dense(num_classes)) # one node for each class<br>model.add(Activation(&#39;softmax&#39;))</pre><pre># compile the model<br>model.compile(loss=&#39;categorical_crossentropy&#39;,<br>              optimizer=optimizer,<br>              metrics=[&#39;accuracy&#39;])</pre><pre>print(&#39;Model summary:&#39;)<br>model.summary() # show the summary</pre><p>First, we see this is a sequential neural network; its structure looks something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*r-Kf9txuaVXWqN2GktTRUA.jpeg" /><figcaption>General representation of a sequential nerural network. Our network has more layers (vertical groups) and more nodes (circles in each layer), but is otherwise similar.</figcaption></figure><p>On the left is the input layer, the middle is the hidden layer (though in this picture, there’s only one), and on the right is the output layer. For our network, we have one input layer, four hidden layers, and two output layers.</p><h4>The network model: input layer</h4><p>The input layer has nodes equal to the number of pixels in the image. This layer is where our image gets converted into data points and starts to move through the network.</p><h4>The network model: hidden layers</h4><p>Hidden layers are any layer that isn’t the input or output. We have a bunch of hidden layers of different sizes, and they’re all interconnected.</p><p>This area is where most of the ‘learning’ comes. As the image data moves through these nodes and layers, their values feed into other nodes, like combining different signals to get new outputs.</p><h4>The network model: output layer</h4><p>We have one output layer, though it has two output nodes because we have two classes. The values of the output layer are the probability the image is either a horse or a human (according to the network). Because this is a probability, these two nodes always sum to 1 (or, 100%). For example, if the network returned the value [0.21 0.79], that means it thinks there’s a 21% chance of the image being the first class and a 79% chance of it being the second class.</p><p>No matter what image we feed into this network, it will only ever output a probability vector (basically two numbers linked together), one being the probability of the image being a horse, the other being the probability of the image being a human.</p><h4>What types of layers does this model have?</h4><p>Here’s a brief description of what some of the layers here do:</p><p><strong>2D Convolutional Layer </strong>— This layer performs a convolution on the image, which gives us a ‘high-level’ look at the features of the image, such as edge detection. Think of convolution as ‘sampling’ points around each pixel to find parts of the image that stand out.</p><p><strong>Dense Layer</strong> — This is a layer where all the inputs and outputs connect to the previous/next layers, like the example above. This configuration is what people generally think of when they visualize a neural network. Dense layers also serve as the final output. Also known as a ‘fully-connected’ layer.</p><h4>The loss function, or, ‘how do I know this is training’?</h4><p>The loss function is a general mathematical formulation for “how well is this algorithm modeling the dataset,” with smaller being better. In a way, we could think of it as “how much error is this producing”? There are a few formulations for a loss function; we’re using one called Categorical Crossentropy, which is useful for images that only have one label (i.e., no horse-human combinations).</p><p>During training, we see the loss function in the plot, and it should go down over time. Individual runs might spike it up and down, but its overall trend should be toward zero.</p><p>Overall, we’re looking for the smallest loss we can get. This loss function is where that graph during training comes into play. As it decreases, the network performs better, though it will taper off at some point. Keep loss low!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*PKwAn435h0uJFUthV1SXlQ.png" /><figcaption>A loss plot early on in training. Note that the loss function (blue) trends downward over time.</figcaption></figure><p>The blue line represents training loss. This line is the ‘main’ loss function we’re concerned with when evaluating how well the network trains. The orange line is validation loss. Optimally, we want the validation loss as close to the training loss as possible, and converge at the end. If the validation loss is greater than the training loss (orange &gt; blue), then our network is <strong>overfitting</strong>.</p><p>Ultimately, we’re also interested in accuracy, which is why we measure it after each epoch as well. Final accuracy should hit around 80% with this project as-is, though we could improve it with some adjustments (more training time, different image sizes, more source material — several things).</p><h4>What’s overfitting and why is it bad?</h4><p>Overfitting is when a neural network learns way too well how to do the exact thing you ask it to do during training. We want to avoid this outcome because the network completely fails when giving it anything even slightly different than what it was trained.</p><p>Imagine an <a href="https://aws.amazon.com/deepracer/">autonomous race car learning to drive</a>, and the only track it learns on is an oval (NASCAR-style). The car will get good at driving fast and turning left because that’s all it ever needed to be successful. However, take this same, trained car and put it on a new windy track, and it will fail spectacularly as its ‘drive fast and turn left’ strategy doesn’t work anymore.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V4qoLqQ6rZ2hWADG2lNLWw.png" /><figcaption>An overfit partitioning problem. Even though the (overfit) green line separates the points perfectly, it misses the overall ‘trend’, or big picture of the black line. The black line is more likely to be correct with new data.</figcaption></figure><p>In a way, we can think of overfitting as ‘forcing’ the model to unnaturally perform better with a very specific set of data, at the cost of being a better ‘all-purpose’ model.</p><blockquote>Overfitting: memorization is not learning</blockquote><p>In addition to overfitting, there’s also underfitting. Underfitting is when the model is just terrible overall, like the NASCAR car that doesn’t even know how to turn or trying to partition the example above with a straight line. Usually, we can solve underfitting by just training longer.</p><h4>How does dropout help prevent overfitting?</h4><p>Image augmentation helps overfitting, but so does dropout. We use both of these in our model.</p><p>Dropout randomly ‘turns off’ some nodes in the neural network during each epoch. So, a dropout of 0.25 would turn off a quarter of the nodes. When dropout turns off nodes, it forces the network to create connections ‘around’ them, kind of like shutting off a road and having traffic take alternate paths around it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rDAi9IsSQ-2ZSmIH-ZuF2w.png" /><figcaption>Network with 50% dropout. Note that the ‘dropped’ nodes change each epoch.</figcaption></figure><p>Dropout ensures that individual nodes and paths don’t dominate the entire network, like a deep rut in a dirt path that drives all the wagons into it.</p><h4>h5 files: the trained network</h4><p>When the network finishes training, it saves everything as an .h5 file. This file is the finished, trained neural network. There are two kinds of h5 files, a weights-only file, or the full weights+network file. I won’t go into the differences here, but generally, you want to use the weights+network file (it will be the larger file), unless the application you’re using it in needs a weights-only h5.</p><p>We don’t open the h5 file directly, but instead, we use some commands to load it and run testing on it. At the end of the training, the network tests itself automatically. There’s also a separate test program, <strong>horsemansTesting</strong>, that only loads an h5 file and runs the testing.</p><p>As the network trains, it remembers the overall best performing model. After training completes, the network copies this best performing model and permanently saves it. This copying means that our final h5 is always the best network during training, even if performance got worse later on. This is an example of using a callback, basically something that runs after each epoch. Callbacks are also how we have a plot update during training, and there’s even a callback to stop training early if the network isn’t making much progress.</p><h4>horsemansTesting: loading and testing models</h4><p>Use this if you only want to test a model you previously trained. It runs the same testing as horsemansTraining, but you can skip the setup and image loading and network creation parts and go right to the testing.</p><p>Generally, you want to load the full h5 file (it’s the larger one with ‘best’ in the name). If you try to load a weights-only h5 file, you will need to re-compile the network model that the network trained! I didn’t include the network compiling in the hosemansTesting code, but it’s in the Network Model section above.</p><p>You might want to use one or the other h5 file if, for instance, you hooked this up to a camera or incorporated it into a mobile app, and your program precisely needed one or the other type of file.</p><p>The network tries to classify every image in the test folder and then logs the results. The program shows us a sampling of the images it looked at, its classification, and its confidence level for that classification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*68dZGP4Bz6Ao_6yJ7o4WuQ.png" /><figcaption>Some magestic test output</figcaption></figure><p>In the above, the network classified everything correctly. For most images, the network was certain of its classification, though, for one, it was less confident. The horse in the middle had a 58% classification confidence, and the two bars next to it show the confidence it had of each class. This confidence is exactly the same as the final weights of the two nodes in the output layer of the network architecture. If the network classified something incorrectly, the bar would be red, as an easy way to see the big picture.</p><p>There are a few other blocks of code that run the same tests, but more abstractly. One gives us the classification of a single image as a number, and another gives us the total percentage of correct classifications. These might be useful for other applications, but this block of images makes it easy to visualize the network’s performance.</p><h3>List of errors that you’ll probably encounter</h3><blockquote>docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post <a href="http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/create">http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/create</a>: dial unix /var/run/docker.sock: connect: permission denied.<br>See ‘docker run — help’.</blockquote><p>This is a weird Linux permissions error. Run this first:</p><pre>sudo chmod 777 /var/run/docker.sock</pre><blockquote>docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.<br>See ‘docker run — help’.</blockquote><p>Make sure Docker is running.</p><blockquote>docker: Pulling from library/node image operating system “linux” cannot be used on this platform”</blockquote><p>Try switching Docker to Linux containers, by right-clicking on the little icon in the taskbar and selecting “Switch to Linux containers…”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*SRmHLnq3s5Qu6oRH7Gwrpg.png" /><figcaption>Fix for some windows users. Sometimes Docker uses Windows containers by default.</figcaption></figure><p>As another option, I build a container on Windows 10 for this, though this fix isn’t as reliable:</p><pre>docker pull kaibrooks/demo-horsemans:windows</pre><h3>List of network problems you’ll probably have</h3><p>I write the following list because these were all problems I had, and this is how I managed them. There’s probably more methods than I list here, but this is my experience with it.</p><blockquote>My network performs spectacularly during training and then fails spectacularly when I try to use it to do anything.</blockquote><p>Overfit.</p><blockquote>My network can’t figure out the difference between two images in this one case, even though it otherwise classifies them correctly.</blockquote><p>Usually something in the background messing with it. Try cropping the images closer, or just removing those images from the pool.</p><blockquote>My network takes forever to get to a point where it becomes accurate.</blockquote><ul><li>Reduce your image (picture) size to make the network smaller.</li><li>Make your network less complex (like fewer layers).</li><li>Increase your learning rate.</li><li>Alternately, throw money at the problem and buy a server cluster to run it on.</li></ul><blockquote>The graph of my network performance is jittering all over the place.</blockquote><p>Reduce your learning rate, the network is making too big of adjustments and keeps overshooting and undershooting where it’s trying to reach.</p><blockquote>My loss graph looks real good at first, it decreases for awhile but then suddenly shoots up and never recovers.</blockquote><p>Learning rate probably too high. Reduce it.</p><h3>Other questions</h3><blockquote>How do I know when the network is making progress in training?</blockquote><p>Look at the plots for the loss function. Loss should decrease over time. A good time to stop is when the network stops making ‘reasonable’ progress (see below). There’s also an early stopping function which can terminate training early if the network isn’t improving at a ‘reasonable’ rate.</p><blockquote>When’s a good time to stop training?</blockquote><p>This one’s on you, and it depends on how much your time is worth, how fast you train, and how confident you are in your network structure and training parameters. There’s no use training for three days if the loss function is barely moving, and you’re not confident in the network configuration anyway. Keep in mind the network saves <em>best_model.h5</em> each epoch, so stopping early doesn’t ‘waste’ your work!</p><blockquote>Why is my network accuracy really good during training, but much worse during testing?</blockquote><p>This is most likely due to overfitting. However, another essential thing to note is that the test set contains images with just the class (horse or human) on a white background. If the network wasn’t picking up the class in the image and was, say, looking too much at the background, having no background during testing can throw it off. Perhaps try adding more convolution layers to pick out features more, or try changing the size of the images to allow more resolution for finding those features.</p><blockquote>Why can’t we use images the network has seen before for the test set? Won’t that improve the networks classification score?</blockquote><p>Yes, it will, but it’s all a lie. The network will seemingly perform very well during testing, and then perform much worse during any ‘real-world’ application. The point of the test set isn’t to make the numbers better arbitrarily; it’s so we get an idea of how this thing will actually perform in a new environment with unseen data.</p><blockquote>What are the main parts of the program we can tweak, without making any major changes to the code?</blockquote><ul><li><strong>epochs</strong> — number of training ‘runs’. More is generally better, but after a certain point the network stops improving.</li><li><strong>imsize</strong> — resize the images</li><li><strong>learning_rate</strong> — the higher it goes, the faster the network improves, but also means the network might end up ‘bouncing’ up and down as it can’t converge on a specific value.</li><li><strong>dropout</strong> — dropout rate on a per-layer basis</li><li><strong>imageGenerator.ipynb</strong> — change the number of augmented images, and how many get split into train/validate sets.</li></ul><blockquote>I have an Nvidia GPU and want to use it to speed up training</blockquote><p>This is the Docker run command. Older articles incorrectly list nvidia-docker and other weird builds that Docker needed in older versions. Note that you’ll probably need some additional configuration/drivers/etc. along with this, so it probably won’t ‘just work’:</p><pre>docker run -it --rm --runtime=nvidia --gpus all -v ~/MYSWEETFOLDER/ -p 8888:8888 demo-horsemans:latest</pre><blockquote>My cat unplugged my computer mid-training and I lost it all!</blockquote><p>Not quite. Each epoch, the network saves <em>last_model.h5</em> and <em>best_model.h5</em> in the <em>trained_models</em> folder. Grab one of them and rename it and you’ve got the model where it was last. You’ll have to start training over to produce a different model, but at least it’s not a total loss.</p><blockquote>Can this classify images with more than one object?</blockquote><p>Not as written, though you could modify it. Look for ‘multi label image classification’.</p><h3>Using your own images</h3><p>Let’s assume we have various images of three classes: <em>Bicycles, Cats, Cheese</em></p><ol><li>Put the images you want to use in the <em>raw</em> folder, separated into folders by class (/raw/bicycles, /raw/cats, /raw/cheese).</li><li>Run the imageGenerator program to create augmented images.</li><li>Split the images into training / validation / testing folders, keeping them in their respective subfolders (like in #1).</li><li>Update <em>num_classes</em> in horsemansTraining to the number of classes you’re using (in this example, 3).</li><li>Change <em>source</em> to be whatever you’re naming this experiment as. This is just so the output files get a different name, which makes it easier to figure out which network was trained on which data.</li><li>Update <em>class_names</em> with the labels for the new class (eg, [‘bicycles’, ‘cats’, ‘cheese’]). Keep in mind this needs to be ordered correctly, so if it the labels are backward here, they’ll be backward when the network runs its test! Just change the order in <em>class_names</em> if that happens.</li><li>Run it!</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OqFo8toX14-Tptsz0NaYIQ.jpeg" /><figcaption>Now we celebrate</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91e57d480c24" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>