GOTOH Shunsuke
    • 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
    • Engagement control
    • 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 Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- tags: 発表, 機械学習名古屋, Julia, CIFAR-10 slideOptions: transition: slide --- Julia で CIFAR-10 データセットと触れあってみた === <!-- .slide: data-background="#5E5E5E" --> 2018/02/03 機械学習 名古屋 第14回勉強会 antimon2(後藤 俊介) <aside class="notes">Juliaで今回のテーマ CIFAR-10 のデータセットと触れあってみた、の紹介っ!</aside> ---- <!-- .slide: data-background="#5E5E5E" --> ## お品書き + 自己紹介 + Julia とは? + CIFAR-10 --- <!-- .slide: data-background="#1A7E82" --> # 自己紹介 ---- <!-- .slide: data-background="#1A7E82" --> ## 自己紹介 + 名前:後藤 俊介 + 所属:有限会社 来栖川電算 + コミュニティ:**[機械学習名古屋](https://machine-learning.connpass.com/)**, [NGK2017B](https://ngk2017b.connpass.com/), Python東海, Ruby東海, [Rails Girls Nagoya](http://railsgirls.com/nagoya)(コーチ), … + 言語:**Julia**, Python, Ruby, Scala(勉強中), … + ![Twitter](https://i.imgur.com/HqouMIg.png)<!-- .element: class="plain" style="vertical-align:middle;background:transparent" --> [@antimon2](https://twitter.com/antimon2) / ![Facebook](https://i.imgur.com/01nPd37.png)<!-- .element: class="plain" style="vertical-align:middle;background:transparent" --> [antimon2](https://www.facebook.com/antimon2) + ![Github](https://i.imgur.com/yBKtii5.png)<!-- .element: class="plain" style="vertical-align:middle;background:transparent" --> [antimon2](https://github.com/antimon2/) / ![Qiita](https://i.imgur.com/FxHMi64.png)<!-- .element: class="plain" style="vertical-align:middle;background:transparent" --> [@antimon2](http://qiita.com/antimon2) <aside class="notes">今回も Julia の紹介。Julia 良いよ Julia っ</aside> --- <!-- .slide: data-background="#213e98" --> # Julia とは? <aside class="notes">簡単な紹介っ</aside> ---- <!-- .slide: data-background="#213e98" --> [![Julia](https://upload.wikimedia.org/wikipedia/commons/6/69/Julia_prog_language.svg)<!-- .element: style="background:white;max-width:80%" -->](https://julialang.org) ---- <!-- .slide: data-background="#213e98" --> ## Julia とは?(1) + [公式サイト(英語) https://julialang.org](https://julialang.org) + Python/Ruby/R 等の「いいとこどり」言語! + 動作が速い!(LLVM JIT コンパイル) + 2017/12/14 に最新 v0.6.2 リリース! + もうすぐ [v1.0 が出る](https://nbviewer.jupyter.org/github/bicycle1885/JuliaTokyo7/blob/master/%E6%9C%80%E6%96%B0Julia%E3%83%81%E3%83%A5%E3%83%BC%E3%83%88%E3%83%AA%E3%82%A2%E3%83%AB.ipynb#Julia-1.0?)(はず) + 検索するときは [`julialang`](https://www.google.co.jp/search?q=julialang) もしくは [`julia言語`](https://twitter.com/search?vertical=default&q=%23julia%E8%A8%80%E8%AA%9E) で! <aside class="notes">科学技術計算に強い!っ<br>あとググるとき最近 <code>julia</code> でもトップに表示されるようになってきた♪</aside> ---- <!-- .slide: data-background="#213e98" --> ## Julia とは?(2) > + Rのように中身がぐちゃぐちゃでなく、 > + Rubyのように遅くなく、 > + Lispのように原始的またはエレファントでなく、 > + Prologのように変態的なところはなく、 > + Javaのように硬すぎることはなく、 > + Haskellのように抽象的すぎない > > ほどよい言語である <!-- .element: style="font-size:66%" --> 引用元:http://www.slideshare.net/Nikoriks/julia-28059489/8 <!-- .element: style="font-size:71%" --> ---- <!-- .slide: data-background="#213e98" --> ## Julia とは?(3) > + C のように高速だけど、 Ruby のような動的型付言語である > + Lisp のようにプログラムと同等に扱えるマクロがあって、しかも Matlab のような直感的な数式表現もできる > + Python のように総合的なプログラミングができて、 R のように統計処理も得意で、 Perl のように文字列処理もできて、 Matlab のように線形代数もできて、 shell のように複数のプログラムを組み合わせることもできる > + 超初心者にも習得は簡単で、 超上級者の満足にも応えられる > + インタラクティブにも動作して、コンパイルもできる <!-- .element: style="font-size:50%" --> ([Why We Created Julia](http://julialang.org/blog/2012/02/why-we-created-julia) から抜粋・私訳) <!-- .element: style="font-size:71%" --> ---- <!-- .slide: data-background="#213e98" --> ## 主な機能 + [多重ディスパッチ](https://ja.wikipedia.org/wiki/%E5%A4%9A%E9%87%8D%E3%83%87%E3%82%A3%E3%82%B9%E3%83%91%E3%83%83%E3%83%81) + 動的型システム + [並行・並列処理](https://docs.julialang.org/en/stable/manual/parallel-computing/)、コルーチン + 組込パッケージマネージャ <aside class="notes">っ</aside> --- <!-- .slide: data-background="#633978" --> # CIFAR-10 <aside class="notes">と触れあうことによる Julia のプログラミング例の紹介っ</aside> ---- <!-- .slide: data-background="#633978" --> ## CIFAR-10 とは? + [CIFAR-10 とは?](https://qiita.com/antimon2/private/b136c29e192be5c68dbc#cifar-10-%E3%81%A8%E3%81%AF)(今回のハンズオン資料より) <aside class="notes">重複になるので今回のハンズオン資料を見てねっ</aside> --- <!-- .slide: data-background="#872724" --> ## Julia で CIFAR-10 データ読込・表示 ---- <!-- .slide: data-background="#872724" --> ### CIFAR-10 データ型の定義 ```julia= # 24584bits(=3073bytes)の Primitive Type を定義 primitive type CIFAR10Record 24584 end ``` <aside class="notes">Juliaではビット数を指定したデータ型を自分で定義できますっ<br>ちなみに今回のスライドは Julia v0.6.x 用のコードしか示しません v0.5.x 以前では動作しませんっ</aside> ---- <!-- .slide: data-background="#872724" --> ### CIFAR-10 データの読込 ```julia= function Base.read(stream::IO, ::Type{CIFAR10Record}) bytes = read(stream, UInt8, 3073) reinterpret(CIFAR10Record, bytes)[1] end ``` <aside class="notes">Juliaでは `read()` 関数を多重定義することで独自データ型の値をファイル等から読み込む記述ができますっ</aside> ---- <!-- .slide: data-background="#872724" --> ```julia # 例: record0 = open("test_batch.bin", "r") do f return read(f, CIFAR10Record) end ``` <aside class="notes">簡単ですねっ</aside> ---- <!-- .slide: data-background="#872724" --> ### CIFAR-10 データの概要表示 ```julia= function Base.show(io::IO, record::CIFAR10Record) bytes = reinterpret(UInt8, [record]) print(io, "CIFAR10Record(") # show 1st byte(=label) show(io, bytes[1]) print(io, ", ") # show hashcode of the rest of bytes(=image) show(io, hash(bytes[2:end])) print(io, ')') end ``` <aside class="notes">Juliaでは `show()` 関数を多重定義することで独自データ型の文字列表現を設定することができますっ</aside> ---- <!-- .slide: data-background="#872724" --> ```julia # 例: string(record0) # => "CIFAR10Record(0x03, 0xd0b45b812aae12b1)" ``` <aside class="notes">簡単ですねっ</aside> ---- <!-- .slide: data-background="#872724" --> ### CIFAR-10 データの画像としての表示 + Jupyter notebook とかだと 画像として表示できると分かりやすい。 + 冬休みにその実験をした(→ [Julia で CIFAR-10 データを画像として表示してみる(外部パッケージ無しで)](https://qiita.com/antimon2/items/315c88299fce7a73c052)) + ここでは結果のみ紹介↓ ---- <!-- .slide: data-background="#872724" --> ![CIFAR-10 の1レコードを画像としてプレビューしたキャプチャ画像](https://camo.qiitausercontent.com/5489d28d9b6f23fcf9cfd543d43fc963ca227f01/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e616d617a6f6e6177732e636f6d2f302f33303430302f64376536373831342d623165312d363361372d663466382d3134393466626536306639612e706e67) ---- <!-- .slide: data-background="#872724" --> ![CIFAR-10 の1レコードを画像としてプレビューしたキャプチャ画像その2](https://camo.qiitausercontent.com/49ec81f0b30e9c63965e9d3299fc93dafa4231d5/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e616d617a6f6e6177732e636f6d2f302f33303430302f37363537386362342d646165342d386162622d623235312d3331626237343061663231662e706e67) --- <!-- .slide: data-background="#27641e" --> ## Julia で CIFAR-10 データで学習 ---- <!-- .slide: data-background="#27641e" --> ### CIFAR-10 データの読込(バッチ処理編) <aside class="notes">前回発表した「データのバッチ生成 with Julia」の内容も参考にっ</aside> ---- <!-- .slide: data-background="#27641e" --> ```julia= function readtrain(channel::Channel{Tuple{CIFAR10Record}}, fid::Int, datadir::String=datadir) if isopen(channel) filepath = joinpath(datadir, "data_batch_$(fid).bin") open(filepath, "r") do f while isopen(channel) for idx in shuffle(0:9999) seek(f, idx * 3073) record = read(f, CIFAR10Record) put!(channel, (record,)) end end end end end ``` <!-- .element: style="font-size:45%" --> <aside class="notes">指定した訓練用データファイルからランダムアクセスで固定長レコードを読み込んで <code>Channel</code> に送出(例外処理省略)っ</aside> ---- <!-- .slide: data-background="#27641e" --> ```julia= function train_batch_produce(channel::Channel{Tuple{CIFAR10Record}}, datadir=datadir) train_channels = [Channel{Tuple{CIFAR10Record}}(32) for _=1:5] for fid in 1:5 @schedule readtrain(train_channels[fid], fid, datadir) end while true try put!(channel, take!(rand(train_channels))) catch ex for ch in train_channels close(ch) end return end end end ``` <!-- .element: style="font-size:45%" --> <aside class="notes">5つの各訓練用データファイルから読み込んだレコードを乱択して <code>Channel</code> に送出っ</aside> ---- <!-- .slide: data-background="#27641e" --> ```julia= struct CF10Batch channel::Channel{Tuple{CIFAR10Record}} batchsize::Int end function (f::CF10Batch)() buf = reshape(reinterpret( UInt8, collect(Iterators.take(f.channel, f.batchsize)) ), (:, f.batchsize)) return (buf[2:3073, :], buf[1, :]) end ``` <!-- .element: style="font-size:45%" --> <aside class="notes">指定したバッチサイズ分のデータを取得して data と labels に分けて返すっ</aside> ---- <!-- .slide: data-background="#27641e" --> ```julia= train_channel = Channel{Tuple{CIFAR10Record}}(32) @schedule train_batch_produce(train_channel) trainbatch = CF10Batch(train_channel, 128) # data, label = trainbatch() # ↑実行する度に新しいデータが返ってくる ``` <!-- .element: style="font-size:45%" --> ---- <!-- .slide: data-background="#27641e" --> ### CNNの構築 ---- <!-- .slide: data-background="#27641e" --> + Julia 用 Deep Learning F/W(いくつか): + [MXNet.jl](https://github.com/dmlc/MXNet.jl)(軽量・効率性・柔軟性がウリ) + [TensorFlow.jl](https://github.com/malmaud/TensorFlow.jl)([TensorFlow](https://www.tensorflow.org/) のラッパー) + [Merlin.jl](https://github.com/hshindo/Merlin.jl)(最近出てきた、日本製) + 今回は、書籍 [ゼロから作る Deep Learning](https://www.oreilly.co.jp/books/9784873117584/) を参考にスクラッチ実装(!) <aside class="notes">行列演算も簡単高速だから自分でも(がんばれば)実装出来ますよっ</aside> ---- <!-- .slide: data-background="#27641e" --> ### CNNの構築 + いろいろやったけれど時間が無いので結果だけ↓ + [Cifar10TrainSample.jl.ipynb](https://gist.github.com/antimon2/32f7d9951865f5748e7a9afbfbf556a5#file-cifar10trainsample-jl-ipynb) ([nbviewer](https://nbviewer.jupyter.org/gist/antimon2/32f7d9951865f5748e7a9afbfbf556a5/Cifar10TrainSample.jl.ipynb)) + [Cifar10PredictSample.jl.ipynb](https://gist.github.com/antimon2/32f7d9951865f5748e7a9afbfbf556a5#file-cifar10predictsample-jl-ipynb) ([nbviewer](https://nbviewer.jupyter.org/gist/antimon2/32f7d9951865f5748e7a9afbfbf556a5/Cifar10PredictSample.jl.ipynb)) <aside class="notes">っ</aside> ---- <!-- .slide: data-background="#27641e" --> #### 考察 + 思ったより遅い(学習も推測も) + Convolution や Pooling が forward/backward ともに時間かかってる → im2col/col2im あんまし速くない? + 特別な正則化してない(入力を255で割って0.0〜1.0の範囲内にしただけ) + cropping やその他 data-augmentation も何もしてない + でも取り敢えず学習動いたっぽい <aside class="notes">っ</aside> --- <!-- .slide: data-background="#213e98" --> ## A. 参考 + [Julia Documentation](https://docs.julialang.org/) + [Julia で CIFAR-10 データを画像として表示してみる(外部パッケージ無しで)](https://qiita.com/antimon2/items/315c88299fce7a73c052) + [TensorFlow の CIFAR-10で実際に予測してみる](http://blog.suprsonicjetboy.com/entry/2017/04/30/204951) + [Gist](https://gist.github.com/antimon2/32f7d9951865f5748e7a9afbfbf556a5): + [Cifar10TrainSample.jl.ipynb](https://gist.github.com/antimon2/32f7d9951865f5748e7a9afbfbf556a5#file-cifar10trainsample-jl-ipynb) ([nbviewer](https://nbviewer.jupyter.org/gist/antimon2/32f7d9951865f5748e7a9afbfbf556a5/Cifar10TrainSample.jl.ipynb)) + [Cifar10PredictSample.jl.ipynb](https://gist.github.com/antimon2/32f7d9951865f5748e7a9afbfbf556a5#file-cifar10predictsample-jl-ipynb) ([nbviewer](https://nbviewer.jupyter.org/gist/antimon2/32f7d9951865f5748e7a9afbfbf556a5/Cifar10PredictSample.jl.ipynb)) --- <!-- .slide: data-background="#213e98" --> ご清聴ありがとうございます。

    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