<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/">
  <channel>
    <title>Roop｜林鼎淵 Dean Lin</title>
    <link>https://deanlin.net/tags/roop/</link>
    <image><url>https://deanlin.net/images/author_hu_aa256fc934e9a932.jpg</url><title>Roop｜林鼎淵 Dean Lin</title><link>https://deanlin.net/tags/roop/</link><width>144</width><height>144</height></image>
    <description>林鼎淵（Dean Lin）的部落格：生成式 AI 企業內訓講師、外商資安公司軟體專家、7 本書作者。400 多篇文章用白話分享生成式 AI 實戰、Claude Code 與 Vibe Coding 教學、團隊合作與職場成長。</description>
    <generator>Hugo</generator>
    <language>zh-tw</language>
    <copyright>© 2020–2026 林鼎淵 Dean Lin</copyright>
    <lastBuildDate>Fri, 09 Feb 2024 21:09:20 +0800</lastBuildDate>
    <atom:link href="https://deanlin.net/tags/roop/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>只要一張自拍照就能讓 AI 換臉整段影片！Mac M1 在本機安裝 Roop 教學</title>
      <link>https://deanlin.net/blog/202402/roop-face-swap-mac/</link>
      <pubDate>Fri, 09 Feb 2024 21:09:20 +0800</pubDate>
      <guid>https://deanlin.net/blog/202402/roop-face-swap-mac/</guid>
      <dc:creator>林鼎淵</dc:creator>
      <category>AI 實戰</category>
      <description>原本我打算放上 Google Colab，但發現免費版執行的失敗率高得嚇人；因此寫了一篇 Mac AppleSilicon 的踩坑文件，讓大家可以輕鬆體驗這款 AI 換臉的工具（在自己電腦執行，無論效率還是便利性都高太多了）。</description>
      <media:content url="https://deanlin.net/blog/202402/roop-face-swap-mac/images/roop-face-swap-mac-og_hu_db17dd163d816ed6.jpg" medium="image" type="image/jpeg" width="1200" height="675" />
      <content:encoded><![CDATA[<p>原本我打算放上 Google Colab，但發現免費版執行失敗率高得嚇人；因此寫了一篇 Mac AppleSilicon 的踩坑文件，讓大家可以輕鬆體驗這款 AI 換臉工具（在自己電腦執行，無論效率還是便利性都高太多了）。</p>
<p>文章開始前，我先總結一下體驗心得：「在 AI 的時代下，眼見不足為憑；這類換臉工具在使用上已經沒有技術壁壘，即使 0 基礎的小白也能在短時間上手。」</p>
<p><strong>【免責聲明】：教學只是示範一種思路，沒有任何不良引導，請勿將工具用於個人學習外其他目的，使用軟體需遵守軟體相關條款協議，<a href="https://web.archive.org/web/20231229190446/https://udn.com/news/story/7321/7672903" title="原網頁已失效，連到網際網路檔案館的存檔">別忘記小玉已經在監獄了</a>。</strong></p>
<figure class="figure"><img src="https://deanlin.net/blog/202402/roop-face-swap-mac/images/roop-face-swap-mac-01.webp" width="1002" height="565" alt="把我的臉合成到葉問上" fetchpriority="high" decoding="async">
  <figcaption>把我的臉合成到葉問上</figcaption>
</figure>

<blockquote>
<p><strong>小提醒</strong>：Windows 要安裝的東西可以<a href="https://github.com/s0md3v/roop/wiki/1.3-Setup-Windows">參考這篇官方文章</a>，其實跟 Mac 差不多。</p>
</blockquote>
<h2 id="step1-安裝-miniconda">STEP1: 安裝 Miniconda<a class="h-anchor" href="#step1-%e5%ae%89%e8%a3%9d-miniconda" aria-label="這個段落的連結"></a></h2>
<p>進入官網選擇與自己電腦相容的 pkg 檔下載: <a href="https://docs.conda.io/en/latest/miniconda.html">https://docs.conda.io/en/latest/miniconda.html</a></p>
<p><img src="https://deanlin.net/blog/202402/roop-face-swap-mac/images/roop-face-swap-mac-02.webp" width="1161" height="796" alt="STEP1: 安裝 Miniconda（圖 2）" loading="lazy" decoding="async"></p>
<p>安裝完成後進入終端機（Terminal），輸入 <code>conda config &ndash;set auto_activate_base true</code> 初始化 Conda（若要關閉輸入 <code>conda config &ndash;set auto_activate_base false</code> 即可）。</p>
<p>再次打開終端機時，命名行前會有（base）</p>
<p><img src="https://deanlin.net/blog/202402/roop-face-swap-mac/images/roop-face-swap-mac-03.webp" width="525" height="106" alt="STEP1: 安裝 Miniconda（圖 3）" loading="lazy" decoding="async"></p>
<hr>
<h2 id="step2-下載-roop-專案--安裝相關套件">STEP2: 下載 Roop 專案 &amp; 安裝相關套件<a class="h-anchor" href="#step2-%e4%b8%8b%e8%bc%89-roop-%e5%b0%88%e6%a1%88--%e5%ae%89%e8%a3%9d%e7%9b%b8%e9%97%9c%e5%a5%97%e4%bb%b6" aria-label="這個段落的連結"></a></h2>
<p>進入終端機後，輸入 <code>git clone <a href="https://github.com/s0md3v/roop">https://github.com/s0md3v/roop</a></code> 下載專案。</p>
<p>下載完成後進入專案目錄，將下面的內容貼到「requirements.txt」文件（這些是要安裝的套件）。</p>
<pre tabindex="0"><code>--extra-index-url https://download.pytorch.org/whl/cu118

numpy==1.23.5
opencv-python==4.7.0.72
onnx==1.14.0
insightface==0.7.3
psutil==5.9.5
tk==0.1.0
pillow==9.5.0
customtkinter==5.1.3
torch==2.0.0
onnxruntime==1.15.0; sys_platform == &#39;darwin&#39; and platform_machine != &#39;arm64&#39;
onnxruntime-silicon==1.13.1; sys_platform == &#39;darwin&#39; and platform_machine == &#39;arm64&#39;
onnxruntime-gpu==1.15.0; sys_platform != &#39;darwin&#39;
tensorflow==2.13.0rc1; sys_platform == &#39;darwin&#39;
tensorflow==2.12.0; sys_platform != &#39;darwin&#39;
opennsfw2==0.10.2
protobuf==4.23.2
tqdm==4.65.0
</code></pre><p>然後在終端機進入 roop 資料夾，輸入 <code>pip install -r requirements.txt</code> 安裝相關套件。</p>
<p><img src="https://deanlin.net/blog/202402/roop-face-swap-mac/images/roop-face-swap-mac-04.webp" width="884" height="304" alt="STEP2: 下載 Roop 專案 &amp; 安裝相關套件（圖 4）" loading="lazy" decoding="async"></p>
<p>接著可以通過 <a href="https://brew.sh/zh-tw/">homebrew</a> 安裝 ffmpeg。</p>
<p><code>brew install ffmpeg</code></p>
<hr>
<h2 id="step3-執行-roof-換臉程式">STEP3: 執行 roof 換臉程式<a class="h-anchor" href="#step3-%e5%9f%b7%e8%a1%8c-roof-%e6%8f%9b%e8%87%89%e7%a8%8b%e5%bc%8f" aria-label="這個段落的連結"></a></h2>
<p>在 roof 資料夾下執行 <code>python run.py</code>，等個幾秒鐘就會有如下的圖形介面出現（第一次執行會需要下載 500 多 MB 的資源，需等待一段時間），操作非常簡單，主要功能可以參考下圖說明。</p>
<p><img src="https://deanlin.net/blog/202402/roop-face-swap-mac/images/roop-face-swap-mac-05.webp" width="1192" height="1444" alt="STEP3: 執行 roof 換臉程式（圖 5）" loading="lazy" decoding="async"></p>
<p>不過大多數人應該第一次執行時不會那麼順利，像筆者就遇到 tk 的錯誤如下：</p>
<p><img src="https://deanlin.net/blog/202402/roop-face-swap-mac/images/roop-face-swap-mac-06.webp" width="886" height="454" alt="STEP3: 執行 roof 換臉程式（圖 6）" loading="lazy" decoding="async"></p>
<p>後面用 <code>brew search tk</code> 來搜尋，才發現 <code><a href="mailto:python-tk@3.10">python-tk@3.10</a></code> 沒裝，執行 <code>brew install <a href="mailto:python-tk@3.10">python-tk@3.10</a></code> 安裝後就正常了。</p>
<p>接著又遇到 torch、torchvision 相容性問題，這部分我看考他們的<a href="https://github.com/pytorch/vision#installation">版本對照表</a>重裝就正常了</p>
<div class="highlight"><pre tabindex="0" style="color:#e6edf3;background-color:#0d1117;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>pip uninstall torch torchvision
</span></span><span style="display:flex;"><span>pip install <span style="color:#79c0ff">torch</span><span style="color:#ff7b72;font-weight:bold">==</span>2.0 <span style="color:#79c0ff">torchvision</span><span style="color:#ff7b72;font-weight:bold">==</span>0.15
</span></span></code></pre></div><hr>
<h2 id="step4-加強出圖效果與品質">STEP4: 加強出圖效果與品質<a class="h-anchor" href="#step4-%e5%8a%a0%e5%bc%b7%e5%87%ba%e5%9c%96%e6%95%88%e6%9e%9c%e8%88%87%e5%93%81%e8%b3%aa" aria-label="這個段落的連結"></a></h2>
<p>作者表示 <a href="https://github.com/s0md3v/roop/wiki/2.-Acceleration#coreml-apple">Apple Silicon 支援 CoreML 加速</a>，執行下面指令安裝對應套件。</p>
<div class="highlight"><pre tabindex="0" style="color:#e6edf3;background-color:#0d1117;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>pip uninstall onnxruntime onnxruntime-silicon
</span></span><span style="display:flex;"><span>pip install onnxruntime-silicon<span style="color:#ff7b72;font-weight:bold">==</span>1.13.1
</span></span></code></pre></div><p>之後執行換臉程式時結尾加上「 — execution-provider coreml」即可加速，另外想增加品質可以在結尾加上「 — frame-processor face_swapper face_enhancer」即可，<strong>完整啟動換臉的指令如下</strong>：</p>
<p><code>python run.py &ndash;frame-processor face_swapper face_enhancer &ndash;execution-provider coreml</code></p>
<hr>
<h2 id="step5-看看換臉後的圖片與影片品質">STEP5: 看看換臉後的圖片與影片品質<a class="h-anchor" href="#step5-%e7%9c%8b%e7%9c%8b%e6%8f%9b%e8%87%89%e5%be%8c%e7%9a%84%e5%9c%96%e7%89%87%e8%88%87%e5%bd%b1%e7%89%87%e5%93%81%e8%b3%aa" aria-label="這個段落的連結"></a></h2>
<p>這邊我先拿自己的照片換到葉問的電影照看看。</p>
<figure class="figure"><img src="https://deanlin.net/blog/202402/roop-face-swap-mac/images/roop-face-swap-mac-07.webp" width="1192" height="1102" alt="圖片來源：葉問，僅作為教育及研究使用" loading="lazy" decoding="async">
  <figcaption><em>圖片來源：葉問，僅作為教育及研究使用</em></figcaption>
</figure>

<p>其實我覺得效果是不錯的，會有違和感是因為我太胖了，跟身體不太吻合。</p>
<p><img src="https://deanlin.net/blog/202402/roop-face-swap-mac/images/roop-face-swap-mac-08.webp" width="1400" height="788" alt="STEP5: 看看換臉後的圖片與影片品質（圖 8）" loading="lazy" decoding="async"></p>
<p>下面我再拿自己的照片跟韓團影片合成看看，不知道會不會一秒變歐巴（因為影片中有兩個人，所以我將 Many Faces 打開）。</p>
<figure class="figure"><img src="https://deanlin.net/blog/202402/roop-face-swap-mac/images/roop-face-swap-mac-09.webp" width="1192" height="1102" alt="影片來源: Levitating / dsomeb Choreography &amp; Dance" loading="lazy" decoding="async">
  <figcaption><em>影片來源: <a href="https://www.youtube.com/watch?v=Ly-Wm-hKoYU&amp;ab_channel=dsomeb">Levitating / dsomeb Choreography &amp; Dance</a></em></figcaption>
</figure>

<p>其實我覺得結果的違和感不大（自己在說），不過因為我提供的照片有眼鏡，所以有些畫面會閃。</p>
<figure class="figure figure-video">
  <video class="gifv" muted loop playsinline controls preload="none" poster="https://deanlin.net/blog/202402/roop-face-swap-mac/images/roop-face-swap-mac-10.webp" width="960" height="540" aria-label="STEP5: 看看換臉後的圖片與影片品質（圖 10）" data-gifv>
    <source src="https://deanlin.net/blog/202402/roop-face-swap-mac/images/roop-face-swap-mac-10.mp4" type="video/mp4">
  </video>
</figure>

<p>以上就是今天 AI 換臉的教學分享，筆者的電腦為 Mac M1 Max 32GB RAM，實測下來建議選擇 15 秒內的影片來做換臉，超過的話 RAM 可能會撐不住（超過可透過分段生成處理）。</p>
<blockquote class="pullquote"><p>最後提醒一下大家，這個工具真的很強大，門檻也很低；我們可以拿來學習、娛樂，但千萬不要拿來做犯法的事情。</p>
</blockquote>
<a class="linkcard" href="https://deanlin.net/categories/ai/">
  <span class="lc-body">
    <span class="lc-title">AI 實戰</span>
    <span class="lc-desc">實測生成式 AI 工具、Vibe Coding 與自動化流程的第一手心得，把 AI 變成每天都用得上的即戰力。</span>
    <span class="lc-site"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M5 12h14M13 6l6 6-6 6"/></svg>林鼎淵 Dean Lin</span>
  </span>
</a>

<p><strong>想將 AI 導入自己的職場與生活嗎？歡迎<a href="https://www.books.com.tw/products/0011004216">購買筆者出版的新書</a></strong>，幫助您<strong>在 AI 的浪潮中站穩腳步，並在未來的職場競爭中佔據優勢！</strong></p>
<figure class="figure"><img src="https://deanlin.net/blog/202402/roop-face-swap-mac/images/roop-face-swap-mac-11.webp" width="1400" height="319" alt="林鼎淵著作《ChatGPT 與 AI 繪圖效率大師（新增 Copilot、Gamma、Runway、Suno）》" loading="lazy" decoding="async">
  <figcaption><a href="https://www.books.com.tw/products/0011004216">https://www.books.com.tw/products/0011004216</a></figcaption>
</figure>

]]></content:encoded>
    </item>
  </channel>
</rss>
