O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

201209 Biopackathon 12th

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio

Confira estes a seguir

1 de 30 Anúncio

201209 Biopackathon 12th

Baixar para ler offline

画像処理・画像解析に関するRパッケージを調査したので、見つかったパッケージを(広く浅く)紹介する。
調査対象: CRAN、Bioconductor、Neuroconductor (= GitHub/CRAN)とか
検索キーワード: imag(e), microscop(y) ctc
ANTsRNetを使って、2D U-NET/CPU版をやってみた。

画像処理・画像解析に関するRパッケージを調査したので、見つかったパッケージを(広く浅く)紹介する。
調査対象: CRAN、Bioconductor、Neuroconductor (= GitHub/CRAN)とか
検索キーワード: imag(e), microscop(y) ctc
ANTsRNetを使って、2D U-NET/CPU版をやってみた。

Anúncio
Anúncio

Mais Conteúdo rRelacionado

Diapositivos para si (20)

Semelhante a 201209 Biopackathon 12th (20)

Anúncio

Mais de Satoshi Kume (20)

Mais recentes (20)

Anúncio

201209 Biopackathon 12th

  1. 1. Satoshi Kume 画像解析関連の Rパッケージについて 〜ANTsRNetを使った画像解析の話も〜 201209 @ BioPackathon 12
  2. 2. 今回の内容 画像処理・画像解析に関するRパッケージを調査した ので、見つかったパッケージを(広く浅く)紹介する。 調査対象: CRAN、Bioconductor、Neuroconductor (= GitHub/CRAN) とか 検索キーワード: imag(e), microscop(y) ctc ANTsRNetを使って、2D U-NET/CPU版をやってみた
  3. 3. ANTsX: A dynamic ecosystem for quantitative biological and medical imaging https://www.medrxiv.org/content/10.1101/2020.10.19.20215392v2 (https://www.medrxiv.org/content/10.1101/2020.10.19.20215392v2.full.pdf) https://github.com/ANTsX Advanced Normalization Tools Ecosystem ANTsRNet ANTsRNetに関連する情報 https://github.com/ANTsX/ANTsRNet Nick Tustison, Associate Professor, Department of Radiology and Medical Imaging, University of Virginia http://ntustison.github.io/CV/
  4. 4. Bioconducto r https://www.bioconductor.org
  5. 5. Bioconductorにおける関連パッケージ あまりない。。。。
  6. 6. EBImage (特長) ・R上で汎用的な画像処理ができる。 (OpenCVに近い感じの印象) ・蛍光顕微鏡画像の細胞セグメンテーションがCUIで出来る。
  7. 7. imageHTS (特長) ・顕微鏡画像のハイスループット・スクリーン解析に特化している ・細胞像のセグメント解析、定量的な細胞特徴の抽出、細胞タイプ の予測、Webインターフェースを介したデータ閲覧を提供
  8. 8. Neuroconductor https://neuroconductor.org (だいたいCRANに同じパッケージがある)
  9. 9. Neuroconductorにおける関連パッケージ - ANTs: 医用画像の定量ツール群 - ichseg: X線 Computed Tomography (CT) 画像における脳内出血領域抽出 - RNiftyReg: NiftyRegライブラリを使った画像位置合わせ - dcm2niir: DICOMからNIfTI画像への変換 画像処理・解析系 - ggBrain: ggplot を用いた脳画像表示 - Papaya: JavaScript を用いた画像ビューア - brainR: 脳イメージング用パッケージ 'misc3d' および 'rgl' のヘルパー機能 画像ビューア関連 - nitrcbot: NeuroImaging Tools and Resources Collaboratory(NITRC)から画像を取得する パッケージ - Rxnat: 神経画像アーカイブツールキットからの検索と画像抽出(公開/非公開データセット) - malf.templates: MICCAI 2012 Grand Challengeのデータセット 画像データセット関連 結構ある!
  10. 10. ANTs
  11. 11. https://github.com/ANTsX/ANTsRNet
  12. 12. https://www.nitrc.org/ nitrcbot
  13. 13. (画像処理・解析関連) magick: Advanced Graphics and Image-Processing in R nat: NeuroAnatomy Toolbox for Analysis of 3D Image Data Bioi: Biological Image Analysis bioimagetools: Tools for Microscopy Imaging OpenImageR: An Image Processing Toolkit image.LineSegmentDetector: Detect Line Segments in Images SuperpixelImageSegmentation: Superpixel Image Segmentation adimpro: Adaptive Smoothing of Digital Images autothresholdr: An R Port of the 'ImageJ' Plugin 'Auto Threshold' bayesImageS: Bayesian Methods for Image Segmentation using a Potts Model downscaledl: Downscale of RS Images using Deep Learning edci: Edge Detection and Clustering in Images imagine: IMAGing engINEs, Tools for Application of Image Filters to Data Matrices CRANにおける関連パッケージ(1) たくさんある!
  14. 14. nat: NeuroAnatomy Toolbox for Analysis of 3D Image Data
  15. 15. CRANにおける関連パッケージ(2) (顕微鏡・バイオ関連) - AFM: Atomic Force Microscope Image Analysis - colocr: Conduct Co-Localization Analysis of Fluorescence Microscopy Images - interfr: Interference Color Charts for Polarized Light Microscopy - TIMP: Fitting Separable Nonlinear Models in Spectroscopy and Microscopy - cytominer: Methods for Image-Based Cell Profiling (可視化・アノテーション) - taipan: Tool for Annotating Images in Preparation for Analysis - ggimage: Use Image in 'ggplot2' - ggimg: Graphics Layers for Plotting Image Data with 'ggplot2’ - imageviewer: Simple 'htmlwidgets' Image Viewer with WebGL Brightness/Contrast
  16. 16. taipan: Tool for Annotating Images in Preparation for Analysis
  17. 17. Summary (1) - 探してみると、Rでも画像関連のパッ ケージ(特に、CRAN)が結構あった。
  18. 18. https://github.com/ANTsX/ANTsRNet
  19. 19. arXiv:1505.04597 https://arxiv.org/pdf/1505.04597.pdf
  20. 20. DLの流れ Dataset 用意 Model 構築 Compile 損失関数 設定 Fit Training Evaluate モデル評価 keras / tensorflow ANTsRNetでは このあたりをサポート チュートリアル データのみ
  21. 21. 実行環境 ## 実行環境 ## macOS Catalina 10.15.4 R version 4.0.2 (2020-06-22) RStudio Version 1.2.5033 $ brew config HOMEBREW_VERSION: 2.4.16 ORIGIN: https://github.com/Homebrew/brew HEAD: 2a4c9f610e69b9fed1eec61ac2c53e4b11a32e4c Last commit: 3 months ago Core tap ORIGIN: https://github.com/Homebrew/homebrew-core Core tap HEAD: 57a5081f9893f0a803a9e2bd1e01da0a48c39d45 Core tap last commit: 3 months ago Core tap branch: master HOMEBREW_PREFIX: /usr/local HOMEBREW_CASK_OPTS: [] HOMEBREW_MAKE_JOBS: 8 CPU: octa-core 64-bit kabylake Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ ruby Clang: 11.0 build 1103 Git: 2.24.1 => /Library/Developer/CommandLineTools/usr/bin/git Curl: 7.64.1 => /usr/bin/curl macOS: 10.15.4-x86_64 CLT: 11.4.0.0.1.1583798712 Xcode: N/A
  22. 22. インストール ## Macで実行 mydeps <- c( "Rcpp", "RcppEigen", "magrittr", "rsvd", "magic", "psych" ) install.packages( pkgs = mydeps, dependencies = TRUE ) install.packages("devtools") library( devtools ) devtools::install_github("stnava/cmaker") devtools::install_github("stnava/ANTsR") devtools::install_github("ANTsX/ANTsRNet") Option $ git clone https://github.com/stnava/ITKR.git $ git clone https://github.com/ANTsX/ANTsRCore.git $ git clone https://github.com/ANTsX/ANTsR.git $ R CMD INSTALL ITKR $ R CMD INSTALL ANTsRCore $ R CMD INSTALL ANTsR $ git clone https://github.com/ANTsX/ANTsRNet.git $ R CMD INSTALL ANTsRNet
  23. 23. データ準備/前処理 library( ANTsR ) library( ANTsRNet ) library( keras ) #チュートリアルデータセットの読み込み imageIDs <- c( "r16", "r27", "r30", "r62", "r64", "r85" ) trainingBatchSize <- length( imageIDs ) # 3組織ラベルのセグメンテーション segmentationLabels <- c( 1, 2, 3 ) numberOfLabels <- length( segmentationLabels ) initialization <- paste0( 'KMeans[', numberOfLabels, ']' ) #画像データの読み込み domainImage <- antsImageRead( getANTsRData( imageIDs[1] ) ) # (NA)空のアレイデータの準備 X_train <- array( data = NA, dim = c( trainingBatchSize, dim( domainImage ), 1 ) ) Y_train <- array( data = NA, dim = c( trainingBatchSize, dim( domainImage ) ) )
  24. 24. #画像データの読み込み images <- list() segmentations <- list() for( i in seq_len( trainingBatchSize ) ){ cat( "Processing image", imageIDs[i], "n" ) image <- antsImageRead( getANTsRData( imageIDs[i] ) ) mask <- getMask( image ) segmentation <- atropos( image, mask, initialization )$segmentation X_train[i,,,1] <- as.array( image ) Y_train[i,,] <- as.array( segmentation ) } # Yデータセットのラベルデータに変換 Y_train <- encodeUnet( Y_train, segmentationLabels ) # ノーマライゼーション X_train <- ( X_train - mean( X_train ) ) / sd( X_train ) 画像読み込み/ノーマライズ
  25. 25. #画像確認 str(X_train) str(Y_train) image(X_train[1,,,]) image(Y_train[1,,,1,1]) image(Y_train[1,,,2,1]) image(Y_train[1,,,3,1]) > str(X_train) num [1:6, 1:256, 1:256, 1] -0.596 -0.596 -0.596 -0.596 -0.596 ... > str(Y_train) num [1:6, 1:256, 1:256, 1:3, 1:3] 0 0 0 0 0 0 0 0 0 0 ... https://akira3132.info/cerebral_cortex.html
  26. 26. 2D U-NETモデル構築 # モデル作成 model <- createUnetModel2D( c( dim( domainImage ), 1 ), numberOfOutputs = numberOfLabels ) source("https://gist.githubusercontent.com/kumeS/41fed5 11efb45bd55d468d4968b0f157/raw/0f64b83700ac578d0 c39abd420da5373d4317083/DL_plot_modi_v1.1.R") install.packages("DiagrammeR"); library( DiagrammeR ) plot_model_modi(model)
  27. 27. # ダイス係数 metric_multilabel_dice_coefficient <- custom_metric( "multilabel_dice_coefficient", multilabel_dice_coefficient ) #ダイスロス関数 loss_dice <- function( y_true, y_pred ) { -multilabel_dice_coefficient(y_true, y_pred) } attr(loss_dice, "py_function_name") <- "multilabel_dice_coefficient" #コンパイル(最適化アルゴリズムの定義) model %>% compile( loss = loss_dice, optimizer = optimizer_adam( lr = 0.0001 ), metrics = metric_multilabel_dice_coefficient ) 損失関数 / 評価関数の定義、コンパイル
  28. 28. track <- model %>% fit( X_train, Y_train, epochs = 20, batch_size = 5, verbose = 1, shuffle = TRUE, callbacks = list( callback_model_checkpoint( "unetModelInterimWeights.h5", monitor = 'val_loss', save_best_only = TRUE ), callback_reduce_lr_on_plateau( monitor = "val_loss", factor = 0.1 ) ), validation_split = 0.2 ) モデルのフィット Train on 4 samples, validate on 2 samples Epoch 1/20 4/4 [==============================] - 4s 884ms/sample - loss: -0.5779 - multilabel_dice_coefficient: 0.5779 - val_loss: -0.5809 - val_multilabel_dice_coefficient: 0.5809 Epoch 2/20 4/4 [==============================] - 2s 568ms/sample - loss: -0.5801 - multilabel_dice_coefficient: 0.5801 - val_loss: -0.5835 - val_multilabel_dice_coefficient: 0.5835 Epoch 3/20 4/4 [==============================] - 2s 553ms/sample - loss: -0.5827 - multilabel_dice_coefficient: 0.5827 - val_loss: -0.5864 - val_multilabel_dice_coefficient: 0.5864 Epoch 4/20 4/4 [==============================] - 2s 573ms/sample - loss: -0.5856 - multilabel_dice_coefficient: 0.5856 - val_loss: -0.5895 - val_multilabel_dice_coefficient: 0.5895 Epoch 5/20 4/4 [==============================] - 2s 622ms/sample - loss: -0.5888 - multilabel_dice_coefficient: 0.5888 - val_loss: -0.5925 - val_multilabel_dice_coefficient: 0.5925 Epoch 6/20 4/4 [==============================] - 2s
  29. 29. Summary (2) - ANTsRNetのセットアップはやや面倒 - MRI解析とかに特化している - DLモデルは活用できる。

×