yaming
    • 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

      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.
      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

    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.
    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
    Ai 班第一組 會議記錄 === ### 2020/05/27會議資訊 :::info - **會議地點:** 3樓休息區 - **日期:** 2020/05/27 - **議程** 1.之後的網頁開發工具使用:Django或node 簡易的資訊可參考: https://medium.com/hobo-engineer/ricky%E7%AD%86%E8%A8%98-django-vs-express-2e30e61aa23d 2.目前大家關於資料查詢的進度or自己編輯程式的進度 3.資源同步的部分https://hackmd.io/@yaming/HyquLLiiL/edit 目前先統一在此地進行紀錄,也可分享程式碼(煩請務必寫上註解) 4.關於AI的演算法,目前希望各位能在會議後各自學習,另外期望各位能在下午決定先研究一個演算法。 然後在下周一每個人能花個(5~10分鐘)分享各自的主題,相關主題的選擇可以參考以下資訊 sklearn中常用的模塊有分類、回歸、聚類。 * 分類:識別某個對象屬於哪個類別,常用的算法有:SVM(支持向量機)、nearest neighbors(最近鄰)、random forest(隨機森林),常見的應用有:垃圾郵件識別、 圖像識別。 * 回歸:預測與對象相關聯的連續值屬性,常見的算法有:SVR(支持向量機)、 ridge regression(嶺回歸)、Lasso,常見的應用有:藥物反應,預測股價。 * 聚類:將相似對象自動分組,常用的算法有:k-Means、 spectral clustering、mean-shift,常見的應用有:客戶細分,分組實驗結果。 資瞭來源: https://www.itread01.com/content/1551725786.html - **會議記錄:** * 投票決議後續網頁伺服器以:Django為主,請大家有空研究一下 * 目前組員個人進度: 1. 進行新聞真假資料的爬蟲,已爬取[事實查核組織](https://tfc-taiwan.org.tw/)。但是此網站的資料真假比例為3:400,無法進行有效的分析。 目前已更換網站[MyGoPen](https://www.mygopen.com)做資料爬取 2. google網路評論爬蟲,已經能夠順利爬取部分的評論資料 後續將另外提供中文語意辨識的演算法(路徑) 3. 找到影像辨識的演算法(YOLO),已進入測試階段。 後續依照[食物圖片](https://www.kaggle.com/kmader/food41/data?)進行測試 4. 找到公開的[食物辨識網站](https://www.caloriemama.ai/api),後續打算使用[食物圖片](https://www.kaggle.com/kmader/food41/data?)中的資料測試以及爬蟲對應的圖片資訊 5. HR 的資料收集,後續尋找辨別文字圖像的工具 * 後續請大家將想要分享的演算法資料記錄在[Ai 演算法分享]中,如果可以演算法發想請標註座號&主題 * 請大家將近期查詢到的資料分享到這邊 大檔案:貼上檔案的下載路徑(google的雲端路徑、檔案原始路徑),放在[雲端資源]的目錄底下 程式:貼在[程式範例]的目錄底下 文字資訊:先貼在分享區,需標註座號或姓名 ::: ### 2020/06/01會議資訊 :::info - **會議地點:** 3樓休息區 - **日期:** 2020/06/01 - **議程** 1. 每人5~10分鐘分享演算法的資料 2. 進度追蹤整理 - **會議記錄:** 1. 食物照片分析部分,目前以既有的網站做訓練,接下來的計畫是以收集台灣在地食物的資料為主,並連結食物營養成分資料庫,食物圖片可使用Yolo訓練。 2. 物件辨識模組訓練持續進行中。目前正在重灌系統,考慮使用資策會的桌電灌顯卡驅動程式。 3. 動物聲音辨識,繼續收集貓咪四種情緒狀態的聲紋資料。有時間幫忙的組員可以找YouTube影片。 4. Google評論文字分析目前準確度提升到50%,接下來計畫是增加資料量到八萬筆。 5. 文字辨識技術已經相當成熟,市場上競爭對手多,組員將把重心放在協助貓咪與食物資料的收集。 6. 至下週前組員的主要目標以資料收集為主,並開始訓練。 ::: ### 2020/06/08會議資訊 :::info - **會議地點:** 3樓休息區 - **日期:** 2020/06/08 - **議程** 1.收集資料彙整 2.當前執行進度追蹤 3.下一週事項規劃 - **會議記錄:** 陽明哥:需要人手前處理錄音檔 準確率1.0!? 周哥:協助音訊前處理 老詔:爬蟲+前處理 斷詞+訓練 調準確率0.77(田口法) 唐哥:增加食物圖片辨識率 口罩辨識 家澄哥:協助標熊哥圖片 熊哥:收集資料 開始YOLO 也需要人手標圖片 ::: ### 2020/06/15會議資訊 :::info - **會議地點:** 3樓休息區 - **日期:** 2020/06/15 17:00 - **議程** 1.當前執行進度追蹤 2.下一週事項規劃 3.下次會議時間討論 - **會議記錄:** - 下次6/23(二) 17:00小組會 - 進度 音組 小馬-周穎 本週 音檔素材蒐集 下週 素材蒐集、模型demo 圖組 佳澄-熊哥-瑋祈 本週 以YOLO標示圖片 下週 圖片標示(營養素分類)、 試跑模型(常見20種類別辨識) 文組 老詔 本週 熵分析5星評價使用文字重要節點 ("好吃"、"美味" 出現時很可能為5星) 下週 LSVM分析未標籤評論平台 - 其他 確認機器學習問題? 深度學習問題? ::: ### 2020/06/23會議資訊 :::info - **會議地點:** 3樓休息區 - **日期:** 2020/06/23 17:00 - **議程** 1.當前執行進度追蹤 2.下一週事項規劃 3.規劃平台呈現 - **會議記錄:** - 根據之前討論的決定使用Django, 組員可以開始熟悉。 - 接下來這週可以開始準備最後呈現的結果,前後端的應用,如何把訓練後的模型與成果整合。 - 貓咪聲音:網頁訓練使用YouTub 影片連結或者Line Bot 輸入聲音 - - 圖片辨識:選擇需要的圖片資料,以具台灣特色的食物為主,再討論。(外國人台灣必吃的美食) - 文字辨識:LSTM準確率提升至90%,接下來做假五星/一星評論分析,產生美食區域雲/本店雲/對手雲。 - 下周討論與貓咪聲音分析、圖像辨識、美食推薦、貓咪收容所推薦...等可能的整合。 ::: ### 2020/06/29會議資訊 :::info - **會議地點:** 3樓休息區 - **日期:** 2020/06/29 17:00 - **議程** 1.當前執行進度追蹤 2.下一週事項規劃 3.規劃平台呈現 - **會議記錄:** - 討論使用 github,以便組內程式碼與檔案資料分享。(目前都存放在雲端硬碟。) - 文字分析Google評論時常常出現極端值 (1星或5星)。接下來會嘗試使用虛擬環境,目標繼續判斷假5星評論,進一步嘗試自動產生評論。 - 貓咪聲音的分析程式已經簡化以提升效率,預計是以YouTube影片作為輸入,每兩秒取一段聲音做分析,做出聲音情緒的分類。 - 影像辨識部分因為model大小和demo速率的關係,改用resnet,下週預計可以用自己訓練的資料跑demo。 - 預計整組七月首週初步完成訓練model,以便開始前端網頁應用部分的工作。 - 接下來這週可以再發想其他可能的專題方向。 ::: ### 2020/07/07會議資訊 :::info - **會議地點:** 3樓休息區 - **日期:** 2020/07/07 17:00 - **議程** 1.規劃平台呈現 2.後續是否要新增主題 3.成果發表規劃 - **會議記錄:** - 暫定本周開始到結訓前,每周二、五於9:30開會(7/10、7/14、7/17、7/21、7/24、7/28) - 接下來整組進度以平台建立和結果呈現為目標。結果以Web呈現,會議有討論到Line Bot,作為有餘力的延伸目標。 - 圖片辨識模型已完成,有五種食物可以辨識。由於分析訓練的困難度,加上各種食物收集到的照片數量不一,訓練過程中照片過少、太難收集或品質不足的食物種類已經排除。再討論是否需要因為專題發表增加種類,或者增加訓練的照片量已提稱。 - 貓咪情緒辨識目前進度在平台建立,預計以事前處理過的YouTube影片片段,在平台上播放,同時標示該片段每兩秒內的貓咪情緒分析結果。 - 文字分析,假五星評論準備上線。如果有其他想法或者需要網路爬蟲的延伸可以再討論。 - 待討論事項:王老師要求的【專題介紹】、專題發表時的結果呈現、報告內容、報告流程與順序、是否有其他關於主題的新想法。 - 目前完成之程式與資料已/將上傳(雲端)。 ::: ### 2020/07/14會議資訊 :::info - **會議地點:** 3樓休息區 - **日期:** 2020/07/14 14:00 - **議程** 1.DEMO系統 2.成果發表規劃 - **會議記錄:** 1. DEMO系統(已完成聲音的功能,評論與美食圖片的應用還未完成) 2. 發表會的討論: 2.1. 目前的流程與暫定的報告人選如下: 2.1.1. 開頭: 吳周穎 2.1.2. 聲音使用的技術: 張陽明 2.1.3. 美食圖片使用的技術: 唐瑋祁 2.1.4. 評論使用的技術: 楊紹年 2.1.5. 網頁DEMO: 熊偉傑 2.1.6. 結論: 李佳澄 2.2. 報告內容的準備 ::: ### 2020/07/17會議資訊 :::info - **會議地點:** 3樓休息區 - **日期:** 2020/07/17 09:30 - **議程** 1.DEMO系統 2.成果發表規劃 - **會議記錄:** ::: Ai 演算法分享 === ## 主題1:決策樹&隨機森林 :::info -**編輯人:張陽明** -**編輯日期:2020/05/30** ## -**決策樹** ![](https://i.imgur.com/jJaE9Oz.jpg) 是由一對IF的概念層層疊加 在讀入數據後會統計及測試判斷條件與解答的相關性 並逐步塞選出**最佳的交換點** **分類樹規則:** **1.資訊增益(Information gain)** 在判斷事情的時候,會有一定的數據分析資訊,例如:投三顆骰子,相加的結果是3~18,機率為1/16 當確定一個資訊後,在後續預測結果的成功率就會增加,例如:我若知道其中一顆骰子是3,相加的結果是5~15,其機率為1/11 資訊增益**類似**於1/11-1/16 在標準的資訊中會用資訊熵來做資訊增益的計算 資訊熵的數學公式 ![](https://i.imgur.com/fgEEYiX.jpg) 參考文資訊:[機器學習(10)--訊息量、資訊熵(Information Entropy)](http://arbu00.blogspot.com/2018/01/10.html) **2.吉尼不純度(GINI impurity)** 主要是透過數學判斷,每項數據對應結果的錯誤率 計算**結果越高**則數據**越不重要**,**越低**代表數據**越重要** **!!!計算結果必須要不等於零!!!** 相關公式: ![](https://i.imgur.com/MOvdC6w.png) **!!!計算結果必須要不等於零!!!** 參考文資訊:[維基百科-決策樹學習](https://zh.wikipedia.org/wiki/%E5%86%B3%E7%AD%96%E6%A0%91%E5%AD%A6%E4%B9%A0) **3.變異數縮減(Variance reduction)** 在多個決策後,其他數據相關的變數就會比較容易減少 最後在樹的高度過高,會有很大的機率遇到過度適應(overfit) 相對應的處理方向,會**修剪樹**以減少過度適應(overfit)發生的機率 # -**隨機森林** 為決策樹的延伸用法,目標為降低過度適應(overfit)的發生 主要是建立多顆分類樹,在依照所有分類樹的結果進行百分比的統計 # -**總結** 目前在實務面以上兩者較多是使用隨機森林來做機器學習,主要為適用性較廣,且發生過度適應(overfit)的機率也相較低。 python 模組建立 ``` from sklearn.tree import DecisionTreeClassifier #導入模組 dtree = DecisionTreeClassifier() #建立決策樹模組 dtree.fit(X_train,y_train) #訓練開始 ``` 資料來源:[DecisionTreeClassifier參數設定說明](https://blog.csdn.net/akon_wang_hkbu/article/details/77621631) ::: ## 主題2: SVM(支持向量機) & nearest neighbors(最近鄰) :::info -**編輯人: Leo Lee -**編輯日期: 2020/6/1 ## -**K-近鄰演算法(K-NN)** K-NN 演算法是一種最簡單的分類演算法,透過識別被分成若干類的數據點,以預測新樣本點的分類。K-NN 是一種非參數的演算法,是「懶惰學習」的著名代表,它根據相似性(如,距離函數)對新數據進行分類。 ![](https://buzzorange.com/techorange/wp-content/uploads/sites/2/2019/08/%E6%BC%94%E7%AE%97%E6%B3%954-768x512.webp?jpg) K-NN 能很好地處理少量輸入變數(p)的情況,但當輸入量非常大時就會出現問題。 ## -**支持向量機(SVM)** 支持向量機既可用於迴歸也可用於分類。它基於定義決策邊界的決策平面。決策平面(超平面)可將一組屬於不同類的對象分開。 ![](https://buzzorange.com/techorange/wp-content/uploads/sites/2/2019/08/%E6%BC%94%E7%AE%97%E6%B3%959-768x510.webp?jpg) 舉例來說,如果將藍球和紅球都丟入袋子裡,要怎麼完美的劃出一條線將他們分割呢?這時透過機器學習的模型—向量支持機(SVM)處理,就能將所有的球拉到更高的維度做切割,讓原本散亂的球,在三維空間漂浮看起來,變得容易分類。 ![](https://i2.wp.com/makerpro.cc/wp-content/uploads/2019/04/1-6.png?w=872&ssl=1) 參考文資訊: (https://buzzorange.com/techorange/2019/08/13/machine-learning-algorithm-collection/) (https://makerpro.cc/2019/05/introduction-to-ai/) ## -**機器學習服務的種類** 有三個主要類別:經過指導的學習、未經指導的學習和增強式學習。 監督式學習 在Train的過程中,每個資料點都會加上標籤或與感興趣的類別或值產生關聯。 分類標籤就是將影像指派為「貓」或「狗」。 值標籤的範例則是與中古汽車相關聯的銷售價格。 監督式學習是研究許多像是這些已加上標籤的範例,然後能夠做出有關未來資料點的預測。 例如,識別包含正確動物的新相片,或者針對其他中古汽車指派精確的銷售價格。 這是常見且實用的機器學習服務類型。 ::: ## 主題3: Reinforcement Learning (強化學習) :::info -**編輯人:吳周穎** -**編輯日期:6/8** ## 架構 簡單來說,就是訓練出一個agent(大腦)可以去適應environment(環境) ![](https://i.imgur.com/Ocktffs.png) - 將environment環境每一個時間點的observation(觀察)的集合當作環境的狀態(State) - 從環境的狀態(State)跟獎勵(Reward)再去選擇一個最好的動作(Action),稱為策略(Policy) ![](https://i.imgur.com/owILf4D.png) 未來只取決於當前,所以我們可以假設 下一個狀態只跟現在這個狀態有關 ![](https://i.imgur.com/9g7OOMp.png) 行動價值函數 ![](https://i.imgur.com/kNyGKhZ.png) 策略價值函數 (求最大) ![](https://i.imgur.com/W4OYjxh.png) 但窮舉記憶體會爆炸,改用深度學習,狀態(s),損失(w) ![](https://i.imgur.com/siCjAgP.png) 要找最大的價值函數,則函數最終趨近Target Q ![](https://i.imgur.com/DF45luK.png) 損失函數要小,則目前價值函數要趨近最大價值函數 ![](https://i.imgur.com/SeLL0OX.png) DQN模型 ![](https://i.imgur.com/cJzrhW9.png) 但DQN屬單線程模型(記憶模型),還是有戰記憶體與需多次疊代缺點 目前最新為用 A3C(Asynchronous Advantage Actor Critic) ![](https://i.imgur.com/lDRlqM4.png) 每個線程負責不同任務,多線程非同步讓處理速度變快 補充資料: https://blog.tensorflow.org/2018/07/deep-reinforcement-learning-keras-eager-execution.html 參考資料: https://bit.ly/379hFgQ https://bit.ly/2zbKXit ::: ## 主題4:Convolutional neural network :::info -**編輯人:唐瑋祁** -**編輯日期:20200617** 將圖片經過卷積與池化處理,凸顯出特徵讓機器容易辨識學習,卷積會讓filter在圖片上跑,幾個filter會跑出幾層channel的圖片, 卷積利用內積概念將特徵放大,而池化降低維度,將資料量縮小。 參考資料:https://medium.com/@chih.sheng.huang821/%E5%8D%B7%E7%A9%8D%E7%A5%9E%E7%B6%93%E7%B6%B2%E8%B7%AF-convolutional-neural-network-cnn-cnn%E9%81%8B%E7%AE%97%E6%B5%81%E7%A8%8B-ecaec240a631 ::: ## 主題5:RNN :::info -**編輯人:**楊詔年 -**編輯日期:**0618開始 ## **RNN** ## *Feedforward network與RNN的差別* 前饋式神經網路,如Dense全連接神經網路/CNN卷積神經網路,將整個資料(電影評論)轉成單一的大型向量並一次處理。 人腦理解語言資訊的方式有時間性,先記住先前的東西('公'),隨著新東西('車')進來而更新('我知道了 是公車')。 Reccurrent neural network 就像上面原理的簡化版,想像你在對一個RNN神經元說話(一個字一個字說),新的輸入資訊('車')會加上過去的輸出('公?'),決定了現在的輸出('喔 是公車啦')。這個輸出成為了神經元的新狀態,給下一時間點('來了')使用。而層的權重可視為該層的狀態。 處理不同評論時 RNN會被重置 ![](https://i.imgur.com/cYFwxiJ.png) 在一開始(還不知道任何詞時) 初始狀態(第0個Output)被設為0向量 ![](https://i.imgur.com/gXrsxO4.png) 我覺得這邊用tanh是要正規化output_t 如果向量中出現了超出正負1區間很多的值 就會被歸類到1或是-1 ![](https://i.imgur.com/OF8NANW.png) ## [RNN中的梯度消失 會讓訓練出來的模型失智!? 影片連結](https://www.youtube.com/watch?v=zYs00KkTltg) LSTM GRU ::: ## 主題6:Spectral Clustering :::info **編輯人:** 熊偉傑 **編輯日期:** 20200620 ## **Spectral Clustering** **分群 (Clustering)的目標,是把「相似的個體 (individual) 通過演算法分到同一個子集合 (subset)」。** * 緊緻性 (Compactness):把「距離 (distance) 必較靠近的幾個資料點」分在同一群。 * 連通性 (Connectedness): 把「可以被串接在一起的資料點」分在同一群。 ![](https://i.imgur.com/B1F1W6J.png) ---- **拓樸資料分析 (Topological Data Analysis)** 1. 考慮資料點 (data point) 之間的距離和分佈的「*形狀*」(Shape)特徵 (feature) 去捕捉連通性的特殊方法,運用圖論 (Graph Theory) 進行分群。 2. 相似圖 (Similarity Graph) 的建立: 利用兩點之間的歐式距離 (Eucledian Distance)計算**高斯核相似函數** (Gaussian Kernerl Simlarity) 。 3. 資料點之間的高**斯核相似函數**就是權重圖中(下圖)連接兩個節點攜帶的權重(weight),權重越大則代表連結性越強。 ![](https://i.imgur.com/zwqvNMX.png) ----- 參考資料: https://taweihuang.hpd.io/2017/07/06/intro-spectral-clustering/ ::: 分享區 === Git教學: https://backlog.com/git-tutorial/tw/intro/intro1_1.html YOLO: 數據來源 === 事實查核網站:https://tfc-taiwan.org.tw/ MyGoPen:https://www.mygopen.com 食物圖片來源:https://www.kaggle.com/kmader/food41/data? 食物辨識網站:https://www.caloriemama.ai/api 食物辨識網站(新加坡):https://foodai.org/ 找圖片的網站: https://www.shutterstock.com #### ~~真假新聞資料~~ (未進行的主題) [新聞資料](https://drive.google.com/file/d/1Qy1IgR4Ai3W0CGoC8nGg5B8ZmB4kywtv/view?usp=sharing) (真:3假:400多)資料分布不平均 ### 協助項目 #### 貓咪聲音 目前整理的資料可到以下連結查詢: https://drive.google.com/drive/folders/1znJD1WXGOA_vjDJW31rLNyRD9-v-pc2l?usp=sharing * 需要查詢的分類: * 貓咪生氣的聲音:1200筆 * 貓咪打呼嚕的聲音:1200筆 * 貓咪發情的聲音:空缺 * 一般叫聲:空缺 * 處理流程: 1. 尋找貓咪影片,盡量不要有其他聲音的 2. 透過[video](https://www.savethevideo.com/convert)下載一個小時的.wav檔 (可手動設定因檔長度) 3. 透過 程式範例 中的 音訊資料圖像轉化的資訊以三秒等長進行切割 4. 再將分割完成的音檔轉成圖檔 #### 爬蟲抓圖資源 Google圖片批次下載: https://google-images-download.readthedocs.io/en/latest Flickr圖片批次下載: https://github.com/ultralytics/flickr_scraper #### 台灣食物圖片 台灣小吃: https://www.taiwan.net.tw/m1.aspx?sNo=0000072 圖片搜尋: https://zh.lovepik.com/images/ 台灣美食資料收集(熊Google雲端): https://drive.google.com/drive/folders/1Jr3FR8yQSn3gAMzBem1eiVRKXg2EpZwr 台灣食品成分資料庫2019版 (熊Google雲端): https://drive.google.com/file/d/1nKFX769MBcHbOV6EUdJdCDNGvaKoquuu/view?usp=sharing #### 圖片標註套件 labelImg: https://github.com/tzutalin/labelImg 程式範例 === ### 爬蟲範例 --- 目的:爬取新聞真假資訊資訊 查詢網站:https://www.mygopen.com/ :::info 匯入涵式 ``` from bs4 import BeautifulSoup as bs import requests from selenium import webdriver from selenium.common.exceptions import TimeoutException from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By import pandas as pd #數據工具 ``` 指定chrome的啟動程式 ``` current_dir = "C:/Users/Student/Downloads/chromedriver_win32" path = current_dir + '/chromedriver' driver = webdriver.Chrome(executable_path=path) ``` 爬取網頁資訊 ``` all_list = list() #存放全部資料 for i in range(1,149): #網頁的最多只有149頁 driver.get("https://www.mygopen.com/#Label1-p-"+str(i)) #自動填入頁數 driver.refresh() #重新整理 time.sleep(5) for j in range(8): temp = list() #單筆資料的list #避免找到對應元素,所以用tr try: # 動態等待 # 指定等待特定的XPATH元素 element = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.XPATH, '//*[@id="widget-content-Label1"]/div['+str(j)+']/div[1]/div[1]'))) #紀錄新聞來源 temp.append(driver.find_element_by_xpath('//*[@id="widget-content-Label1"]/div['+str(j)+']/div[1]/div[1]').text ) #找不到資料的運作 except: temp.append("not find form") try: #新聞標題&本地端詳細資訊連結 element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="widget-content-Label1"]/div['+str(j)+']/div[1]/h3/a')) ) #新聞標題 temp.append(driver.find_element_by_xpath('//*[@id="widget-content-Label1"]/div['+str(j)+']/div[1]/h3/a').text ) #本地端詳細資訊連結 temp.append(driver.find_element_by_xpath('//*[@id="widget-content-Label1"]/div['+str(j)+']/div[1]/h3/a').get_attribute('href') ) except: temp.append("not find topic") temp.append("not find url") try: element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="widget-content-Label1"]/div['+str(j)+']/div[1]/div[2]/a[3]/span')) ) #紀錄編輯時間 temp.append(driver.find_element_by_xpath('//*[@id="widget-content-Label1"]/div['+str(j)+']/div[1]/div[2]/a[3]/span').text ) except: temp.append("not find write time") try: element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="widget-content-Label1"]/div['+str(j)+']/div[1]/div[3]/div[1]')) ) #新聞簡介 temp.append(driver.find_element_by_xpath('//*[@id="widget-content-Label1"]/div['+str(j)+']/div[1]/div[3]/div[1]').text ) except: temp.append("not find intest") all_list.append(temp) ``` 將資料轉成Pandas格式,使用Pandas的檔案匯出CSV ``` pd_data = pd.DataFrame(all_list) pd_data.to_csv("C:/Users/Student/Desktop/pg_1/news.csv") ``` ::: ### 音訊資料圖像轉化 說明:大多的聲音辨別,會先將聲音轉換為圖像,在做深度學習 備註:目前還在了解階段,大家同步一下 步驟: 1.取得聲音檔,透過網頁工具將youtube的影片下載為wav的音訊檔 2.取得的音訊檔進行切割 :::info ``` import os import wave import numpy as np import pylab as plt import librosa path = r"F:\catsound\wavfile" files = os.listdir(path) files = [path + "\\" + f for f in files if f.endswith('.wav')] CutTime = 3 #单位长度4s def CutAudios(): for i in range(len(files)): FileName = files[i] f = wave.open(r"" + FileName, 'rb') params = f.getparams() #读取音频文件信息 nchannels, sampwidth, framerate, nframes = params[:4] #声道数, 量化位数, 采样频率, 采样点数 str_data = f.readframes(nframes) f.close() wave_data = np.frombuffer(str_data, dtype=np.short) #根据声道数对音频进行转换 if nchannels > 1: wave_data.shape = -1, 2 wave_data = wave_data.T temp_data = wave_data.T else: wave_data = wave_data.T temp_data = wave_data.T CutFrameNum = framerate * CutTime Cutnum =nframes/CutFrameNum #音频片段数 StepNum = int(CutFrameNum) StepTotalNum = 0 for j in range(int(Cutnum)): FileName = r"F:\catsound\wavfile\11\\" + files[i][-17:-4] +"-"+ str(j) + ".wav" temp_dataTemp = temp_data[StepNum * (j):StepNum * (j + 1)] StepTotalNum = (j + 1) * StepNum temp_dataTemp.shape = 1, -1 temp_dataTemp = temp_dataTemp.astype(np.short)# 打开WAV文档 f = wave.open(FileName, 'wb') # 配置声道数、量化位数和取样频率 f.setnchannels(nchannels) f.setsampwidth(sampwidth) f.setframerate(framerate) f.writeframes(temp_dataTemp.tostring()) # 将wav_data转换为二进制数据写入文件 f.close() ``` ::: 3.將音訊檔轉換為影像檔 :::info ``` import librosa import librosa.display import matplotlib.pyplot as plt import numpy as np import os def create_spectrogram(filename,name): plt.interactive(False) clip, sample_rate = librosa.load(filename, sr=None) fig = plt.figure(figsize=[0.72,0.72]) ax = fig.add_subplot(111) ax.axes.get_xaxis().set_visible(False) ax.axes.get_yaxis().set_visible(False) ax.set_frame_on(False) S = librosa.feature.melspectrogram(y=clip, sr=sample_rate) librosa.display.specshow(librosa.power_to_db(S, ref=np.max)) filename = 'F:/catsound/img/' + name + '.jpg' plt.savefig(filename, dpi=400, bbox_inches='tight',pad_inches=0) plt.close() fig.clf() plt.close(fig) plt.close('all') del filename,name,clip,sample_rate,fig,ax,S mypath = r"F:\catsound\wavfile\ofAngryCatSound" files = os.listdir(mypath) for i in files: create_spectrogram(mypath+'/'+i,"cat_angry_"+i) ``` 轉換結果: 貓生氣的聲音: ![](https://i.imgur.com/bEYLOGv.jpg) ![](https://i.imgur.com/ds03BmR.jpg) 貓呼嚕的聲音: ![](https://i.imgur.com/bfbZ1Uf.jpg) ![](https://i.imgur.com/oKkCgYs.jpg) ::: ### LSTM訓練 4311則電商評價(正負評) 準確率90~93% 來源:https://iter01.com/418571.html :::info ``` # -*- coding: utf-8 -*- import os os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/' import pickle import numpy as np import pandas as pd from keras.utils import np_utils, plot_model from keras.models import Sequential from keras.preprocessing.sequence import pad_sequences from keras.layers import LSTM, Dense, Embedding, Dropout from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score print("import good") ``` # 定義:匯入資料 # 檔案的資料中,特徵為evaluation, 類別為label. ``` def load_data(filepath, input_shape=20): df = pd.read_csv(filepath) # 標籤及詞彙表 labels, vocabulary = list(df['label'].unique()), list(df['evaluation'].unique()) # 構造字元級別的特徵 string = '' for word in vocabulary: string += word vocabulary = set(string) # 字典列表 word_dictionary = {word: i+1 for i, word in enumerate(vocabulary)} with open('word_dict.pk', 'wb') as f: pickle.dump(word_dictionary, f) inverse_word_dictionary = {i+1: word for i, word in enumerate(vocabulary)} label_dictionary = {label: i for i, label in enumerate(labels)} with open('label_dict.pk', 'wb') as f: pickle.dump(label_dictionary, f) output_dictionary = {i: labels for i, labels in enumerate(labels)} vocab_size = len(word_dictionary.keys()) # 詞彙表大小 label_size = len(label_dictionary.keys()) # 標籤類別數量 # 序列填充,按input_shape填充,長度不足的按0補充 x = [[word_dictionary[word] for word in sent] for sent in df['evaluation']] x = pad_sequences(maxlen=input_shape, sequences=x, padding='post', value=0) y = [[label_dictionary[sent]] for sent in df['label']] y = [np_utils.to_categorical(label, num_classes=label_size) for label in y] y = np.array([list(_[0]) for _ in y]) return x, y, output_dictionary, vocab_size, label_size, inverse_word_dictionary print("def load_data good") ``` # 定義:建立深度學習模型, Embedding + LSTM + Softmax. ``` def create_LSTM(n_units, input_shape, output_dim, filepath): x, y, output_dictionary, vocab_size, label_size, inverse_word_dictionary = load_data(filepath) model = Sequential() model.add(Embedding(input_dim=vocab_size + 1, output_dim=output_dim, input_length=input_shape, mask_zero=True)) model.add(LSTM(n_units, input_shape=(x.shape[0], x.shape[1]))) model.add(Dropout(0.2)) model.add(Dense(label_size, activation='softmax')) model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) plot_model(model, to_file='./model_lstm.png', show_shapes=True) model.summary() return model print("def create_LSTM good") ``` # 定義:模型訓練 ``` def model_train(input_shape, filepath, model_save_path): # 將資料集分為訓練集和測試集,佔比為9:1 # input_shape = 100 x, y, output_dictionary, vocab_size, label_size, inverse_word_dictionary = load_data(filepath, input_shape) train_x, test_x, train_y, test_y = train_test_split(x, y, test_size = 0.1, random_state = 42) # 模型輸入引數,需要自己根據需要調整 n_units = 100 batch_size = 32 epochs = 5 output_dim = 20 # 模型訓練 lstm_model = create_LSTM(n_units, input_shape, output_dim, filepath) lstm_model.fit(train_x, train_y, epochs=epochs, batch_size=batch_size, verbose=1) # 模型儲存 lstm_model.save(model_save_path) N = test_x.shape[0] # 測試的條數 predict = [] label = [] for start, end in zip(range(0, N, 1), range(1, N+1, 1)): sentence = [inverse_word_dictionary[i] for i in test_x[start] if i != 0] y_predict = lstm_model.predict(test_x[start:end]) label_predict = output_dictionary[np.argmax(y_predict[0])] label_true = output_dictionary[np.argmax(test_y[start:end])] print(''.join(sentence), label_true, label_predict) # 輸出預測結果 predict.append(label_predict) label.append(label_true) acc = accuracy_score(predict, label) # 預測準確率 print('模型在測試集上的準確率為: %s.' % acc) print("def model_train good") ``` # 開始訓練 ``` if __name__ == '__main__': filepath = './corpus.csv' input_shape = 180 model_save_path = './corpus_model.h5' print("model_train start") model_train(input_shape, filepath, model_save_path) print("model_train good") ``` ::: ### 聲音深度學習(貓) :::info [google程式檔案](https://colab.research.google.com/drive/1CWzlTmrAVyQ60GBBGxwgmMyMl0byoIU8?usp=sharing) [音檔切割工具]( https://drive.google.com/file/d/1e4wVU_z0kTxFFaXg98hcBDaFdyQnqGF4/view?usp=sharing) [聲音檔](https://drive.google.com/drive/folders/1oTBRyxKnMHHzcn4R-kwOoNgJomRKuQYG?usp=sharing) *原始音檔放在目錄*原始音檔*底下* ::: ### 圖片分析程式 :::info [github連結]( https://github.com/TangBenson/Git_MyProject/blob/master/ai_project/MyMD_foodtest/Food_Pretrained.ipynb) ::: ### keras的自動生成圖片功能 https://www.itread01.com/content/1546542668.html ### 如果提供影像辨識的訓練資料不足,AI電腦視覺技術是不是就派不上用場了? 對應方式: 1.Transfer Learning 2.對抗生成網路(GAN),但偏向本身有很多資料了再生成更多資料 參考:https://aigo.org.tw/zh-tw/forum/content/25 ### [DJANGO試做連結](https://drive.google.com/file/d/1O_Wx9ebNQV1UL2pCwSGT6f3iBi0bRXEj/view?usp=sharing) ### [DJANGO試做連結20200707](https://drive.google.com/file/d/1Re_SCmeezJJubOiCA09ifGbLwxc8TFuS/view?usp=sharing) ### [DJANGO試做連結20200708(rolanzo/yaming)](https://drive.google.com/file/d/1hF1zhoKglihSrNL1nPELZUYeGjy-ML9s/view?usp=sharing)

    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

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    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