<?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 Ian Lai on Medium]]></title>
        <description><![CDATA[Stories by Ian Lai on Medium]]></description>
        <link>https://medium.com/@Ian_Lai?source=rss-440f27de61d6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*bxcRZjQu43yP6TGE</url>
            <title>Stories by Ian Lai on Medium</title>
            <link>https://medium.com/@Ian_Lai?source=rss-440f27de61d6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 04:24:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Ian_Lai/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[【影像辨識】搭建YOLOv5環境介紹]]></title>
            <link>https://medium.com/hunter-cheng/%E5%BD%B1%E5%83%8F%E8%BE%A8%E8%AD%98-%E6%90%AD%E5%BB%BAyolov5%E7%92%B0%E5%A2%83%E4%BB%8B%E7%B4%B9-ec3673f7eeee?source=rss-440f27de61d6------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec3673f7eeee</guid>
            <category><![CDATA[object-detection]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[hunter資料科學]]></category>
            <category><![CDATA[yolov5]]></category>
            <category><![CDATA[computer-vision]]></category>
            <dc:creator><![CDATA[Ian Lai]]></dc:creator>
            <pubDate>Thu, 24 Mar 2022 16:22:50 GMT</pubDate>
            <atom:updated>2022-03-24T16:22:50.953Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>近期研究了YOLOv5，在安裝環境時遇到不少困難，在此整理方便且省略反鎖的步驟，方便下次搭建，希望也對大家有所幫助。</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4U_6WGwmz_s_20qp" /><figcaption>Photo by <a href="https://unsplash.com/@firmbee?utm_source=medium&amp;utm_medium=referral">Firmbee.com</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4><strong>安裝Anaconda</strong></h4><p>Anaconda 其中包含Python ，是資料科學、機器學習常用的平台，其中以包含許多套件方便我們使用，對於套件與環境的管理較為方便，稍後也會利用Anaconda環境跟套件。</p><p><strong>Anaconda官網下載</strong>:<a href="https://www.anaconda.com/products/individual?modal=nucleus">https://www.anaconda.com/?modal=commercial</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*aw4jkV_PpTmdBInlbHlIAA.png" /></figure><h4>下載CUDA</h4><p>CUDA是NVIDIA 研發的平行運算平台及編程模型，可利用GPU來提高運算效能，其被深度學習廣泛的使用，因為類神經網路需要大量的計算，其需要依照自身設備下載對應的版本。</p><p><strong>版本查詢</strong>:<a href="https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html#cuda-major-component-versions">https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html#cuda-major-component-versions</a></p><p><strong>CUDA Toolkit 11.6版下載:</strong><a href="https://developer.nvidia.com/cuda-downloads?target_os=Windows&amp;target_arch=x86_64&amp;target_version=11&amp;target_type=exe_local">https://developer.nvidia.com/cuda-downloads?target_os=Windows&amp;target_arch=x86_64&amp;target_version=11&amp;target_type=exe_local</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*bVKr75fs4W0NO2GVpLhn2g.png" /></figure><h4>下載YOLOv5</h4><p>YOLO全名是You Only Look Once，是一種物件偵測的方法，其方法為one-staone，可以將物件的位置偵測以及物件的分類一步到位的標示出來，然而YOLOv5這個名字卻十分有爭議，其發表時間與YOLOv4相差不到幾個月，其未經官方承認且創新性不足也被為人詬病，但是他有著YOLOv4的準確性，模型大小卻小了YOLOv4好幾倍以上。</p><p><strong>YOLOv5 github下載</strong>:<a href="https://github.com/ultralytics/yolov5">https://github.com/ultralytics/yolov5</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*kxfRFd9ogjF6RjiXmz1emw.png" /></figure><h4>建立YOLOv5環境</h4><p>安裝完Anaconda後開起Anaconda Prompt，建立我們所需要的環境，以及利用將YOLOv5解壓所後，在yolov5-master這個資料夾裡面有requirement.txt檔，可以按照裡面安裝我們所需要的套件。</p><blockquote>建立環境</blockquote><blockquote>conda create -n yolov5_gpu python=3.8</blockquote><blockquote>conda activate yolov5_gpu</blockquote><blockquote>安裝套件</blockquote><blockquote><em>pip install -r requirements.txt</em></blockquote><h4>安裝PyTorch</h4><p>PyTorch是一個深度學習框架，能支持張量(Tensor)計算，且可以運用GPU加速運算，由Facebook 人工智慧研究團隊所開發，目前廣受機器學習學習者所使用。</p><p>在requirement.txt裡面已經有安裝過一遍不過是CPU版本無法啟用GPU加速計算，所以我要到Pytroch的官網進行下載對應的相關版本，複製Command 到我們剛剛所創建的環境yolov5_gpu的Anaconda Prompt進行安裝。</p><p><strong>Pytroch官網下載:</strong><a href="https://pytorch.org/get-started/locally/">https://pytorch.org/get-started/locally/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*qcsD_14XyCgNCALM_Sv4hA.png" /></figure><h4>驗證GPU是否啟動</h4><p>利用torch.cuda.is_available()是否有啟動GPU有啟用，則會返回True。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TGfrjDBnhZ_u8G-35JwS3Q.png" /></figure><h4>結語</h4><p>近期學習了YOLOv5，在安裝環境上花了不少時間，所以特地寫了下來，希望對大家有所幫助，以上為整理的學習筆記，有疏忽遺漏的歡迎指正。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec3673f7eeee" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hunter-cheng/%E5%BD%B1%E5%83%8F%E8%BE%A8%E8%AD%98-%E6%90%AD%E5%BB%BAyolov5%E7%92%B0%E5%A2%83%E4%BB%8B%E7%B4%B9-ec3673f7eeee">【影像辨識】搭建YOLOv5環境介紹</a> was originally published in <a href="https://medium.com/hunter-cheng">學習漂流瓶 Drift Bottle</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[【Python】實現粒子群演算法(Particle Swarm Optimization, PSO) 解Rastrigin Function最小化問題]]></title>
            <link>https://medium.com/hunter-cheng/python-%E5%AF%A6%E7%8F%BE%E7%B2%92%E5%AD%90%E7%BE%A4%E6%BC%94%E7%AE%97%E6%B3%95-particle-swarm-optimization-pso-%E8%A7%A3rastrigin-function%E6%9C%80%E5%B0%8F%E5%8C%96%E5%95%8F%E9%A1%8C-afe3e01de221?source=rss-440f27de61d6------2</link>
            <guid isPermaLink="false">https://medium.com/p/afe3e01de221</guid>
            <category><![CDATA[hunter-資料科學]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[heuristic-algorithm]]></category>
            <category><![CDATA[optimization]]></category>
            <dc:creator><![CDATA[Ian Lai]]></dc:creator>
            <pubDate>Tue, 22 Mar 2022 15:15:32 GMT</pubDate>
            <atom:updated>2022-03-22T15:15:32.061Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>粒子群演算法(Particle Swarm Optimization)由J. Kennedy 和 R. C. Eberhart等人提出，屬於啟發式演算法目標在於搜尋近似最佳解，基於對於鳥群群體移動的觀察，模擬鳥群覓食行為。</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vDVVVvjWNZkJC_9w" /><figcaption>Photo by <a href="https://unsplash.com/@shwetha?utm_source=medium&amp;utm_medium=referral">Shwetha Shankar</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>粒子群演算法</strong>(Particle Swarm Optimization, PSO)，其模擬鳥群的行為建立在每隻鳥的局部感知上，鳥類會隨著自身的經驗，以及參考群體的最佳的經驗，去尋找出食物的確切位置，其優點為<strong>概念簡單</strong>，<strong>參數設置較少</strong>，<strong>方便實現，且可解大部分最佳化問題</strong>，缺點為<strong>容易陷入局部最佳解</strong>，由於可全域搜索，其<strong>收斂性較差</strong>，其<strong>解的精度不高</strong>。</p><p>本文會介紹PSO的概念以及原理，針對PSO本身參數以及PSO的流程加以解說，並用Python實現解Rastrigin Function最小化問題。</p><blockquote>Rastrigin function:是一個非凸函數的測試函數(Test functions)，此函數尋找最小值是十分困難的，有許多的局部最佳解，且搜索空間很大。</blockquote><p>本文選用二維的Rastrigin function來測試我們的PSO演算法，在此這裡A=10 n=2 且<em>Xi </em>∈[-5.12,5.12]，x=0 時有全域最小解f(x)=0，其公式以及圖片如下:</p><figure><img alt="Rastrigin function" src="https://cdn-images-1.medium.com/max/1024/1*-SB2Lda4LyhEh-0tl8np7g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*eGxn5eRrBaKTFNg1P2Y1pg.png" /></figure><p><strong>粒子群演算法(Particle Swarm Optimization, PSO)</strong></p><p><strong>概念:</strong>利用鳥類群體覓食的原理，鳥類個體可以通過一些自我評估的規則判斷位置的好壞，並且找到自己最好的位置，然而每一隻鳥類都會透過這種方式，找尋到自己最好的位置，然而群體中找到最好的位置就是我們所找尋的食物的所在地。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vb2x-xqXd3vB7Z26G60Znw.jpeg" /></figure><p><strong>步驟:</strong></p><p>1. 初始起始位置(pos)、速度(v)以及粒子</p><p>2. 計算目標函數，求出目標值(obj_val)</p><p>3. 紀錄局部最佳解(pbest)以及全域最佳解(gbest)</p><p>4. 計算速度(vel)將其粒子更新位置</p><p>5. 更新局部最佳解((pbest))以及全域最佳解(gbest)</p><p>6. 最後重複2~3步驟</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*M7TogOvYtCIvBGdFKo1FHQ.png" /><figcaption>PSO 流程圖</figcaption></figure><h4>Python程式碼實作</h4><p><strong>(一) 參數、函數設定</strong></p><p>1. <strong>Dim</strong>:解的維度，變數的數量</p><p>2. <strong>pop_size</strong> :母體大小，粒子的數量，也就是族群中鳥的數量</p><p>3. <strong>w_it_max</strong>:最大的慣性權重，其影響速度的大小。</p><p>4. <strong>w_it_min</strong>: 最小的慣性權重，其影響速度的大小。</p><p>5. <strong>c1 / c2</strong>: 學習因子，決定粒子本身經驗與群體的經驗對運動軌跡的影響，調整可以減少局部最小值以及解決收斂速度慢的困擾，一般範圍為[1,2.5]。</p><p>6. <strong>max_iter</strong>:最大迭代次數</p><p>7. <strong>Lb</strong>: 解的下界，在Rastrigin function為 <em>Xi</em>∈[-5.12,5.12]</p><p>8. <strong>Ub</strong>: 解的上界，在Rastrigin function為 <em>Xi</em>∈[-5.12,5.12]</p><p>9. <strong>fun</strong>: 目標函式為Rastrigin function(2D)其公式如下:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94db8706058a48ae3952b2b044c9f015/href">https://medium.com/media/94db8706058a48ae3952b2b044c9f015/href</a></iframe><p><strong>(二) 初始起始位置(pos)、速度(vel)</strong></p><p>1. 利用上下界隨機初始化位置</p><p>2. 隨機初始化速度</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d76a7a48e8b16d6f4eb8ce906a96ec3/href">https://medium.com/media/4d76a7a48e8b16d6f4eb8ce906a96ec3/href</a></iframe><p><strong>(三)計算目標函數，求出目標值(obj_val)並且記錄解</strong></p><p>1. 求出目標值(obj_val)</p><p>2. 紀錄局部最佳解(pbest)以及全域最佳解(gbest)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ffcfc77d4126a022a895b2142a8ce9a/href">https://medium.com/media/5ffcfc77d4126a022a895b2142a8ce9a/href</a></iframe><p><strong>(四) 計算速度(vel)將其粒子更新位置</strong></p><p>1. 利用線性遞減的方式計算慣性權重(w)</p><p>2. 利用慣性權重以及隨機變數來更新速度(vel)，公式如下</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-vy4v_tEsYXlp8m7mTaKcw.jpeg" /></figure><p>3. 更新粒子位置(pos)，公式以及示意圖如下</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/208/1*qZU9XxDWy9wvgvvTU9er1g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*F0DBmoZFk94CYqUkJ6-1bw.png" /><figcaption>位置更新示意圖</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b095583d7b968c194a556f87ec20f81/href">https://medium.com/media/2b095583d7b968c194a556f87ec20f81/href</a></iframe><p><strong>(五)更新局部最佳解((pbest))以及全域最佳解(gbest)</strong></p><p>1.紀錄每一個點的最佳位置，並找出局部最佳</p><p>2.從記錄中的局部最中找出全域最佳解</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01c5a9e326c6933160538971308c73ea/href">https://medium.com/media/01c5a9e326c6933160538971308c73ea/href</a></iframe><p><strong>程式運行結果:</strong></p><blockquote>最後運行結果為如下，[x1,x2]=[ 4.86256190e-10 -1.54326018e-09]時有<strong>最小值為0</strong>，粒子群演算法在解Rastrigin function的效果還是不錯的，可以發現很快可以找出全域最小值，下圖為運行結果以及每次迭代中最小值。</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*FT7QBwdM-vNqVSRVttKQqw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*gvFd_u2Z_PMom07y8K-KvQ.png" /></figure><p><strong>結語</strong>:這次分享的演算法是利用觀察鳥群覓食所發展出來的粒子群演算法(PSO)，其概念簡單且容易實作，實用性廣泛，可以解很多最佳化問題，以上為整理的學習筆記，有疏忽遺漏的歡迎指正。</p><p>•<strong>全部程式碼</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1306508cdb376de61c547378edfd539f/href">https://medium.com/media/1306508cdb376de61c547378edfd539f/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afe3e01de221" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hunter-cheng/python-%E5%AF%A6%E7%8F%BE%E7%B2%92%E5%AD%90%E7%BE%A4%E6%BC%94%E7%AE%97%E6%B3%95-particle-swarm-optimization-pso-%E8%A7%A3rastrigin-function%E6%9C%80%E5%B0%8F%E5%8C%96%E5%95%8F%E9%A1%8C-afe3e01de221">【Python】實現粒子群演算法(Particle Swarm Optimization, PSO) 解Rastrigin Function最小化問題</a> was originally published in <a href="https://medium.com/hunter-cheng">學習漂流瓶 Drift Bottle</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>