kylekylehaha
  • NEW!
    NEW!  Connect Ideas Across Notes
    Save time and share insights. With Paragraph Citation, you can quote others’ work with source info built in. If someone cites your note, you’ll see a card showing where it’s used—bringing notes closer together.
    Got it
      • Create new note
      • Create a note from template
        • Sharing URL Link copied
        • /edit
        • View mode
          • Edit mode
          • View mode
          • Book mode
          • Slide mode
          Edit mode View mode Book mode Slide mode
        • Customize slides
        • Note Permission
        • Read
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Write
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invite by email
        Invitee

        This note has no invitees

      • Publish Note

        Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

        Your note will be visible on your profile and discoverable by anyone.
        Your note is now live.
        This note is visible on your profile and discoverable online.
        Everyone on the web can find and read all notes of this public team.

        Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Explore these features while you wait
        Complete general settings
        Bookmark and like published notes
        Write a few more notes
        Complete general settings
        Write a few more notes
        See published notes
        Unpublish note
        Please check the box to agree to the Community Guidelines.
        View profile
      • Commenting
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Suggest edit
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
      • Emoji Reply
      • Enable
      • Versions and GitHub Sync
      • Note settings
      • Note Insights New
      • Engagement control
      • Make a copy
      • Transfer ownership
      • Delete this note
      • Save as template
      • Insert from template
      • Import from
        • Dropbox
        • Google Drive
        • Gist
        • Clipboard
      • Export to
        • Dropbox
        • Google Drive
        • Gist
      • Download
        • Markdown
        • HTML
        • Raw HTML
    Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Engagement control Make a copy Transfer ownership Delete this note
    Import from
    Dropbox Google Drive Gist Clipboard
    Export to
    Dropbox Google Drive Gist
    Download
    Markdown HTML Raw HTML
    Back
    Sharing URL Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Customize slides
    Note Permission
    Read
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Write
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Self Supervised Learning contributed by <`kylekylehaha`> ###### tags:`Data Science` 1. Reconstruct data 2. Pretext task (間接任務) 3. Contrastive Learning ## Reconstruct data **核心想法**: 將圖片做 feature extraction 後,再將其還原。如果 feature extraction 時可以抓到的是重要的 feature,透過這樣就應該有足夠的資訊還原整張圖片。 這樣就可以不用 label 來學習如何抽取圖片特徵。 **缺點**: 1. pixel 層級需要花比較多的資源來訓練,所需時間也較長。 2. 模型學習到的 feature 比較不通用。 3. 不易訓練成功。 --- ## Pretext task **想法**: 透過人為設計的任務,使機器完成任務時必須學會抽取圖片 feature。 常見的 pretext task: - 區塊重建 - 分類相對位置: - 拼圖 - 判斷旋轉角度 ### 區塊重建 將原圖挖空,讓 model 去重建空白部分。 ![](https://i.imgur.com/T7nCtpB.png) --- ### 分類相對位置 把圖片切成九塊並且分類外圍區域相 對於中間區域的位置。以下圖為例,模型學習特徵抽取時需要能抽取耳朵特徵才可 以成功的分類相對位置。 ![](https://i.imgur.com/xrT9tNt.png) 該效果不錯,能和 supervised 差不多,但並非百分百差不多。 --- ### 拼圖 將原始圖片切成九等分後打亂,讓機器學習如何拼回去。 ![](https://i.imgur.com/UK5WWq9.jpg) --- ### 判斷旋轉角度 我們旋轉原始圖片,並讓模型預測旋轉角度。 原論文中有比較supervised learning (AlexNet)與使用旋轉任務的self-supervised learning所抽取的特徵的差異,如下圖。可以看到關注的區域不太一樣。 另外由實驗結果顯示最好的旋轉角度為0, 90, 180, 270度,更多更少種都會降低模 型的能力與分類準確率。 ![](https://i.imgur.com/XIjrU2H.jpg) --- **缺點**: 1. 不具通用性。不同的 dataset,需要由人去判斷該任務適合或不適合,也就是說,需要該 dataset 的 domain knowledge。 2. 會不會機器不用學會特徵便可以完成任務?說不定模型透過圖片的 RBG 來完成拼圖任務,而非真的學習到圖的特徵。 因此,pretext tasks 並非 self supervised learning 的主流。 --- ## Contrastive learning **核心想法**:相同的樣本在空間中要相似,不相同的樣本在空間中要不相似。 將原始資料做 data augmentation 後,丟入 contrastive model,我們希望來自相同來源的 data 在空間中是相近的。來源相同的,視為正樣本(positive smaples),不相同則視為(negative samples),即便這兩張圖看起來相似(可能都是狗狗)。 對於某一個樣本來說,它的正樣本(positive samples)要相似、負樣本(negative samples)要不相似。 以下面為例,即便都是狗狗,但來源不同就要視為 negative samples ![](https://i.imgur.com/cxYyLHJ.png) **優點** 1. 實驗結果顯示,對比學習的表現非常好,分類準確率媲美監督式學習。 2. 監督式學習在 labeled data 減少時表現會大幅下降,而對比學習不會。 3. 對比學習學到的特徵抽取模型可以遷移到不同的資料集上。 **缺點** 1. 對於運算需求高,通常需要多張GPU才能實現。 2. 在相同資料集大小下,訓練時間會比監督式學習長。 3. 模型通常需要更大更深才能有更好的表現。 --- ### Data Augmentation 的強度要高或低? 在做 data augmentation 時,會不會需要有重疊的部分才能識別?(一張圖是狗的屁股,另一張圖只有狗的身體),然而論文指出對比學習需要**高強度**的圖片變換,通常會複數種變換一起使用。 並且會讓圖片變換帶有隨機的性質,隨機的翻轉、隨機的顏色更動強度、隨機的裁 切範圍,目的是產生更多樣的圖片,才能做很多不同的對比跟觀察。 實驗顯示,若是只能採用兩種變換組合,最有效的組合是裁切(crop)+顏色抖動 (color jitter)。 ![](https://i.imgur.com/KypcVoI.png) 另一篇論文(InfoMin)也研究了圖片變換的強度,研究顯示會有一個倒U形狀,雖 然過高強度的變換會弱化模型,但是過低強度的變換弱化的程度卻是更加嚴重。 如果圖片變換的強度不夠高,正樣本可能就無法學到圖片的不變性(image invariance)![](https://i.imgur.com/wQUIy4m.png) 回到一開始的裁切問題: 會不會剛好切到沒有重疊的地方? 這樣的確是個問題,但要切到完全沒重疊的機率很低。 --- ### 如何用 loss function 判斷 feature 近或遠? 對比學習中常用的 loss function called InfoNCE。為了降低此函數,分子部分越高越好。其中 sim() 代表 cosine similarity。 ![](https://i.imgur.com/M64ddMD.png) 除此之外,也可以將 InfoNCE 視為做分類的 CrossEntropyLoss: 判斷這張圖屬於哪一個原本的圖。 ![](https://i.imgur.com/IvhESlE.png) --- ## Classic Paper - SimCLR(A Simple Framework for Contrastive Learning of Visual Representations) - MoCo(Momentum Contrast for Unsupervised Visual Representation Learning) - BYOL(Bootstrap your own latent: A new approach to self-supervised Learning) - BarlowTwins(Barlow Twins: Self-Supervised Learning via Redundancy Reduction) --- ### SimCLR(A Simple Framework for Contrastive Learning of Visual Representations) SimCLR目標是利用無標註的圖片訓練模型成為好的特徵抽取器,而這個特徵抽取器能運用在其他的下游任務,像是圖像分類或是其他電腦視覺任務。 SimCLR既不是生成類別(generative modeling)也不是利用間接任務(pretext task)的訓練方式。 - 生成類別的缺點:生成高度還原的圖片對於學習特徵並不必要。 - 間接任務的缺點:相對來說需要更多人為的知識與前處理。 --- SimCLR提出一個簡單的訓練框架,其中包含隨機性的圖片變換T、一個特徵抽取模型f 和一個映射層g。 ![](https://i.imgur.com/k8PiNid.png) --- ![](https://i.imgur.com/oLvVreL.jpg) > 圖片的 data augmentation 是隨機的。 --- ![](https://i.imgur.com/eCtpZ1w.png) --- ![](https://i.imgur.com/GiKMAId.png) --- ![](https://i.imgur.com/PYYmsQA.png) --- ![](https://i.imgur.com/1TowIvn.png) --- ![](https://i.imgur.com/FUqgLj0.png) --- ![](https://i.imgur.com/e7kmHB4.png)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully